My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

bool PatternMatch(const char *p, const char *s);
bool PatternMatchMulti(const char *p, const char *s);

const char *GetFileNamePos(const char *path);
const char *GetFileExtPos(const char *path);

bool HasFileExt(const char *path);
bool HasWildcards(const char *path);
bool IsFullPath(const char *path);

String GetFileDirectory(const char *path); // with DIR_SEP at the end
String GetFileFolder(const char *path); // without DIR_SEP at the end, if not Win32 root
String GetFileTitle(const char *path);
String GetFileExt(const char *path);
String GetFileName(const char *path);

String AppendFileName(const String& path, const char *filename);

String WinPath(const char *path);
String UnixPath(const char *path);

#ifdef PLATFORM_WIN32
inline String NativePath(const char *path) { return WinPath(path); }
#endif

#ifdef PLATFORM_POSIX
inline String NativePath(const char *path) { return UnixPath(path); }
#endif

String AppendExt(const char *path, const char *ext);
String ForceExt(const char *path, const char *ext);

String GetFileOnPath(const char *file, const char *paths, bool current = true, const char *curdir = NULL);

#ifndef PLATFORM_WINCE
String GetFullPath(const char *path);
String GetCurrentDirectory();
#endif

struct FileTime;

int Compare_FileTime(const FileTime& fa, const FileTime& fb);

#ifdef PLATFORM_WIN32

struct FileTime : FILETIME, CompareRelOps<const FileTime&, &Compare_FileTime> {
FileTime() {}
FileTime(const FILETIME& ft) { dwLowDateTime = ft.dwLowDateTime;
dwHighDateTime = ft.dwHighDateTime; }
};

class FindFile {
WIN32_FIND_DATA *a;
WIN32_FIND_DATAW *w;
HANDLE handle;
String pattern;
String path;

void Init();
bool Next0();
void Close();

public:
bool Search(const char *path);
bool Next();

dword GetAttributes() const;
String GetName() const;
String GetPath() const;
int64 GetLength() const;
FileTime GetCreationTime() const;
FileTime GetLastAccessTime() const;
FileTime GetLastWriteTime() const;

bool IsDirectory() const;
bool IsFolder() const;
bool IsFile() const { return !IsDirectory(); }
bool IsSymLink() const;
bool IsExecutable() const;

bool IsArchive() const;
bool IsCompressed() const;
bool IsHidden() const;
bool IsReadOnly() const;
bool IsSystem() const;
bool IsTemporary() const;

operator bool() const { return handle != INVALID_HANDLE_VALUE; }

FindFile();
FindFile(const char *name);
~FindFile();
};

#endif

#ifdef PLATFORM_POSIX

struct FileTime : CompareRelOps<const FileTime&, &Compare_FileTime>
{
FileTime() {}
FileTime(time_t ft) : ft(ft) {}

operator time_t () const { return ft; }

time_t ft;
};

inline int Compare_FileTime(const FileTime& f, const FileTime& g) { return f.ft < g.ft ? -1 : f.ft > g.ft ? 1 : 0; }

class FindFile {
bool file;
DIR *dir;
mutable bool statis;
mutable struct stat statf;
String path;
String name;
String pattern;

struct stat &Stat() const;

public:
bool Search(const char *name);
bool Next();
void Close();

dword GetMode() const { return Stat().st_mode; }
String GetName() const { return name; }
String GetPath() const;
int64 GetLength() const { return Stat().st_size; }
FileTime GetLastChangeTime() const { return Stat().st_ctime; }
FileTime GetLastAccessTime() const { return Stat().st_atime; }
FileTime GetLastWriteTime() const { return Stat().st_mtime; }

bool IsReadOnly() const { return !(GetMode() & (S_IWUSR|S_IWGRP|S_IWOTH)); }

bool IsHidden() const { return *name == '.'; }
bool IsDirectory() const { return S_ISDIR(GetMode()); }
bool IsFolder() const;
bool IsFile() const { return S_ISREG(GetMode()); }
bool IsSymLink() const;
bool IsExecutable() const;

operator bool() const { return file; }

FindFile() { file = false; dir = NULL; }
FindFile(const char *name);
~FindFile() { Close(); }
};

// POSIX FileTime is unfortunately long int and clashes with Date::operator int()
inline bool operator==(Time a, FileTime b) { return a == Time(b); }
inline bool operator!=(Time a, FileTime b) { return a != Time(b); }

inline bool operator==(FileTime a, Time b) { return Time(a) == b; }
inline bool operator!=(FileTime a, Time b) { return Time(a) != b; }

