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
33class AbstractFSNode;
34
35namespace Common {
36
46class FSNode;
47class FSDirectory;
48class SeekableReadStream;
49class WriteStream;
50class SeekableWriteStream;
51
57class FSList : public Array<FSNode> {};
58
69class FSNode : public ArchiveMember {
70private:
71 friend class ::AbstractFSNode;
72 friend class FSDirectory;
80 FSNode(AbstractFSNode *realNode);
81
82public:
86 enum ListMode {
87 kListFilesOnly = 1,
88 kListDirectoriesOnly = 2,
89 kListAll = 3
90 };
91
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
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
263
272 SeekableReadStream *createReadStreamForAltStream(AltStreamType altStreamType) const override;
273
286 SeekableWriteStream *createWriteStream(bool atomic = true) const;
287
295 bool createDirectory() const;
296};
297
341class 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
368public:
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
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
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: abstract-fs.h:41
Definition: archive.h:141
Definition: archive.h:68
Definition: array.h:52
Definition: fs.h:341
SeekableReadStream * createReadStreamForMemberAltStream(const Path &path, AltStreamType altStreamType) const override
const ArchiveMemberPtr getMember(const Path &path) const override
FSDirectory * getSubDirectory(const Path &name, int depth=1, bool flat=false, bool ignoreClashes=false)
bool isPathDirectory(const Path &path) const override
int listMatchingMembers(ArchiveMemberList &list, const Path &pattern, bool matchPathComponents=false) const override
FSDirectory(const Path &prefix, const Path &name, int depth=1, bool flat=false, bool ignoreClashes=false, bool includeDirectories=false)
FSDirectory(const FSNode &node, int depth=1, bool flat=false, bool ignoreClashes=false, bool includeDirectories=false)
int listMembers(ArchiveMemberList &list) const override
FSDirectory(const Path &prefix, const FSNode &node, int depth=1, bool flat=false, bool ignoreClashes=false, bool includeDirectories=false)
FSNode getFSNode() const
FSDirectory(const Path &name, int depth=1, bool flat=false, bool ignoreClashes=false, bool includeDirectories=false)
SeekableReadStream * createReadStreamForMember(const Path &path) const override
bool hasFile(const Path &path) const override
FSDirectory * getSubDirectory(const Path &prefix, const Path &name, int depth=1, bool flat=false, bool ignoreClashes=false)
Definition: fs.h:57
Definition: fs.h:69
ListMode
Definition: fs.h:86
bool isDirectory() const override
void listChildren(Common::ArchiveMemberList &childList, const char *pattern=nullptr) const override
U32String getDisplayName() const override
bool exists() const
virtual String getRealName() const
SeekableReadStream * createReadStreamForAltStream(AltStreamType altStreamType) const override
SeekableWriteStream * createWriteStream(bool atomic=true) const
bool isWritable() const
FSNode getParent() const
String getName() const override
bool getChildren(FSList &fslist, ListMode mode=kListDirectoriesOnly, bool hidden=true) const
SeekableReadStream * createReadStream() const override
FSNode getChild(const String &name) const
Path getPath() const
bool isReadable() const
bool operator<(const FSNode &node) const
bool createDirectory() const
String getFileName() const override
FSNode(const Path &path)
Path getPathInArchive() const override
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: stream.h:351
Definition: str.h:59
Definition: ustr.h:57
Definition: algorithm.h:29