rlm@1: // Windows/FileFind.h rlm@1: rlm@1: #ifndef __WINDOWS_FILEFIND_H rlm@1: #define __WINDOWS_FILEFIND_H rlm@1: rlm@1: #include "../Common/MyString.h" rlm@1: #include "../Common/Types.h" rlm@1: #include "FileName.h" rlm@1: #include "Defs.h" rlm@1: rlm@1: namespace NWindows { rlm@1: namespace NFile { rlm@1: namespace NFind { rlm@1: rlm@1: namespace NAttributes rlm@1: { rlm@1: inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; } rlm@1: inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; } rlm@1: inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; } rlm@1: inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; } rlm@1: inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; } rlm@1: inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; } rlm@1: inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; } rlm@1: } rlm@1: rlm@1: class CFileInfoBase rlm@1: { rlm@1: bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); } rlm@1: public: rlm@1: UInt64 Size; rlm@1: FILETIME CTime; rlm@1: FILETIME ATime; rlm@1: FILETIME MTime; rlm@1: DWORD Attrib; rlm@1: rlm@1: #ifndef _WIN32_WCE rlm@1: UINT32 ReparseTag; rlm@1: #else rlm@1: DWORD ObjectID; rlm@1: #endif rlm@1: rlm@1: bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); } rlm@1: bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); } rlm@1: bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); } rlm@1: bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); } rlm@1: bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); } rlm@1: bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); } rlm@1: bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); } rlm@1: bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); } rlm@1: bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); } rlm@1: bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); } rlm@1: bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); } rlm@1: bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); } rlm@1: }; rlm@1: rlm@1: class CFileInfo: public CFileInfoBase rlm@1: { rlm@1: public: rlm@1: CSysString Name; rlm@1: bool IsDots() const; rlm@1: }; rlm@1: rlm@1: #ifdef _UNICODE rlm@1: typedef CFileInfo CFileInfoW; rlm@1: #else rlm@1: class CFileInfoW: public CFileInfoBase rlm@1: { rlm@1: public: rlm@1: UString Name; rlm@1: bool IsDots() const; rlm@1: }; rlm@1: #endif rlm@1: rlm@1: class CFindFile rlm@1: { rlm@1: friend class CEnumerator; rlm@1: HANDLE _handle; rlm@1: public: rlm@1: bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; } rlm@1: CFindFile(): _handle(INVALID_HANDLE_VALUE) {} rlm@1: ~CFindFile() { Close(); } rlm@1: bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo); rlm@1: bool FindNext(CFileInfo &fileInfo); rlm@1: #ifndef _UNICODE rlm@1: bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo); rlm@1: bool FindNext(CFileInfoW &fileInfo); rlm@1: #endif rlm@1: bool Close(); rlm@1: }; rlm@1: rlm@1: bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo); rlm@1: rlm@1: bool DoesFileExist(LPCTSTR name); rlm@1: #ifndef _UNICODE rlm@1: bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo); rlm@1: bool DoesFileExist(LPCWSTR name); rlm@1: #endif rlm@1: rlm@1: class CEnumerator rlm@1: { rlm@1: CFindFile _findFile; rlm@1: CSysString _wildcard; rlm@1: bool NextAny(CFileInfo &fileInfo); rlm@1: public: rlm@1: CEnumerator(): _wildcard(NName::kAnyStringWildcard) {} rlm@1: CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {} rlm@1: bool Next(CFileInfo &fileInfo); rlm@1: bool Next(CFileInfo &fileInfo, bool &found); rlm@1: }; rlm@1: rlm@1: #ifdef _UNICODE rlm@1: typedef CEnumerator CEnumeratorW; rlm@1: #else rlm@1: class CEnumeratorW rlm@1: { rlm@1: CFindFile _findFile; rlm@1: UString _wildcard; rlm@1: bool NextAny(CFileInfoW &fileInfo); rlm@1: public: rlm@1: CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {} rlm@1: CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {} rlm@1: bool Next(CFileInfoW &fileInfo); rlm@1: bool Next(CFileInfoW &fileInfo, bool &found); rlm@1: }; rlm@1: #endif rlm@1: rlm@1: class CFindChangeNotification rlm@1: { rlm@1: HANDLE _handle; rlm@1: public: rlm@1: operator HANDLE () { return _handle; } rlm@1: bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; } rlm@1: CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {} rlm@1: ~CFindChangeNotification() { Close(); } rlm@1: bool Close(); rlm@1: HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter); rlm@1: #ifndef _UNICODE rlm@1: HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter); rlm@1: #endif rlm@1: bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); } rlm@1: }; rlm@1: rlm@1: #ifndef _WIN32_WCE rlm@1: bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings); rlm@1: #ifndef _UNICODE rlm@1: bool MyGetLogicalDriveStrings(UStringVector &driveStrings); rlm@1: #endif rlm@1: #endif rlm@1: rlm@1: }}} rlm@1: rlm@1: #endif rlm@1: