2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-02-18 02:34:18 +01:00
|
|
|
*
|
2002-11-13 17:16:18 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-24 08:07:48 +00:00
|
|
|
#ifndef COMMON_FS_H
|
|
|
|
#define COMMON_FS_H
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
#include "common/array.h"
|
2008-12-27 18:03:27 +00:00
|
|
|
#include "common/archive.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/hash-str.h"
|
|
|
|
#include "common/hashmap.h"
|
2008-03-29 21:12:36 +00:00
|
|
|
#include "common/ptr.h"
|
2006-05-03 11:42:50 +00:00
|
|
|
#include "common/str.h"
|
2021-07-01 10:11:51 +01:00
|
|
|
#include "common/ustr.h"
|
2006-05-03 11:42:50 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
class AbstractFSNode;
|
2008-08-03 18:35:51 +00:00
|
|
|
|
|
|
|
namespace Common {
|
2006-06-24 08:07:48 +00:00
|
|
|
|
2020-07-08 23:30:36 +02:00
|
|
|
/**
|
|
|
|
* @defgroup common_fs File system
|
|
|
|
* @ingroup common
|
|
|
|
*
|
|
|
|
* @brief API for operations on the file system.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
class FSNode;
|
2022-12-09 05:12:27 +01:00
|
|
|
class FSDirectory;
|
2008-09-03 11:22:51 +00:00
|
|
|
class SeekableReadStream;
|
|
|
|
class WriteStream;
|
2021-07-29 18:41:15 -07:00
|
|
|
class SeekableWriteStream;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* List of multiple file system nodes. For example, the contents of a given directory.
|
|
|
|
* This is a subclass instead of just a typedef so that forward declarations
|
|
|
|
* of it can be used in other places.
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2008-12-27 18:03:27 +00:00
|
|
|
class FSList : public Array<FSNode> {};
|
2006-05-03 11:42:50 +00:00
|
|
|
|
2007-03-08 15:02:13 +00:00
|
|
|
/**
|
2008-10-02 16:58:59 +00:00
|
|
|
* FSNode, short for "File System Node", provides an abstraction for file
|
2020-10-08 00:04:21 +02:00
|
|
|
* paths, allowing for portable file system browsing. This means, for example,
|
2008-10-02 16:58:59 +00:00
|
|
|
* that multiple or single roots have to be supported (compare Unix with a
|
|
|
|
* single root, Windows with multiple roots C:, D:, ...).
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
|
|
|
* To this end, we abstract away from paths; implementations can be based on
|
2020-10-08 00:04:21 +02:00
|
|
|
* paths (and it is left to them whether '/', '\', or ':' is the path separator)
|
2002-11-13 17:16:18 +00:00
|
|
|
* but it is also possible to use inodes or vrefs (MacOS 9) or anything else.
|
|
|
|
*/
|
2008-12-27 18:03:27 +00:00
|
|
|
class FSNode : public ArchiveMember {
|
2004-11-20 21:35:49 +00:00
|
|
|
private:
|
2016-01-07 11:14:00 +01:00
|
|
|
friend class ::AbstractFSNode;
|
2022-12-09 05:12:27 +01:00
|
|
|
friend class FSDirectory;
|
2008-12-27 18:03:27 +00:00
|
|
|
SharedPtr<AbstractFSNode> _realNode;
|
2016-01-07 11:14:00 +01:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Construct an FSNode from a backend's AbstractFSNode implementation.
|
2016-01-07 11:14:00 +01:00
|
|
|
*
|
|
|
|
* @param realNode Pointer to a heap allocated instance. FSNode will take
|
|
|
|
* ownership of the pointer.
|
|
|
|
*/
|
2016-01-06 10:45:25 +01:00
|
|
|
FSNode(AbstractFSNode *realNode);
|
2015-12-01 18:53:52 +01:00
|
|
|
|
2016-01-07 11:14:00 +01:00
|
|
|
public:
|
2016-01-06 10:45:25 +01:00
|
|
|
/**
|
2006-05-03 10:14:05 +00:00
|
|
|
* Flag to tell listDir() which kind of files to list.
|
|
|
|
*/
|
|
|
|
enum ListMode {
|
|
|
|
kListFilesOnly = 1,
|
|
|
|
kListDirectoriesOnly = 2,
|
|
|
|
kListAll = 3
|
|
|
|
};
|
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Create a new pathless FSNode. Since there is no path associated
|
2008-01-27 19:47:41 +00:00
|
|
|
* with this node, path-related operations (i.e. exists(), isDirectory(),
|
2007-08-18 05:24:18 +00:00
|
|
|
* getPath()) will always return false or raise an assertion.
|
2006-05-12 21:41:54 +00:00
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode();
|
2006-05-03 10:14:05 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
2008-10-02 16:58:59 +00:00
|
|
|
* Create a new FSNode referring to the specified path. This is
|
2006-04-30 22:52:10 +00:00
|
|
|
* the counterpart to the path() method.
|
2006-05-12 21:41:54 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* If the path is empty or equals ".", then a node representing the "current
|
2006-05-12 21:41:54 +00:00
|
|
|
* directory" will be created. If that is not possible (since e.g. the
|
2020-10-08 00:04:21 +02:00
|
|
|
* operating system does not support the concept), some other directory is
|
2006-05-12 21:41:54 +00:00
|
|
|
* used (usually the root directory).
|
2006-04-30 22:52:10 +00:00
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
explicit FSNode(const Path &path);
|
2006-04-30 22:52:10 +00:00
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
virtual ~FSNode() {}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-07-22 17:01:50 +00:00
|
|
|
/**
|
2007-05-03 02:39:33 +00:00
|
|
|
* Compare the name of this node to the name of another. Directories
|
|
|
|
* go before normal files.
|
2006-07-22 17:01:50 +00:00
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
bool operator<(const FSNode& node) const;
|
2006-07-22 17:01:50 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Indicate whether the object referred by this node exists in the file system or not.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return True if the node exists, false otherwise.
|
2006-04-30 22:52:10 +00:00
|
|
|
*/
|
2010-02-13 11:57:01 +00:00
|
|
|
bool exists() const;
|
2004-05-06 10:34:41 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
2008-09-02 16:35:16 +00:00
|
|
|
* Create a new node referring to a child node of the current node, which
|
2008-09-07 21:47:01 +00:00
|
|
|
* must be a directory node (otherwise an invalid node is returned).
|
2008-09-02 16:35:16 +00:00
|
|
|
* If a child matching the name exists, a normal node for it is returned.
|
|
|
|
* If no child with the name exists, a node for it is still returned,
|
|
|
|
* but exists() will return 'false' for it. This node can however be used
|
2009-01-23 03:41:36 +00:00
|
|
|
* to create a new file using the createWriteStream() method.
|
2008-09-02 16:35:16 +00:00
|
|
|
*
|
2009-01-23 03:41:36 +00:00
|
|
|
* @todo If createWriteStream() (or a hypothetical future mkdir() method) is used,
|
2008-09-02 16:35:16 +00:00
|
|
|
* this should affect what exists/isDirectory/isReadable/isWritable return
|
|
|
|
* for existing nodes. However, this is not the case for many existing
|
|
|
|
* FSNode implementations. Either fix those, or document that FSNodes
|
2020-10-08 00:04:21 +02:00
|
|
|
* can become 'stale'.
|
2008-09-02 16:35:16 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @param name Name of a child of this directory.
|
|
|
|
* @return The node referring to the child with the given name.
|
2006-04-30 22:52:10 +00:00
|
|
|
*/
|
2008-12-27 18:03:27 +00:00
|
|
|
FSNode getChild(const String &name) const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
/**
|
2008-09-02 16:35:16 +00:00
|
|
|
* Return a list of all child nodes of this directory node. If called on a node
|
2006-05-03 20:43:26 +00:00
|
|
|
* that does not represent a directory, false is returned.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return True if successful, false otherwise (e.g. when the directory does not exist).
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2019-01-30 06:24:06 +01:00
|
|
|
bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = true) const;
|
2006-07-22 14:14:16 +00:00
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Return a human-readable string for this node, usable for display (e.g.
|
2006-05-03 11:42:50 +00:00
|
|
|
* in the GUI code). Do *not* rely on it being usable for anything else,
|
2020-10-08 00:04:21 +02:00
|
|
|
* like constructing paths.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return The display name.
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2023-07-06 00:08:36 -04:00
|
|
|
U32String getDisplayName() const override;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-02-17 19:54:11 +00:00
|
|
|
* Return a string representation of the name of the file. This can be
|
2006-07-22 14:14:16 +00:00
|
|
|
* used e.g. by detection code that relies on matching the name of a given
|
2020-10-08 00:04:21 +02:00
|
|
|
* file. However, it is *not* suitable for use with fopen / File::open, nor
|
2006-07-22 14:14:16 +00:00
|
|
|
* should it be archived.
|
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return The file name.
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2023-07-06 00:08:36 -04:00
|
|
|
String getName() const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a string representation of the name of the file.
|
|
|
|
*
|
|
|
|
* @return The file name.
|
|
|
|
*/
|
|
|
|
String getFileName() const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a string representation of the name of the file. Since FSNode
|
|
|
|
* parents are always the parent FSDirectory, this will not return a full
|
|
|
|
* path, only the file name.
|
|
|
|
*
|
|
|
|
* @return The file name.
|
|
|
|
*/
|
|
|
|
Common::Path getPathInArchive() const override;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
DIRECTOR: More fixes for partial filename matching
For Macintosh, it is possible to have filenames with a "/" in them.
Dumper Companion will punyencode this and any other non-ASCII characters
when extracting from a Macintosh filesystem. As such, when checking
components of a filename, we should attempt to match against the punydecoded
name, but always return the "real" name (i.e. the name of the file in
the local filesystem, possibly punyencoded).
In addition, it is possible for a movie A/B/C.DIR to go to a movie
"E/F.DIR", where the actual path is A/E/F.DIR. To make the partial matching
work, first we try removing each component from the start of the target
path, then retry all combinations again after removing a component from
the end of the source directory, etc.
Fixes several movie switches in The Seven Colors.
2023-07-08 00:56:31 +08:00
|
|
|
/**
|
|
|
|
* Return a string representation of the name of the file, without any
|
|
|
|
* Punycode transformation. This can be used e.g. by detection code that
|
|
|
|
* relies on matching the name of a given file. However, it is *not*
|
|
|
|
* suitable for use with fopen / File::open, nor should it be archived.
|
|
|
|
*
|
|
|
|
* @return The file name.
|
|
|
|
*/
|
|
|
|
virtual String getRealName() const;
|
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Return a string representation of the file that is suitable for
|
2008-09-11 09:28:14 +00:00
|
|
|
* archiving (i.e. writing to the config file). This will usually be a
|
|
|
|
* 'path' (hence the name of the method), but can be anything that meets
|
2020-10-08 00:04:21 +02:00
|
|
|
* the above criteria. What a 'path' is differs greatly from system to
|
|
|
|
* system.
|
2006-07-22 14:14:16 +00:00
|
|
|
*
|
|
|
|
* @note Do not assume that this string contains (back)slashes or any
|
|
|
|
* other kind of 'path separators'.
|
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return The 'path' represented by this file system node.
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2010-02-13 11:57:01 +00:00
|
|
|
String getPath() const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
/**
|
|
|
|
* Get the parent node of this node. If this node has no parent node,
|
|
|
|
* then it returns a duplicate of this node.
|
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
FSNode getParent() const;
|
2003-10-17 12:04:44 +00:00
|
|
|
|
2006-05-03 10:14:05 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Indicate whether the node refers to a directory or not.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2007-08-18 05:24:18 +00:00
|
|
|
* @todo Currently we assume that a node that is not a directory
|
|
|
|
* automatically is a file (ignoring things like symlinks or pipes).
|
|
|
|
* That might actually be OK... but we could still add an isFile method.
|
|
|
|
* Or even replace isDirectory by a getType() method that can return values like
|
2007-05-03 02:39:33 +00:00
|
|
|
* kDirNodeType, kFileNodeType, kInvalidNodeType.
|
|
|
|
*/
|
2010-02-13 11:57:01 +00:00
|
|
|
bool isDirectory() const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-06-04 22:16:17 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Indicate whether the object referred by this node can be read from or not.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* If the node refers to a directory, readability implies being able to read
|
2007-08-18 05:24:18 +00:00
|
|
|
* and list the directory entries.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* If the node refers to a file, readability implies being able to read the
|
2007-08-18 05:24:18 +00:00
|
|
|
* contents of the file.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return True if the object can be read, false otherwise.
|
2007-06-04 22:16:17 +00:00
|
|
|
*/
|
2010-02-13 11:57:01 +00:00
|
|
|
bool isReadable() const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-06-04 22:16:17 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Indicate whether the object referred by this node can be written to or not.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* If the node refers to a directory, writability implies being able to modify
|
2020-10-08 00:04:21 +02:00
|
|
|
* the directory entry (i.e. rename the directory, remove it, or write files inside of it).
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* If the node refers to a file, writability implies being able to write data
|
2007-08-18 05:24:18 +00:00
|
|
|
* to the file.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return True if the object can be written to, false otherwise.
|
2006-05-03 10:14:05 +00:00
|
|
|
*/
|
2010-02-13 11:57:01 +00:00
|
|
|
bool isWritable() const;
|
2008-01-26 19:25:04 +00:00
|
|
|
|
2008-08-03 18:35:51 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Create a SeekableReadStream instance corresponding to the file
|
2008-08-03 18:35:51 +00:00
|
|
|
* referred by this node. This assumes that the node actually refers
|
|
|
|
* to a readable file. If this is not the case, 0 is returned.
|
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return Pointer to the stream object, 0 in case of a failure.
|
2008-08-03 18:35:51 +00:00
|
|
|
*/
|
2023-07-06 02:48:31 -04:00
|
|
|
SeekableReadStream *createReadStream() const override;
|
2008-08-03 18:35:51 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Create a WriteStream instance corresponding to the file
|
2008-08-03 18:35:51 +00:00
|
|
|
* referred by this node. This assumes that the node actually refers
|
|
|
|
* to a readable file. If this is not the case, 0 is returned.
|
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return Pointer to the stream object, 0 in case of a failure.
|
2008-08-03 18:35:51 +00:00
|
|
|
*/
|
2021-07-29 18:41:15 -07:00
|
|
|
SeekableWriteStream *createWriteStream() const;
|
2019-06-29 18:56:57 +03:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Create a directory referred by this node. This assumes that this
|
|
|
|
* node refers to a non-existing directory. If this is not the case,
|
2019-06-29 18:56:57 +03:00
|
|
|
* false is returned.
|
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* @return True if the directory was created, false otherwise.
|
2019-06-29 18:56:57 +03:00
|
|
|
*/
|
|
|
|
bool createDirectory() const;
|
2002-11-13 17:16:18 +00:00
|
|
|
};
|
|
|
|
|
2008-12-27 18:03:27 +00:00
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* FSDirectory models a directory tree from the file system and allows users
|
2008-12-27 18:03:27 +00:00
|
|
|
* to access it through the Archive interface. Searching is case-insensitive,
|
2020-10-08 00:04:21 +02:00
|
|
|
* since the intended goal is to support retrieval of game data.
|
2008-12-27 18:03:27 +00:00
|
|
|
*
|
|
|
|
* FSDirectory can represent a single directory, or a tree with specified depth,
|
|
|
|
* depending on the value passed to the 'depth' parameter in the constructors.
|
2020-10-08 00:04:21 +02:00
|
|
|
* In the default mode, file names are cached with their relative path,
|
2009-06-01 00:01:32 +00:00
|
|
|
* with elements separated by slashes, e.g.:
|
2020-10-08 00:04:21 +02:00
|
|
|
* @code
|
2008-12-27 18:03:27 +00:00
|
|
|
* c:\my\data\file.ext
|
2020-10-08 00:04:21 +02:00
|
|
|
* @endcode
|
2008-12-27 18:03:27 +00:00
|
|
|
* would be cached as 'data/file.ext' if FSDirectory was created on 'c:/my' with
|
|
|
|
* depth > 1. If depth was 1, then the 'data' subdirectory would have been
|
|
|
|
* ignored, instead.
|
2009-01-20 12:37:05 +00:00
|
|
|
* Again, only SLASHES are used as separators independently from the
|
2008-12-27 18:03:27 +00:00
|
|
|
* underlying file system.
|
|
|
|
*
|
2009-01-23 04:45:44 +00:00
|
|
|
* Relative paths can be specified when calling matching functions like createReadStreamForMember(),
|
2020-10-08 00:04:21 +02:00
|
|
|
* hasFile(), listMatchingMembers(), and listMembers(). See the function-specific
|
|
|
|
* documentation for more information.
|
2008-12-27 18:03:27 +00:00
|
|
|
*
|
2009-06-01 00:01:32 +00:00
|
|
|
* If the 'flat' argument to the constructor is true, files in subdirectories
|
2020-10-08 00:04:21 +02:00
|
|
|
* are cached without the relative path, so in the following example:
|
|
|
|
* @code
|
|
|
|
* c:\my\data\file.ext
|
|
|
|
* @endcode
|
|
|
|
* would be cached as 'file.ext'.
|
2009-06-01 00:01:32 +00:00
|
|
|
*
|
2019-10-20 17:37:18 +02:00
|
|
|
* When the 'ignoreClashes' argument to the constructor is true, name clashes are
|
2020-10-08 00:04:21 +02:00
|
|
|
* expected by the engine. It means that files that clash should be identical and
|
|
|
|
* getSubDirectory should not be used on clashing directories. This flag is useful
|
|
|
|
* in flat mode when there are directories with the same name at different places in the
|
|
|
|
* tree whose name is not relevant for the engine code.
|
2019-10-20 17:37:18 +02:00
|
|
|
*
|
2020-10-08 00:04:21 +02:00
|
|
|
* Client code can customize the cache by using constructors with the 'prefix'
|
2008-12-27 18:03:27 +00:00
|
|
|
* parameter. In this case, the prefix is prepended to each entry in the cache,
|
|
|
|
* and effectively treated as a 'virtual' parent subdirectory. FSDirectory adds
|
2020-10-08 00:04:21 +02:00
|
|
|
* a trailing slash to the prefix if needed. Following on with the previous example
|
|
|
|
* and using 'your' as a prefix, the cache entry would have been 'your/data/file.ext'.
|
2009-06-01 00:01:32 +00:00
|
|
|
* This is done both in non-flat and flat mode.
|
2008-12-27 18:03:27 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
class FSDirectory : public Archive {
|
2019-10-20 17:37:18 +02:00
|
|
|
FSNode _node;
|
|
|
|
int _depth;
|
|
|
|
bool _flat;
|
|
|
|
bool _ignoreClashes;
|
2020-10-07 01:35:38 +02:00
|
|
|
bool _includeDirectories;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
2022-12-09 05:12:27 +01:00
|
|
|
Path _prefix; // string that is prepended to each cache item key
|
|
|
|
void setPrefix(const Path &prefix);
|
2009-01-23 04:36:18 +00:00
|
|
|
|
2008-12-27 18:03:27 +00:00
|
|
|
// Caches are case insensitive, clashes are dealt with when creating
|
|
|
|
// Key is stored in lowercase.
|
2022-12-09 05:12:27 +01:00
|
|
|
typedef HashMap<Path, FSNode, Path::IgnoreCaseAndMac_Hash, Path::IgnoreCaseAndMac_EqualsTo> NodeCache;
|
2009-01-23 04:36:18 +00:00
|
|
|
mutable NodeCache _fileCache, _subDirCache;
|
|
|
|
mutable bool _cached;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
// look for a match
|
2022-12-09 05:12:27 +01:00
|
|
|
FSNode *lookupCache(NodeCache &cache, const Path &name) const;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
// cache management
|
2021-08-01 19:33:22 -04:00
|
|
|
void cacheDirectoryRecursive(FSNode node, int depth, const Path& prefix) const;
|
2009-01-23 04:36:18 +00:00
|
|
|
|
2008-12-27 18:03:27 +00:00
|
|
|
// fill cache if not already cached
|
2009-01-23 04:36:18 +00:00
|
|
|
void ensureCached() const;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a FSDirectory representing a tree with the specified depth. Will result in an
|
2020-10-08 00:04:21 +02:00
|
|
|
* unbound FSDirectory if name is not found in the file system or if the node is not a
|
2008-12-27 18:03:27 +00:00
|
|
|
* valid directory.
|
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
FSDirectory(const Path &name, int depth = 1, bool flat = false,
|
2020-10-07 01:35:38 +02:00
|
|
|
bool ignoreClashes = false, bool includeDirectories = false);
|
2020-10-08 00:04:21 +02:00
|
|
|
/**
|
|
|
|
* @overload
|
|
|
|
*/
|
2019-10-20 17:37:18 +02:00
|
|
|
FSDirectory(const FSNode &node, int depth = 1, bool flat = false,
|
2020-10-07 01:35:38 +02:00
|
|
|
bool ignoreClashes = false, bool includeDirectories = false);
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a FSDirectory representing a tree with the specified depth. The parameter
|
2020-10-08 00:04:21 +02:00
|
|
|
* prefix is prepended to the keys in the cache. See @ref FSDirectory.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
FSDirectory(const Path &prefix, const Path &name, int depth = 1,
|
2020-10-07 01:35:38 +02:00
|
|
|
bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
|
2020-10-08 00:04:21 +02:00
|
|
|
/**
|
|
|
|
* @overload
|
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
FSDirectory(const Path &prefix, const FSNode &node, int depth = 1,
|
2020-10-07 01:35:38 +02:00
|
|
|
bool flat = false, bool ignoreClashes = false, bool includeDirectories = false);
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
virtual ~FSDirectory();
|
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Return the underlying FSNode of the FSDirectory.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
|
|
|
FSNode getFSNode() const;
|
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Create a new FSDirectory pointing to a subdirectory of the instance.
|
|
|
|
* @return A new FSDirectory instance.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
FSDirectory *getSubDirectory(const Path &name, int depth = 1, bool flat = false,
|
2019-10-20 17:37:18 +02:00
|
|
|
bool ignoreClashes = false);
|
2020-10-08 00:04:21 +02:00
|
|
|
/**
|
|
|
|
* Create a new FSDirectory pointing to a subdirectory of the instance. See FSDirectory
|
|
|
|
* for an explanation of the prefix parameter.
|
|
|
|
* @return A new FSDirectory instance.
|
|
|
|
*/
|
2021-08-01 19:33:22 -04:00
|
|
|
FSDirectory *getSubDirectory(const Path &prefix, const Path &name, int depth = 1,
|
2019-10-20 17:37:18 +02:00
|
|
|
bool flat = false, bool ignoreClashes = false);
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Check for the existence of a file in the cache. A full match of relative path and file name
|
|
|
|
* is needed for success.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2021-11-13 22:30:12 +02:00
|
|
|
bool hasFile(const Path &path) const override;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Return a list of matching file names. Pattern can use GLOB wildcards.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2023-01-07 15:13:13 +01:00
|
|
|
int listMatchingMembers(ArchiveMemberList &list, const Path &pattern, bool matchPathComponents = false) const override;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Return a list of all the files in the cache.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2021-11-13 22:30:12 +02:00
|
|
|
int listMembers(ArchiveMemberList &list) const override;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Get an ArchiveMember representation of the specified file. A full match of relative
|
|
|
|
* path and file name is needed for success.
|
2008-12-27 18:03:27 +00:00
|
|
|
*/
|
2021-11-13 22:30:12 +02:00
|
|
|
const ArchiveMemberPtr getMember(const Path &path) const override;
|
2008-12-27 18:03:27 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-08 00:04:21 +02:00
|
|
|
* Open the specified file. A full match of relative path and file name is needed
|
2008-12-27 18:03:27 +00:00
|
|
|
* for success.
|
|
|
|
*/
|
2021-11-13 22:30:12 +02:00
|
|
|
SeekableReadStream *createReadStreamForMember(const Path &path) const override;
|
2008-12-27 18:03:27 +00:00
|
|
|
};
|
|
|
|
|
2020-07-08 23:30:36 +02:00
|
|
|
/** @} */
|
2008-12-27 18:03:27 +00:00
|
|
|
|
2008-09-03 11:22:51 +00:00
|
|
|
} // End of namespace Common
|
2004-11-20 21:35:49 +00:00
|
|
|
|
2007-05-03 02:39:33 +00:00
|
|
|
#endif //COMMON_FS_H
|