ScummVM API documentation
directory.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Platform-independent Directory functions
25 //
26 //=============================================================================
27 
28 #ifndef AGS_SHARED_UTIL_DIRECTORY_H
29 #define AGS_SHARED_UTIL_DIRECTORY_H
30 
31 #include "common/fs.h"
32 #include "common/stack.h"
33 #include "common/std/memory.h"
34 #include "ags/shared/core/platform.h"
35 #include "ags/shared/util/string.h"
36 
37 namespace AGS3 {
38 namespace AGS {
39 namespace Shared {
40 
41 extern const char *SAVE_FOLDER_PREFIX;
42 
43 namespace Directory {
44 
45 // Creates new directory (if it does not exist)
46 bool CreateDirectory(const String &path);
47 // Makes sure all the sub-directories in the path are created. Parent path is
48 // not touched, and function must fail if parent path is not accessible.
49 bool CreateAllDirectories(const String &parent, const String &sub_dirs);
50 // Sets current working directory, returns the resulting path
51 String SetCurrentDirectory(const String &path);
52 // Gets current working directory
53 String GetCurrentDirectory();
54 
55 // Get list of subdirs found in the given directory
56 bool GetDirs(const String &dir_path, std::vector<String> &dirs);
57 // Get list of files found in the given directory
58 bool GetFiles(const String &dir_path, std::vector<String> &files);
59 
60 } // namespace Directory
61 
62 class FindFile {
63 private:
64  Common::FSNode _folder;
65  Common::FSList _files;
66  int _index = 0;
67 
68 private:
69  static FindFile Open(const String &path, const String &wildcard,
70  bool do_file, bool do_dir);
71 
72 public:
73  FindFile() {}
74  ~FindFile();
75  static FindFile OpenFiles(const String &path, const String &wildcard = "*") {
76  return Open(path, wildcard, true, false);
77  }
78  static FindFile OpenDirs(const String &path, const String &wildcard = "*") {
79  return Open(path, wildcard, false, true);
80  }
81  bool AtEnd() const {
82  return (_index >= (int)_files.size());
83  }
84  String Current() const {
85  return AtEnd() ? String() : String(_files[_index].getName().c_str());
86  }
87  void Close();
88  bool Next();
89 };
90 
92 public:
95 
96  static FindFileRecursive Open(const String &path, const String &wildcard = "*",
97  size_t max_level = -1);
98  // TODO: directory mode, like in FindFile
99  bool AtEnd() const {
100  return _ffile.AtEnd();
101  }
102  String Current() const {
103  return _curFile;
104  }
105  void Close();
106  bool Next();
107 
108 private:
109  bool PushDir(const String &sub);
110  bool PopDir();
111 
113  FindFile _fdir; // current find dir iterator
114  FindFile _ffile; // current find file iterator
115  uint32_t _maxLevel = SIZE_MAX;
116  String _fullDir; // full directory path
117  String _curDir; // current dir path, relative to the base path
118  String _curFile; // current file path with parent dirs
119 };
120 
121 } // namespace Shared
122 } // namespace AGS
123 } // namespace AGS3
124 
125 #endif
Definition: achievements_tables.h:27
Definition: directory.h:91
Definition: fs.h:69
Definition: fs.h:57
Definition: directory.h:62
size_type size() const
Definition: array.h:315
Definition: string.h:62
Definition: stack.h:102
Definition: ags.h:40