1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
/**
* \file DirEnumerator.h
* Includes the ZipArchiveLib::CDirEnumerator class.
*
*/
#if !defined(ZIPARCHIVE_DIRENUMERATOR_DOT_H)
#define ZIPARCHIVE_DIRENUMERATOR_DOT_H
#if _MSC_VER > 1000
#pragma once
#pragma warning( push )
#pragma warning (disable : 4100) // unreferenced formal parameter
#if defined ZIP_HAS_DLL
#pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
#endif
#endif
#include "ZipString.h"
#include "ZipPathComponent.h"
#include "FileFilter.h"
/**
Includes helper classes. Some of them can be reused in other applications.
*/
namespace ZipArchiveLib
{
/**
A base class for processing multiple files in a directory.
It provides a directory enumeration functionality.
*/
class ZIP_API CDirEnumerator
{
LPCTSTR m_lpszDirectory;
LPCTSTR m_lpszFileNameMask;
bool m_bRecursive;
CZipString m_szCurrentDirectory;
protected:
/**
Initializes a new CDirEnumerator object.
\param lpszDirectory
A directory to process.
\param bRecursive
The value indicating whether the subfolders of \a lpszDirectory
should be processed recursively or not.
\see
GetDirectory
\see
IsRecursive
*/
CDirEnumerator(LPCTSTR lpszDirectory, bool bRecursive = true)
{
CZipString dir(lpszDirectory);
if (dir.IsEmpty())
m_lpszDirectory = _T(".");
else
m_lpszDirectory = lpszDirectory;
m_bRecursive = bRecursive;
}
/**
Override this method to perform file processing while enumerating directories.
This method is not called for directories, but for files only.
\param lpszPath
The full path to the current file.
\param info
A structure containing an information about the current file.
\return
Return \c true to continue the enumeration.
When you return \c false, the enumeration is aborted.
\see
CFileFilter::Evaluate
*/
virtual bool Process(LPCTSTR lpszPath, const CFileInfo& info) = 0;
/**
This method is called at the beginning of the enumeration process.
\see
OnEnumerationEnd
*/
virtual void OnEnumerationBegin(){}
/**
This method is called at the end of the enumeration process.
\param bResult
It is set to \c false, if the #Process method returned \c false (the enumeration
was aborted). Otherwise, it is set to \c true.
\see
OnEnumerationBegin
*/
virtual void OnEnumerationEnd(bool bResult){}
/**
This method is called when an enumeration process enters a new directory.
\see
GetCurrentDirectory
\see
ExitDirectory
*/
virtual void EnterDirectory(){}
/**
This method is method called when an enumeration process exits a directory.
\see
GetCurrentDirectory
\see
EnterDirectory
*/
virtual void ExitDirectory(){}
public:
/**
Returns the directory being enumerated.
\return
The directory being enumerated (root).
\see
CDirEnumerator::CDirEnumerator
*/
LPCTSTR GetDirectory() const {return m_lpszDirectory;}
/**
Returns the value indicating whether the subfolders of the root directory
are processed recursively or not.
\return
\c true, if the enumeration process is recursive; \c false otherwise.
\see
CDirEnumerator::CDirEnumerator
*/
bool IsRecursive() const {return m_bRecursive;}
/**
Returns the directory which the enumeration process is currently processing.
\return
The directory which the enumeration process is currently processing.
*/
LPCTSTR GetCurrentDirectory() const {return m_szCurrentDirectory;}
/**
Starts the enumeration process. Calls CFileFilter::Evaluate method for every file or directory found.
If CFileFilter::Evaluate returns \c true, the file is processed by the #Process method.
\param filter
A filter that decides which directories and/or files should be processed and which should not.
\return
\c false, if the process was aborted (the #Process method returned \c false); \c true otherwise.
\see
CFileFilter::Evaluate
*/
bool Start(CFileFilter& filter);
virtual ~CDirEnumerator(){}
private:
static bool IsDots(LPCTSTR lpszName);
};
}
#if _MSC_VER > 1000
#pragma warning( pop )
#endif
#endif
|