1 // Windows/FileFind.h 2 3 #ifndef __WINDOWS_FILE_FIND_H 4 #define __WINDOWS_FILE_FIND_H 5 6 #include "../Common/MyString.h" 7 #include "Defs.h" 8 9 namespace NWindows { 10 namespace NFile { 11 namespace NFind { 12 13 namespace NAttributes 14 { 15 inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; } 16 inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; } 17 inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; } 18 inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; } 19 inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; } 20 inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; } 21 inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; } 22 } 23 24 class CFileInfoBase 25 { 26 bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); } 27 public: 28 UInt64 Size; 29 FILETIME CTime; 30 FILETIME ATime; 31 FILETIME MTime; 32 DWORD Attrib; 33 bool IsAltStream; 34 bool IsDevice; 35 36 /* 37 #ifdef UNDER_CE 38 DWORD ObjectID; 39 #else 40 UINT32 ReparseTag; 41 #endif 42 */ 43 44 CFileInfoBase() { Clear(); } 45 void Clear() throw(); 46 47 void SetAsDir() { Attrib = FILE_ATTRIBUTE_DIRECTORY; } 48 49 bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); } 50 bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); } 51 bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); } 52 bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); } 53 bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); } 54 bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); } 55 bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); } 56 bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); } 57 bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); } 58 bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); } 59 bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); } 60 bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); } 61 }; 62 63 struct CFileInfo: public CFileInfoBase 64 { 65 FString Name; 66 #if defined(_WIN32) && !defined(UNDER_CE) 67 // FString ShortName; 68 #endif 69 70 bool IsDots() const throw(); 71 bool Find(CFSTR wildcard); 72 }; 73 74 class CFindFileBase 75 { 76 protected: 77 HANDLE _handle; 78 public: 79 bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; } 80 CFindFileBase(): _handle(INVALID_HANDLE_VALUE) {} 81 ~CFindFileBase() { Close(); } 82 bool Close() throw(); 83 }; 84 85 class CFindFile: public CFindFileBase 86 { 87 public: 88 bool FindFirst(CFSTR wildcard, CFileInfo &fileInfo); 89 bool FindNext(CFileInfo &fileInfo); 90 }; 91 92 #if defined(_WIN32) && !defined(UNDER_CE) 93 94 struct CStreamInfo 95 { 96 UString Name; 97 UInt64 Size; 98 99 UString GetReducedName() const; 100 bool IsMainStream() const throw(); 101 }; 102 103 class CFindStream: public CFindFileBase 104 { 105 public: 106 bool FindFirst(CFSTR filePath, CStreamInfo &streamInfo); 107 bool FindNext(CStreamInfo &streamInfo); 108 }; 109 110 class CStreamEnumerator 111 { 112 CFindStream _find; 113 FString _filePath; 114 115 bool NextAny(CFileInfo &fileInfo); 116 public: 117 CStreamEnumerator(const FString &filePath): _filePath(filePath) {} 118 bool Next(CStreamInfo &streamInfo, bool &found); 119 }; 120 121 #endif 122 123 bool DoesFileExist(CFSTR name); 124 bool DoesDirExist(CFSTR name); 125 bool DoesFileOrDirExist(CFSTR name); 126 127 class CEnumerator 128 { 129 CFindFile _findFile; 130 FString _wildcard; 131 132 bool NextAny(CFileInfo &fileInfo); 133 public: 134 CEnumerator(const FString &wildcard): _wildcard(wildcard) {} 135 bool Next(CFileInfo &fileInfo); 136 bool Next(CFileInfo &fileInfo, bool &found); 137 }; 138 139 class CFindChangeNotification 140 { 141 HANDLE _handle; 142 public: 143 operator HANDLE () { return _handle; } 144 bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; } 145 CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {} 146 ~CFindChangeNotification() { Close(); } 147 bool Close() throw(); 148 HANDLE FindFirst(CFSTR pathName, bool watchSubtree, DWORD notifyFilter); 149 bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); } 150 }; 151 152 #ifndef UNDER_CE 153 bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings); 154 #endif 155 156 }}} 157 158 #endif 159