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