blob: 5b7298e23dade9221ccfd02221e49cfaf2f867af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
// Windows/FileFind.h
#ifndef __WINDOWS_FILEFIND_H
#define __WINDOWS_FILEFIND_H
#include "../Common/MyString.h"
#include "FileName.h"
#include "Defs.h"
#include "../Common/MyWindows.h"
#include <sys/types.h> /* for DIR */
#ifdef ENV_UNIX
#include <dirent.h>
#else
typedef void DIR;
typedef unsigned long long UInt64;
#endif
namespace NWindows {
namespace NFile {
namespace NFind {
namespace NAttributes
{
inline bool IsReadOnly(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_READONLY) != 0; }
inline bool IsHidden(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; }
inline bool IsSystem(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; }
inline bool IsDir(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_DIRECTORY) != 0; }
inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; }
inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; }
inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
}
class CFileInfoBase
{
bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
public:
UInt64 Size;
FILETIME CTime;
FILETIME ATime;
FILETIME MTime;
DWORD Attrib;
bool IsDevice;
#ifndef ENV_UNIX
#ifndef _WIN32_WCE
UINT32 ReparseTag;
#else
DWORD ObjectID;
#endif
#endif
bool IsDir() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
};
class CFileInfo: public CFileInfoBase
{
public:
AString Name; // FIXME CSysString Name;
bool IsDots() const;
bool Find(LPCSTR wildcard);
};
// FIXME #ifdef _UNICODE
// typedef CFileInfo CFileInfoW;
// #else
class CFileInfoW: public CFileInfoBase
{
public:
UString Name;
bool IsDots() const;
bool Find(LPCWSTR wildcard);
};
// #endif
class CFindFile
{
friend class CEnumerator;
#ifdef ENV_UNIX
DIR *_dirp;
#else
HANDLE _handle;
#endif
AString _pattern;
AString _directory;
public:
#ifdef ENV_UNIX
CFindFile(): _dirp(0) {}
bool IsHandleAllocated() const { return (_dirp != 0); }
#else
CFindFile(): _handle( INVALID_HANDLE_VALUE ) {}
bool IsHandleAllocated() const { return (_handle != INVALID_HANDLE_VALUE ); }
#endif
~CFindFile() { Close(); }
// bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
bool FindFirst(LPCSTR wildcard, CFileInfo &fileInfo);
bool FindNext(CFileInfo &fileInfo);
// FIXME #ifndef _UNICODE
bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
bool FindNext(CFileInfoW &fileInfo);
// FIXME #endif
bool Close();
};
bool FindFile(LPCSTR wildcard, CFileInfo &fileInfo);
bool DoesFileExist(LPCSTR name);
bool DoesFileOrDirExist(LPCSTR name);
// #ifndef _UNICODE
bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
bool DoesFileExist(LPCWSTR name);
bool DoesFileOrDirExist(LPCWSTR name);
// #endif
class CEnumerator
{
CFindFile _findFile;
AString _wildcard; // FIXME CSysString _wildcard;
bool NextAny(CFileInfo &fileInfo);
public:
CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
// FIXME CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
CEnumerator(const AString &wildcard): _wildcard(wildcard) {}
bool Next(CFileInfo &fileInfo);
bool Next(CFileInfo &fileInfo, bool &found);
};
// FIXME #ifdef _UNICODE
// typedef CEnumerator CEnumeratorW;
// #else
class CEnumeratorW
{
CFindFile _findFile;
UString _wildcard;
bool NextAny(CFileInfoW &fileInfo);
public:
CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
bool Next(CFileInfoW &fileInfo);
bool Next(CFileInfoW &fileInfo, bool &found);
};
// FIXME #endif
}}}
#endif
|