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 
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.
354  mutable NodeCache _fileCache, _subDirCache;
355  mutable bool _cached;
356 
357  // look for a match
358  FSNode *lookupCache(NodeCache &cache, const Path &name) const;
359 
360  // cache management
361  void cacheDirectoryRecursive(FSNode node, int depth, const Path& prefix) const;
362 
363  // fill cache if not already cached
364  void ensureCached() const;
365 
366 public:
372  FSDirectory(const Path &name, int depth = 1, bool flat = false,
373  bool ignoreClashes = false, bool includeDirectories = false);
377  FSDirectory(const FSNode &node, int depth = 1, bool flat = false,
378  bool ignoreClashes = false, bool includeDirectories = false);
379 
384  FSDirectory(const Path &prefix, const Path &name, int depth = 1,
385  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
389  FSDirectory(const Path &prefix, const FSNode &node, int depth = 1,
390  bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
391 
392  virtual ~FSDirectory();
393 
397  FSNode getFSNode() const;
398 
403  FSDirectory *getSubDirectory(const Path &name, int depth = 1, bool flat = false,
404  bool ignoreClashes = false);
410  FSDirectory *getSubDirectory(const Path &prefix, const Path &name, int depth = 1,
411  bool flat = false, bool ignoreClashes = false);
412 
417  bool hasFile(const Path &path) const override;
418 
422  bool isPathDirectory(const Path &path) const override;
423 
427  int listMatchingMembers(ArchiveMemberList &list, const Path &pattern, bool matchPathComponents = false) const override;
428 
432  int listMembers(ArchiveMemberList &list) const override;
433 
438  const ArchiveMemberPtr getMember(const Path &path) const override;
439 
444  SeekableReadStream *createReadStreamForMember(const Path &path) const override;
445 
450  SeekableReadStream *createReadStreamForMemberAltStream(const Path &path, AltStreamType altStreamType) const override;
451 };
452 
455 } // End of namespace Common
456 
457 #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