ScummVM API documentation
fs.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 #ifndef COMMON_FS_H
23 #define COMMON_FS_H
24 
25 #include "common/array.h"
26 #include "common/archive.h"
27 #include "common/hash-str.h"
28 #include "common/hashmap.h"
29 #include "common/ptr.h"
30 #include "common/str.h"
31 #include "common/ustr.h"
32 
33 class AbstractFSNode;
34 
35 namespace Common {
36 
46 class FSNode;
47 class FSDirectory;
48 class SeekableReadStream;
49 class WriteStream;
50 class SeekableWriteStream;
51 
57 class FSList : public Array<FSNode> {};
58 
69 class FSNode : public ArchiveMember {
70 private:
71  friend class ::AbstractFSNode;
72  friend class FSDirectory;
73  SharedPtr<AbstractFSNode> _realNode;
80  FSNode(AbstractFSNode *realNode);
81 
82 public:
86  enum ListMode {
87  kListFilesOnly = 1,
88  kListDirectoriesOnly = 2,
89  kListAll = 3
90  };
91 
97  FSNode();
98 
108  explicit FSNode(const Path &path);
109  ~FSNode();
110 
115  bool operator<(const FSNode& node) const;
116 
122  bool exists() const;
123 
141  FSNode getChild(const String &name) const;
142 
149  bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = true) const;
150 
158  U32String getDisplayName() const override;
159 
168  String getName() const override;
169 
175  String getFileName() const override;
176 
184  Path getPathInArchive() const override;
185 
194  virtual String getRealName() const;
195 
204  Path getPath() const;
205 
210  FSNode getParent() const;
211 
221  bool isDirectory() const override;
222 
227  void listChildren(Common::ArchiveMemberList &childList, const char *pattern = nullptr) const override;
228 
240  bool isReadable() const;
241 
253  bool isWritable() const;
254 
262  SeekableReadStream *createReadStream() const override;
263 
272  SeekableReadStream *createReadStreamForAltStream(AltStreamType altStreamType) const override;
273 
281  SeekableWriteStream *createWriteStream() const;
282 
290  bool createDirectory() const;
291 };
292 
336 class FSDirectory : public Archive {
337  FSNode _node;
338  int _depth;
339  bool _flat;
340  bool _ignoreClashes;
341  bool _includeDirectories;
342 
343  Path _prefix; // string that is prepended to each cache item key
344  void setPrefix(const Path &prefix);
345 
346  // Caches are case insensitive, clashes are dealt with when creating
347  // Key is stored in lowercase.
349  mutable NodeCache _fileCache, _subDirCache;
350  mutable bool _cached;
351 
352  // look for a match
353  FSNode *lookupCache(NodeCache &cache, const Path &name) const;
354 
355  // cache management
356  void cacheDirectoryRecursive(FSNode node, int depth, const Path& prefix) const;
357 
358  // fill cache if not already cached
359  void ensureCached() const;
360 
361 public:
367  FSDirectory(const Path &name, int depth = 1, bool flat = false,
368  bool ignoreClashes = false, bool includeDirectories = false);
372  FSDirectory(const FSNode &node, int depth = 1, bool flat = false,
373  bool ignoreClashes = false, bool includeDirectories = false);
374 
379  FSDirectory(const Path &prefix, const Path &name, int depth = 1,
380  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
384  FSDirectory(const Path &prefix, const FSNode &node, int depth = 1,
385  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
386 
387  virtual ~FSDirectory();
388 
392  FSNode getFSNode() const;
393 
398  FSDirectory *getSubDirectory(const Path &name, int depth = 1, bool flat = false,
399  bool ignoreClashes = false);
405  FSDirectory *getSubDirectory(const Path &prefix, const Path &name, int depth = 1,
406  bool flat = false, bool ignoreClashes = false);
407 
412  bool hasFile(const Path &path) const override;
413 
417  bool isPathDirectory(const Path &path) const override;
418 
422  int listMatchingMembers(ArchiveMemberList &list, const Path &pattern, bool matchPathComponents = false) const override;
423 
427  int listMembers(ArchiveMemberList &list) const override;
428 
433  const ArchiveMemberPtr getMember(const Path &path) const override;
434 
439  SeekableReadStream *createReadStreamForMember(const Path &path) const override;
440 
445  SeekableReadStream *createReadStreamForMemberAltStream(const Path &path, AltStreamType altStreamType) const override;
446 };
447 
450 } // End of namespace Common
451 
452 #endif //COMMON_FS_H
Definition: str.h:59
Definition: array.h:52
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: archive.h:141
Definition: ustr.h:57
ListMode
Definition: fs.h:86
Definition: archive.h:68
Definition: algorithm.h:29
Definition: fs.h:69
Definition: fs.h:57
Definition: stream.h:351
Definition: fs.h:336
Definition: abstract-fs.h:41