00001
00002
00003
00004
00005 #ifndef __WINDOWS_FILEFIND_H
00006 #define __WINDOWS_FILEFIND_H
00007
00008 #include "String.h"
00009 #include "Types.h"
00010 #include "FileName.h"
00011 #include "Defs.h"
00012
00013 namespace NWindows {
00014 namespace NFile {
00015 namespace NFind {
00016
00017 namespace NAttributes
00018 {
00019 inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; }
00020 inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; }
00021 inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; }
00022 inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
00023 inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }
00024 inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }
00025 inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
00026 }
00027
00028 class CFileInfoBase
00029 {
00030 bool MatchesMask(UINT32 mask) const { return ((Attributes & mask) != 0); }
00031 public:
00032 DWORD Attributes;
00033 FILETIME CreationTime;
00034 FILETIME LastAccessTime;
00035 FILETIME LastWriteTime;
00036 UInt64 Size;
00037
00038 #ifndef _WIN32_WCE
00039 UINT32 ReparseTag;
00040 #else
00041 DWORD ObjectID;
00042 #endif
00043
00044 bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
00045 bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
00046 bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
00047 bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }
00048 bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }
00049 bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }
00050 bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }
00051 bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }
00052 bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }
00053 bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
00054 bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
00055 bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
00056 };
00057
00058 class CFileInfo: public CFileInfoBase
00059 {
00060 public:
00061 CSysString Name;
00062 bool IsDots() const;
00063 };
00064
00065 #ifdef _UNICODE
00066 typedef CFileInfo CFileInfoW;
00067 #else
00068 class CFileInfoW: public CFileInfoBase
00069 {
00070 public:
00071 UString Name;
00072 bool IsDots() const;
00073 };
00074 #endif
00075
00076 class CFindFile
00077 {
00078 friend class CEnumerator;
00079 HANDLE _handle;
00080 bool _handleAllocated;
00081 public:
00082 bool IsHandleAllocated() const { return _handleAllocated; }
00083 CFindFile(): _handleAllocated(false) {}
00084 ~CFindFile() { Close(); }
00085 bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
00086 bool FindNext(CFileInfo &fileInfo);
00087 #ifndef _UNICODE
00088 bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
00089 bool FindNext(CFileInfoW &fileInfo);
00090 #endif
00091 bool Close();
00092 };
00093
00094 bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
00095
00096 bool DoesFileExist(LPCTSTR name);
00097 #ifndef _UNICODE
00098 bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
00099 bool DoesFileExist(LPCWSTR name);
00100 #endif
00101
00102 class CEnumerator
00103 {
00104 CFindFile _findFile;
00105 CSysString _wildcard;
00106 bool NextAny(CFileInfo &fileInfo);
00107 public:
00108 CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
00109 CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
00110 bool Next(CFileInfo &fileInfo);
00111 bool Next(CFileInfo &fileInfo, bool &found);
00112 };
00113
00114 #ifdef _UNICODE
00115 typedef CEnumerator CEnumeratorW;
00116 #else
00117 class CEnumeratorW
00118 {
00119 CFindFile _findFile;
00120 UString _wildcard;
00121 bool NextAny(CFileInfoW &fileInfo);
00122 public:
00123 CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
00124 CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
00125 bool Next(CFileInfoW &fileInfo);
00126 bool Next(CFileInfoW &fileInfo, bool &found);
00127 };
00128 #endif
00129
00130 class CFindChangeNotification
00131 {
00132 HANDLE _handle;
00133 public:
00134 operator HANDLE () { return _handle; }
00135 CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
00136 ~CFindChangeNotification() { Close(); }
00137 bool Close();
00138 HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
00139 #ifndef _UNICODE
00140 HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);
00141 #endif
00142 bool FindNext()
00143 { return BOOLToBool(::FindNextChangeNotification(_handle)); }
00144 };
00145
00146 #ifndef _WIN32_WCE
00147 bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
00148 #ifndef _UNICODE
00149 bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
00150 #endif
00151 #endif
00152
00153 inline bool MyGetCompressedFileSize(LPCTSTR fileName, UInt64 &size)
00154 {
00155 DWORD highPart;
00156 DWORD lowPart = ::GetCompressedFileSize(fileName, &highPart);
00157 if (lowPart == INVALID_FILE_SIZE)
00158 if (::GetLastError() != NO_ERROR)
00159 return false;
00160 size = (UInt64(highPart) << 32) | lowPart;
00161 return true;
00162 }
00163
00164 inline bool MyGetCompressedFileSizeW(LPCWSTR fileName, UInt64 &size)
00165 {
00166 DWORD highPart;
00167 DWORD lowPart = ::GetCompressedFileSizeW(fileName, &highPart);
00168 if (lowPart == INVALID_FILE_SIZE)
00169 if (::GetLastError() != NO_ERROR)
00170 return false;
00171 size = (UInt64(highPart) << 32) | lowPart;
00172 return true;
00173 }
00174
00175 }}}
00176
00177 #endif
00178