view 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
line wrap: on
line source
1 // Windows/FileFind.h
3 #ifndef __WINDOWS_FILEFIND_H
4 #define __WINDOWS_FILEFIND_H
6 #include "../Common/MyString.h"
7 #include "../Common/Types.h"
8 #include "FileName.h"
9 #include "Defs.h"
11 namespace NWindows {
12 namespace NFile {
13 namespace NFind {
15 namespace NAttributes
16 {
17 inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }
18 inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }
19 inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }
20 inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }
21 inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
22 inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
23 inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
24 }
26 class CFileInfoBase
27 {
28 bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
29 public:
30 UInt64 Size;
31 FILETIME CTime;
32 FILETIME ATime;
33 FILETIME MTime;
34 DWORD Attrib;
36 #ifndef _WIN32_WCE
37 UINT32 ReparseTag;
38 #else
39 DWORD ObjectID;
40 #endif
42 bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
43 bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
44 bool IsDir() 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 };
56 class CFileInfo: public CFileInfoBase
57 {
58 public:
59 CSysString Name;
60 bool IsDots() const;
61 };
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
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 };
91 bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
93 bool DoesFileExist(LPCTSTR name);
94 #ifndef _UNICODE
95 bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
96 bool DoesFileExist(LPCWSTR name);
97 #endif
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 };
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
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 };
143 #ifndef _WIN32_WCE
144 bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
145 #ifndef _UNICODE
146 bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
147 #endif
148 #endif
150 }}}
152 #endif