ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
286  SeekableWriteStream *createWriteStream(bool atomic = true) const;
287 
295  bool createDirectory() const;
296 };
297 
341 class FSDirectory : public Archive {
342  FSNode _node;
343  int _depth;
344  bool _flat;
345  bool _ignoreClashes;
346  bool _includeDirectories;
347 
348  Path _prefix; // string that is prepended to each cache item key
349  void setPrefix(const Path &prefix);
350 
351  // Caches are case insensitive, clashes are dealt with when creating
352  // Key is stored in lowercase.
355  mutable NodeCache _fileCache, _subDirCache;
356  mutable NodeMapCache _fileMapCache, _dirMapCache;
357  mutable bool _cached;
358 
359  // look for a match
360  FSNode *lookupCache(NodeCache &cache, const Path &name) const;
361 
362  // cache management
363  void cacheDirectoryRecursive(FSNode node, int depth, const Path& prefix) const;
364 
365  // fill cache if not already cached
366  void ensureCached() const;
367 
368 public:
374  FSDirectory(const Path &name, int depth = 1, bool flat = false,
375  bool ignoreClashes = false, bool includeDirectories = false);
379  FSDirectory(const FSNode &node, int depth = 1, bool flat = false,
380  bool ignoreClashes = false, bool includeDirectories = false);
381 
386  FSDirectory(const Path &prefix, const Path &name, int depth = 1,
387  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
391  FSDirectory(const Path &prefix, const FSNode &node, int depth = 1,
392  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
393 
394  virtual ~FSDirectory();
395 
399  FSNode getFSNode() const;
400 
405  FSDirectory *getSubDirectory(const Path &name, int depth = 1, bool flat = false,
406  bool ignoreClashes = false);
412  FSDirectory *getSubDirectory(const Path &prefix, const Path &name, int depth = 1,
413  bool flat = false, bool ignoreClashes = false);
414 
419  bool hasFile(const Path &path) const override;
420 
424  bool isPathDirectory(const Path &path) const override;
425 
429  int listMatchingMembers(ArchiveMemberList &list, const Path &pattern, bool matchPathComponents = false) const override;
430 
434  int listMembers(ArchiveMemberList &list) const override;
435 
440  const ArchiveMemberPtr getMember(const Path &path) const override;
441 
446  SeekableReadStream *createReadStreamForMember(const Path &path) const override;
447 
448  bool getChildren(const Common::Path &path, Common::Array<Common::String> &list, ListMode mode = kListDirectoriesOnly, bool hidden = true) const override;
449 
454  SeekableReadStream *createReadStreamForMemberAltStream(const Path &path, AltStreamType altStreamType) const override;
455 };
456 
459 } // End of namespace Common
460 
461 #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:341
Definition: abstract-fs.h:41