#endif

int64 GetFileLength(const char *path);
bool FileExists(const char *path);
bool DirectoryExists(const char *path);

struct Time;
FileTime GetFileTime(const char *path);
Time FileGetTime(const char *path);
bool SetFileTime(const char *path, FileTime ft);
bool FileSetTime(const char *path, Time time);
FileTime TimeToFileTime(Time time);

bool FileCopy(const char *oldpath, const char *newpath);
bool FileMove(const char *oldpath, const char *newpath);
bool FileDelete(const char *path);

#ifdef PLATFORM_POSIX
bool DirectoryCreate(const char *path, int mode = 0755);
bool RealizeDirectory(const String& path, int mode = 0755);
bool RealizePath(const String& path, int mode = 0755);
#else
bool DirectoryCreate(const char *path);
bool RealizeDirectory(const String& path);
bool RealizePath(const String& path);
#endif

bool DirectoryDelete(const char *path);

String NormalizePath(const char *path, const char *currdir);
String NormalizePath(const char *path);

bool PathIsEqual(const char *p1, const char *p2);

#ifdef PLATFORM_POSIX
inline bool DeleteFile(const char *fn) { return unlink(fn) == 0; }
#endif

bool DeleteFolderDeep(const char *dir);

#ifndef PLATFORM_WINCE
String GetTempPath();
String GetTempFileName(const char *prefix = NULL);
#endif

String GetSymLinkPath(const char *linkpath);

template <class T>
class Array;

class FileSystemInfo {
public:
enum
{
ROOT_UNKNOWN = 0,
ROOT_NO_ROOT_DIR = 1,
ROOT_REMOVABLE = 2,
ROOT_FIXED = 3,
ROOT_REMOTE = 4,
ROOT_CDROM = 5,
ROOT_RAMDISK = 6,
ROOT_NETWORK = 7,
ROOT_COMPUTER = 8,
};

enum
{
STYLE_WIN32 = 0x0001,
STYLE_POSIX = 0x0002,
};

struct FileInfo
{
FileInfo();

operator bool () const { return !IsNull(filename); }

String filename;
String msdos_name;
String root_desc;
int64 length;
Time last_access_time;
Time last_write_time;
Time creation_time;
bool read_only;
bool is_directory;
bool is_folder;
bool is_file;
bool is_symlink;
bool is_archive;
bool is_compressed;
bool is_hidden;
bool is_read_only;
bool is_system;
bool is_temporary;
char root_style;
dword unix_mode;
};

virtual int GetStyle() const;
bool IsWin32() const { return GetStyle() & STYLE_WIN32; }
bool IsPosix() const { return GetStyle() & STYLE_POSIX; }

virtual Array<FileInfo> Find(String mask, int max_count = 1000000, bool unmounted = false) const; // mask = Null -> root
virtual bool CreateFolder(String path, String& error) const;

bool FolderExists(String path) const;

virtual ~FileSystemInfo() {}
};

FileSystemInfo& StdFileSystemInfo();

#ifdef PLATFORM_WIN32

class NetNode : Moveable<NetNode> {
NETRESOURCE net;
String local, remote, comment, provider;

String name;
String path;

static void Copy(String& t, char *s);
static Array<NetNode> Enum0(HANDLE hEnum);
static void SetPtr(String& s, char *& ptr);

void SetPtrs();

public:
enum {
UNKNOWN, NETWORK, GROUP, SERVER, SHARE
};
String GetName() const { return name; }
String GetPath() const { return path; }
int GetDisplayType() const;
String GetRemote() const { return remote; }
String GetLocal() const { return local; }
String GetProvider() const { return provider; }
String GetComment() const { return comment; }
Array<NetNode> Enum() const;

void Serialize(Stream& s);

static Array<NetNode> EnumRoot();
static Array<NetNode> EnumRemembered();

NetNode();
NetNode(const NetNode& s) { *this = s; }

NetNode& operator=(const NetNode& s);
};

#endif

Change log

r4660 by cxl on Mar 5, 2012   Diff
NetNode: More getters (thanks kropniczki)
Go to: 
Project members, sign in to write a code review

Older revisions

r4451 by cxl on Jan 20, 2012   Diff
Core: FindFile::GetPath - POSIX
support
r4449 by cxl on Jan 20, 2012   Diff
Core: FindFile::GetPath
r4325 by unodgs on Dec 18, 2011   Diff
Core: Added unmounted parameter to
FileSystemInfo::Find to allow
including registered drives with no
content (like cdrom)
All revisions of this file

File info

Size: 8590 bytes, 311 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting