michael@0: // Windows/FileFind.h michael@0: michael@0: #ifndef __WINDOWS_FILEFIND_H michael@0: #define __WINDOWS_FILEFIND_H michael@0: michael@0: #include "../Common/String.h" michael@0: #include "../Common/Types.h" michael@0: #include "FileName.h" michael@0: #include "Defs.h" michael@0: michael@0: namespace NWindows { michael@0: namespace NFile { michael@0: namespace NFind { michael@0: michael@0: namespace NAttributes michael@0: { michael@0: inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; } michael@0: inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; } michael@0: inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; } michael@0: inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; } michael@0: inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; } michael@0: inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; } michael@0: inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; } michael@0: } michael@0: michael@0: class CFileInfoBase michael@0: { michael@0: bool MatchesMask(UINT32 mask) const { return ((Attributes & mask) != 0); } michael@0: public: michael@0: DWORD Attributes; michael@0: FILETIME CreationTime; michael@0: FILETIME LastAccessTime; michael@0: FILETIME LastWriteTime; michael@0: UInt64 Size; michael@0: michael@0: #ifndef _WIN32_WCE michael@0: UINT32 ReparseTag; michael@0: #else michael@0: DWORD ObjectID; michael@0: #endif michael@0: michael@0: bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); } michael@0: bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); } michael@0: bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); } michael@0: bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); } michael@0: bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); } michael@0: bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); } michael@0: bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); } michael@0: bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); } michael@0: bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); } michael@0: bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); } michael@0: bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); } michael@0: bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); } michael@0: }; michael@0: michael@0: class CFileInfo: public CFileInfoBase michael@0: { michael@0: public: michael@0: CSysString Name; michael@0: bool IsDots() const; michael@0: }; michael@0: michael@0: #ifdef _UNICODE michael@0: typedef CFileInfo CFileInfoW; michael@0: #else michael@0: class CFileInfoW: public CFileInfoBase michael@0: { michael@0: public: michael@0: UString Name; michael@0: bool IsDots() const; michael@0: }; michael@0: #endif michael@0: michael@0: class CFindFile michael@0: { michael@0: friend class CEnumerator; michael@0: HANDLE _handle; michael@0: bool _handleAllocated; michael@0: public: michael@0: bool IsHandleAllocated() const { return _handleAllocated; } michael@0: CFindFile(): _handleAllocated(false) {} michael@0: ~CFindFile() { Close(); } michael@0: bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo); michael@0: bool FindNext(CFileInfo &fileInfo); michael@0: #ifndef _UNICODE michael@0: bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo); michael@0: bool FindNext(CFileInfoW &fileInfo); michael@0: #endif michael@0: bool Close(); michael@0: }; michael@0: michael@0: bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo); michael@0: michael@0: bool DoesFileExist(LPCTSTR name); michael@0: #ifndef _UNICODE michael@0: bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo); michael@0: bool DoesFileExist(LPCWSTR name); michael@0: #endif michael@0: michael@0: class CEnumerator michael@0: { michael@0: CFindFile _findFile; michael@0: CSysString _wildcard; michael@0: bool NextAny(CFileInfo &fileInfo); michael@0: public: michael@0: CEnumerator(): _wildcard(NName::kAnyStringWildcard) {} michael@0: CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {} michael@0: bool Next(CFileInfo &fileInfo); michael@0: bool Next(CFileInfo &fileInfo, bool &found); michael@0: }; michael@0: michael@0: #ifdef _UNICODE michael@0: typedef CEnumerator CEnumeratorW; michael@0: #else michael@0: class CEnumeratorW michael@0: { michael@0: CFindFile _findFile; michael@0: UString _wildcard; michael@0: bool NextAny(CFileInfoW &fileInfo); michael@0: public: michael@0: CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {} michael@0: CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {} michael@0: bool Next(CFileInfoW &fileInfo); michael@0: bool Next(CFileInfoW &fileInfo, bool &found); michael@0: }; michael@0: #endif michael@0: michael@0: class CFindChangeNotification michael@0: { michael@0: HANDLE _handle; michael@0: public: michael@0: operator HANDLE () { return _handle; } michael@0: CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {} michael@0: ~CFindChangeNotification() { Close(); } michael@0: bool Close(); michael@0: HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter); michael@0: #ifndef _UNICODE michael@0: HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter); michael@0: #endif michael@0: bool FindNext() michael@0: { return BOOLToBool(::FindNextChangeNotification(_handle)); } michael@0: }; michael@0: michael@0: #ifndef _WIN32_WCE michael@0: bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings); michael@0: #ifndef _UNICODE michael@0: bool MyGetLogicalDriveStrings(UStringVector &driveStrings); michael@0: #endif michael@0: #endif michael@0: michael@0: inline bool MyGetCompressedFileSize(LPCTSTR fileName, UInt64 &size) michael@0: { michael@0: DWORD highPart; michael@0: DWORD lowPart = ::GetCompressedFileSize(fileName, &highPart); michael@0: if (lowPart == INVALID_FILE_SIZE) michael@0: if (::GetLastError() != NO_ERROR) michael@0: return false; michael@0: size = (UInt64(highPart) << 32) | lowPart; michael@0: return true; michael@0: } michael@0: michael@0: inline bool MyGetCompressedFileSizeW(LPCWSTR fileName, UInt64 &size) michael@0: { michael@0: DWORD highPart; michael@0: DWORD lowPart = ::GetCompressedFileSizeW(fileName, &highPart); michael@0: if (lowPart == INVALID_FILE_SIZE) michael@0: if (::GetLastError() != NO_ERROR) michael@0: return false; michael@0: size = (UInt64(highPart) << 32) | lowPart; michael@0: return true; michael@0: } michael@0: michael@0: }}} michael@0: michael@0: #endif michael@0: