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
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
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-03-29 21:12:36 +00:00
|
|
|
#include "common/ptr.h"
|
2006-05-03 11:42:50 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
|
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
|
|
|
|
2008-10-02 16:58:59 +00:00
|
|
|
class FSNode;
|
2008-09-03 11:22:51 +00:00
|
|
|
class SeekableReadStream;
|
|
|
|
class WriteStream;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of multiple file system nodes. E.g. the contents of a given directory.
|
|
|
|
* This is subclass instead of just a typedef so that we can use forward
|
|
|
|
* declarations of it in other places.
|
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
class FSList : public Common::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
|
|
|
|
* paths, allowing for portable file system browsing. This means for example,
|
|
|
|
* 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
|
|
|
|
* paths (and it's left to them whether / or \ or : is the path separator :-);
|
|
|
|
* but it is also possible to use inodes or vrefs (MacOS 9) or anything else.
|
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
class FSNode {
|
2004-11-20 21:35:49 +00:00
|
|
|
private:
|
2008-10-02 16:58:59 +00:00
|
|
|
Common::SharedPtr<AbstractFSNode> _realNode;
|
|
|
|
FSNode(AbstractFSNode *realNode);
|
2006-04-03 21:54:26 +00:00
|
|
|
|
2002-11-13 17:16:18 +00:00
|
|
|
public:
|
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
|
|
|
/**
|
2008-10-02 16:58:59 +00:00
|
|
|
* Create a new pathless FSNode. Since there's 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
|
|
|
*
|
|
|
|
* If path is empty or equals ".", then a node representing the "current
|
|
|
|
* directory" will be created. If that is not possible (since e.g. the
|
|
|
|
* operating system doesn't support the concept), some other directory is
|
|
|
|
* used (usually the root directory).
|
2006-04-30 22:52:10 +00:00
|
|
|
*/
|
2008-10-02 16:58:59 +00:00
|
|
|
explicit FSNode(const Common::String &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
|
|
|
/**
|
2008-08-03 18:35:51 +00:00
|
|
|
* Indicates whether the object referred by this node exists in the filesystem or not.
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* @return bool true if the node exists, false otherwise.
|
2006-04-30 22:52:10 +00:00
|
|
|
*/
|
2007-06-05 21:02:35 +00:00
|
|
|
virtual 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
|
|
|
|
* to create a new file using the openForWriting() method.
|
|
|
|
*
|
|
|
|
* @todo If openForWriting() (or a hypothetical future mkdir() method) is used,
|
|
|
|
* 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
|
|
|
|
* can become 'stale'...
|
|
|
|
*
|
|
|
|
* @param name the 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-10-02 16:58:59 +00:00
|
|
|
FSNode getChild(const Common::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
|
|
|
*
|
2008-09-02 16:35:16 +00:00
|
|
|
* @return true if successful, false otherwise (e.g. when the directory does not exist).
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2008-01-27 19:47:41 +00:00
|
|
|
virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const;
|
2006-07-22 14:14:16 +00:00
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
/**
|
|
|
|
* Return a human readable string for this node, usable for display (e.g.
|
|
|
|
* in the GUI code). Do *not* rely on it being usable for anything else,
|
|
|
|
* like constructing paths!
|
2008-01-27 19:47:41 +00:00
|
|
|
*
|
2006-05-03 11:42:50 +00:00
|
|
|
* @return the display name
|
|
|
|
*/
|
2007-06-05 21:02:35 +00:00
|
|
|
virtual Common::String getDisplayName() const;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-22 14:14:16 +00:00
|
|
|
* Return a string representation of the name of the file. This is can be
|
|
|
|
* used e.g. by detection code that relies on matching the name of a given
|
|
|
|
* file. But it is *not* suitable for use with fopen / File::open, nor
|
|
|
|
* should it be archived.
|
|
|
|
*
|
|
|
|
* @return the file name
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2007-06-05 21:02:35 +00:00
|
|
|
virtual Common::String getName() const;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
2008-09-11 09:28:14 +00:00
|
|
|
* Return a string representation of the file which is suitable for
|
|
|
|
* 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
|
|
|
|
* the above criterions. What a 'path' is differs greatly from system to
|
|
|
|
* system anyway.
|
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'.
|
|
|
|
*
|
|
|
|
* @return the 'path' represented by this filesystem node
|
2006-05-03 11:42:50 +00:00
|
|
|
*/
|
2007-06-05 21:02:35 +00:00
|
|
|
virtual Common::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
|
|
|
/**
|
2008-08-03 18:35:51 +00:00
|
|
|
* Indicates 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.
|
|
|
|
*/
|
|
|
|
virtual bool isDirectory() const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-06-04 22:16:17 +00:00
|
|
|
/**
|
2008-08-03 18:35:51 +00:00
|
|
|
* Indicates 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
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* @return true if the object can be read, false otherwise.
|
2007-06-04 22:16:17 +00:00
|
|
|
*/
|
|
|
|
virtual bool isReadable() const;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2007-06-04 22:16:17 +00:00
|
|
|
/**
|
2008-08-03 18:35:51 +00:00
|
|
|
* Indicates 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
|
2007-08-18 05:24:18 +00: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
|
|
|
*
|
2008-08-03 18:35:51 +00:00
|
|
|
* @return true if the object can be written to, false otherwise.
|
2006-05-03 10:14:05 +00:00
|
|
|
*/
|
2007-06-04 22:16:17 +00:00
|
|
|
virtual bool isWritable() const;
|
2008-01-26 19:25:04 +00:00
|
|
|
|
2008-08-03 18:35:51 +00:00
|
|
|
/**
|
|
|
|
* Creates a SeekableReadStream instance corresponding to the file
|
|
|
|
* referred by this node. This assumes that the node actually refers
|
|
|
|
* to a readable file. If this is not the case, 0 is returned.
|
|
|
|
*
|
|
|
|
* @return pointer to the stream object, 0 in case of a failure
|
|
|
|
*/
|
2008-09-06 20:49:48 +00:00
|
|
|
virtual Common::SeekableReadStream *openForReading() const;
|
2008-08-03 18:35:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a WriteStream instance corresponding to the file
|
|
|
|
* referred by this node. This assumes that the node actually refers
|
|
|
|
* to a readable file. If this is not the case, 0 is returned.
|
|
|
|
*
|
|
|
|
* @return pointer to the stream object, 0 in case of a failure
|
|
|
|
*/
|
2008-09-06 20:49:48 +00:00
|
|
|
virtual Common::WriteStream *openForWriting() const;
|
2002-11-13 17:16:18 +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
|