@@ -31,6 +31,22 @@ namespace AGS
3131namespace Common
3232{
3333
34+ // FileEntry describes a single entry in the filesystem.
35+ struct FileEntry
36+ {
37+ String Name;
38+ // TODO: make flags instead?
39+ bool IsFile = false ;
40+ bool IsDir = false ;
41+ time_t Time{};
42+
43+ FileEntry () = default ;
44+ FileEntry (const String &name, bool is_file, bool is_dir, const time_t &time)
45+ : Name(name), IsFile(is_file), IsDir(is_dir), Time(time) {}
46+
47+ operator bool () const { return !Name.IsEmpty (); }
48+ };
49+
3450namespace Directory
3551{
3652 // Creates new directory (if it does not exist)
@@ -47,25 +63,15 @@ namespace Directory
4763 void GetDirs (const String &dir_path, std::vector<String> &dirs);
4864 // Get list of files found in the given directory
4965 void GetFiles (const String &dir_path, std::vector<String> &files);
66+ // Get list of files found in the given directory using wildcard pattern
67+ void GetFiles (const String &dir_path, std::vector<String> &files, const String &wildcard);
68+ // Get list of file entries in the given directory using wildcard pattern
69+ void GetFiles (const String &dir_path, std::vector<FileEntry> &files, const String &wildcard);
70+ // Tells whether there are any files in the given directory
71+ bool HasAnyFiles (const String &dir_path);
5072} // namespace Directory
5173
5274
53- // FileEntry describes a single entry in the filesystem.
54- struct FileEntry
55- {
56- String Name;
57- // TODO: make flags instead?
58- bool IsFile = false ;
59- bool IsDir = false ;
60- time_t Time{};
61-
62- FileEntry () = default ;
63- FileEntry (const String &name, bool is_file, bool is_dir, const time_t &time)
64- : Name(name), IsFile(is_file), IsDir(is_dir), Time(time) {}
65-
66- operator bool () const { return !Name.IsEmpty (); }
67- };
68-
6975//
7076// DirectoryIterator iterates entries in the directory.
7177// The order of iteration is undefined.
@@ -202,6 +208,74 @@ class FindFile
202208 bool _doDirs = false ;
203209};
204210
211+
212+ //
213+ // FileEntry comparators
214+ //
215+ struct FileEntryEqByName
216+ {
217+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
218+ {
219+ return fe1.Name == fe2.Name ;
220+ }
221+ };
222+
223+ struct FileEntryEqByNameCI
224+ {
225+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
226+ {
227+ return fe1.Name .CompareNoCase (fe2.Name ) == 0 ;
228+ }
229+ };
230+
231+ struct FileEntryCmpByName
232+ {
233+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
234+ {
235+ return fe1.Name .Compare (fe2.Name ) < 0 ;
236+ }
237+ };
238+
239+ struct FileEntryCmpByNameDsc
240+ {
241+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
242+ {
243+ return fe2.Name .Compare (fe1.Name ) < 0 ;
244+ }
245+ };
246+
247+ struct FileEntryCmpByNameCI
248+ {
249+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
250+ {
251+ return fe1.Name .CompareNoCase (fe2.Name ) < 0 ;
252+ }
253+ };
254+
255+ struct FileEntryCmpByNameDscCI
256+ {
257+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
258+ {
259+ return fe2.Name .CompareNoCase (fe1.Name ) < 0 ;
260+ }
261+ };
262+
263+ struct FileEntryCmpByTime
264+ {
265+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
266+ {
267+ return fe1.Time < fe2.Time ;
268+ }
269+ };
270+
271+ struct FileEntryCmpByTimeDsc
272+ {
273+ bool operator ()(const FileEntry &fe1, const FileEntry &fe2) const
274+ {
275+ return fe2.Time < fe1.Time ;
276+ }
277+ };
278+
205279} // namespace Common
206280} // namespace AGS
207281
0 commit comments