annotate src/win32/7zip/7z/CPP/Windows/FileFind.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
rev   line source
rlm@1 1 // Windows/FileFind.h
rlm@1 2
rlm@1 3 #ifndef __WINDOWS_FILEFIND_H
rlm@1 4 #define __WINDOWS_FILEFIND_H
rlm@1 5
rlm@1 6 #include "../Common/MyString.h"
rlm@1 7 #include "../Common/Types.h"
rlm@1 8 #include "FileName.h"
rlm@1 9 #include "Defs.h"
rlm@1 10
rlm@1 11 namespace NWindows {
rlm@1 12 namespace NFile {
rlm@1 13 namespace NFind {
rlm@1 14
rlm@1 15 namespace NAttributes
rlm@1 16 {
rlm@1 17 inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }
rlm@1 18 inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }
rlm@1 19 inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }
rlm@1 20 inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }
rlm@1 21 inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
rlm@1 22 inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
rlm@1 23 inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
rlm@1 24 }
rlm@1 25
rlm@1 26 class CFileInfoBase
rlm@1 27 {
rlm@1 28 bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
rlm@1 29 public:
rlm@1 30 UInt64 Size;
rlm@1 31 FILETIME CTime;
rlm@1 32 FILETIME ATime;
rlm@1 33 FILETIME MTime;
rlm@1 34 DWORD Attrib;
rlm@1 35
rlm@1 36 #ifndef _WIN32_WCE
rlm@1 37 UINT32 ReparseTag;
rlm@1 38 #else
rlm@1 39 DWORD ObjectID;
rlm@1 40 #endif
rlm@1 41
rlm@1 42 bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
rlm@1 43 bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
rlm@1 44 bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
rlm@1 45 bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }
rlm@1 46 bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }
rlm@1 47 bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }
rlm@1 48 bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }
rlm@1 49 bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }
rlm@1 50 bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }
rlm@1 51 bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
rlm@1 52 bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
rlm@1 53 bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
rlm@1 54 };
rlm@1 55
rlm@1 56 class CFileInfo: public CFileInfoBase
rlm@1 57 {
rlm@1 58 public:
rlm@1 59 CSysString Name;
rlm@1 60 bool IsDots() const;
rlm@1 61 };
rlm@1 62
rlm@1 63 #ifdef _UNICODE
rlm@1 64 typedef CFileInfo CFileInfoW;
rlm@1 65 #else
rlm@1 66 class CFileInfoW: public CFileInfoBase
rlm@1 67 {
rlm@1 68 public:
rlm@1 69 UString Name;
rlm@1 70 bool IsDots() const;
rlm@1 71 };
rlm@1 72 #endif
rlm@1 73
rlm@1 74 class CFindFile
rlm@1 75 {
rlm@1 76 friend class CEnumerator;
rlm@1 77 HANDLE _handle;
rlm@1 78 public:
rlm@1 79 bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }
rlm@1 80 CFindFile(): _handle(INVALID_HANDLE_VALUE) {}
rlm@1 81 ~CFindFile() { Close(); }
rlm@1 82 bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
rlm@1 83 bool FindNext(CFileInfo &fileInfo);
rlm@1 84 #ifndef _UNICODE
rlm@1 85 bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
rlm@1 86 bool FindNext(CFileInfoW &fileInfo);
rlm@1 87 #endif
rlm@1 88 bool Close();
rlm@1 89 };
rlm@1 90
rlm@1 91 bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
rlm@1 92
rlm@1 93 bool DoesFileExist(LPCTSTR name);
rlm@1 94 #ifndef _UNICODE
rlm@1 95 bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
rlm@1 96 bool DoesFileExist(LPCWSTR name);
rlm@1 97 #endif
rlm@1 98
rlm@1 99 class CEnumerator
rlm@1 100 {
rlm@1 101 CFindFile _findFile;
rlm@1 102 CSysString _wildcard;
rlm@1 103 bool NextAny(CFileInfo &fileInfo);
rlm@1 104 public:
rlm@1 105 CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
rlm@1 106 CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
rlm@1 107 bool Next(CFileInfo &fileInfo);
rlm@1 108 bool Next(CFileInfo &fileInfo, bool &found);
rlm@1 109 };
rlm@1 110
rlm@1 111 #ifdef _UNICODE
rlm@1 112 typedef CEnumerator CEnumeratorW;
rlm@1 113 #else
rlm@1 114 class CEnumeratorW
rlm@1 115 {
rlm@1 116 CFindFile _findFile;
rlm@1 117 UString _wildcard;
rlm@1 118 bool NextAny(CFileInfoW &fileInfo);
rlm@1 119 public:
rlm@1 120 CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
rlm@1 121 CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
rlm@1 122 bool Next(CFileInfoW &fileInfo);
rlm@1 123 bool Next(CFileInfoW &fileInfo, bool &found);
rlm@1 124 };
rlm@1 125 #endif
rlm@1 126
rlm@1 127 class CFindChangeNotification
rlm@1 128 {
rlm@1 129 HANDLE _handle;
rlm@1 130 public:
rlm@1 131 operator HANDLE () { return _handle; }
rlm@1 132 bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE && _handle != 0; }
rlm@1 133 CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
rlm@1 134 ~CFindChangeNotification() { Close(); }
rlm@1 135 bool Close();
rlm@1 136 HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
rlm@1 137 #ifndef _UNICODE
rlm@1 138 HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);
rlm@1 139 #endif
rlm@1 140 bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }
rlm@1 141 };
rlm@1 142
rlm@1 143 #ifndef _WIN32_WCE
rlm@1 144 bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
rlm@1 145 #ifndef _UNICODE
rlm@1 146 bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
rlm@1 147 #endif
rlm@1 148 #endif
rlm@1 149
rlm@1 150 }}}
rlm@1 151
rlm@1 152 #endif
rlm@1 153