2002-11-13 17:16:18 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
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"
|
|
|
|
#include "common/str.h"
|
|
|
|
|
2006-06-24 08:07:48 +00:00
|
|
|
//namespace Common {
|
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
class FilesystemNode;
|
|
|
|
class AbstractFilesystemNode;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class FSList : public Common::Array<FilesystemNode> {};
|
|
|
|
|
|
|
|
|
2002-11-13 17:16:18 +00:00
|
|
|
/*
|
2006-05-03 11:42:50 +00:00
|
|
|
* FilesystemNode provides an abstraction for file pathes, allowing for portable
|
|
|
|
* file system browsing. To this ends, multiple or single roots have to be supported
|
2002-11-13 17:16:18 +00:00
|
|
|
* (compare Unix with a single root, Windows with multiple roots C:, D:, ...).
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2004-12-10 00:11:52 +00:00
|
|
|
* NOTE: Backends still have to provide a way to extract a path from a FSIntern
|
2002-11-13 17:16:18 +00:00
|
|
|
*
|
|
|
|
* You may ask now: "isn't this cheating? Why do we go through all this when we use
|
|
|
|
* a path in the end anyway?!?".
|
|
|
|
* Well, for once as long as we don't provide our own file open/read/write API, we
|
|
|
|
* still have to use fopen(). Since all our targets already support fopen(), it should
|
|
|
|
* be possible to get a fopen() compatible string for any file system node.
|
|
|
|
*
|
|
|
|
* Secondly, with this abstraction layer, we still avoid a lot of complications based on
|
|
|
|
* differences in FS roots, different path separators, or even systems with no real
|
2004-05-06 09:20:21 +00:00
|
|
|
* paths (MacOS 9 doesn't even have the notion of a "current directory").
|
2002-11-13 17:16:18 +00:00
|
|
|
* And if we ever want to support devices with no FS in the classical sense (Palm...),
|
|
|
|
* we can build upon this.
|
|
|
|
*/
|
2006-05-03 10:14:05 +00:00
|
|
|
class FilesystemNode {
|
2004-11-20 21:35:49 +00:00
|
|
|
typedef Common::String String;
|
|
|
|
private:
|
|
|
|
AbstractFilesystemNode *_realNode;
|
|
|
|
int *_refCount;
|
|
|
|
|
2006-04-03 21:54:26 +00:00
|
|
|
FilesystemNode(AbstractFilesystemNode *realNode);
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Create a new invalid FilesystemNode. In other words, isValid() for that
|
|
|
|
* node returns false, and if you try to get it's path, an assert is
|
|
|
|
* triggered.
|
|
|
|
*/
|
|
|
|
FilesystemNode();
|
2006-05-03 10:14:05 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
2006-05-03 11:42:50 +00:00
|
|
|
* Create a new FilesystemNode 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
|
|
|
*/
|
|
|
|
FilesystemNode(const String &path);
|
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
2004-11-20 21:35:49 +00:00
|
|
|
FilesystemNode(const FilesystemNode &node);
|
2006-05-12 21:41:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2006-05-03 10:14:05 +00:00
|
|
|
virtual ~FilesystemNode();
|
2002-11-13 17:16:18 +00:00
|
|
|
|
2006-05-12 21:41:54 +00:00
|
|
|
/**
|
|
|
|
* Copy operator.
|
|
|
|
*/
|
2004-11-20 21:35:49 +00:00
|
|
|
FilesystemNode &operator =(const FilesystemNode &node);
|
2004-05-06 10:34:41 +00:00
|
|
|
|
2006-07-22 17:01:50 +00:00
|
|
|
/**
|
|
|
|
* Checks if the FilesystemNode is valid for any usage
|
|
|
|
*/
|
|
|
|
bool isValid() const;
|
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
|
|
|
* Get the parent node of this node. If this node has no parent node,
|
|
|
|
* then it returns a duplicate of this node.
|
|
|
|
*/
|
2004-11-20 21:35:49 +00:00
|
|
|
FilesystemNode getParent() const;
|
2004-05-06 10:34:41 +00:00
|
|
|
|
2006-04-30 22:52:10 +00:00
|
|
|
/**
|
|
|
|
* Fetch a child node of this node, with the given name. Only valid for
|
|
|
|
* directory nodes (an assertion is triggered otherwise). If no no child
|
|
|
|
* node with the given name exists, an invalid node is returned.
|
|
|
|
*/
|
|
|
|
FilesystemNode getChild(const String &name) const;
|
2004-05-06 10:34:41 +00:00
|
|
|
|
2006-05-03 11:42:50 +00:00
|
|
|
/**
|
2006-05-03 20:43:26 +00:00
|
|
|
* Return a list of child nodes of this directory node. If called on a node
|
|
|
|
* that does not represent a directory, false is returned.
|
|
|
|
* @return true if succesful, false otherwise (e.g. when the directory does not exist).
|
2006-05-03 11:42:50 +00:00
|
|
|
* @todo Rename this to listChildren or getChildren.
|
|
|
|
*/
|
2006-05-03 20:43:26 +00:00
|
|
|
virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
2006-07-22 14:14:16 +00:00
|
|
|
/**
|
|
|
|
* Is this node pointing to a directory?
|
|
|
|
* @todo Currently we assume that a valid node that is not a directory
|
|
|
|
* automatically is a file (ignoring things like symlinks). That might
|
|
|
|
* actually be OK... but we could still add an isFile method. Or even replace
|
|
|
|
* isValid and isDirectory by a getType() method that can return values like
|
|
|
|
* kDirNodeType, kFileNodeType, kInvalidNodeType.
|
|
|
|
*/
|
|
|
|
virtual bool isDirectory() const;
|
|
|
|
|
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!
|
|
|
|
* @return the display name
|
|
|
|
*/
|
2006-04-03 21:54:26 +00:00
|
|
|
virtual String displayName() 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
|
|
|
*/
|
2006-07-22 14:14:16 +00:00
|
|
|
virtual String name() const;
|
2006-05-03 11:42:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a string representation of the file which can be passed to fopen(),
|
|
|
|
* and 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
|
2006-07-22 14:14:16 +00:00
|
|
|
* be anything that fulfills the above criterions.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
2006-04-03 21:54:26 +00:00
|
|
|
virtual String path() const;
|
2003-10-17 12:04:44 +00:00
|
|
|
|
2006-05-03 10:14:05 +00:00
|
|
|
/**
|
|
|
|
* Compare the name of this node to the name of another. Directories
|
|
|
|
* go before normal files.
|
|
|
|
*/
|
|
|
|
bool operator< (const FilesystemNode& node) const;
|
|
|
|
|
2004-11-20 21:35:49 +00:00
|
|
|
protected:
|
|
|
|
void decRefCount();
|
2002-11-13 17:16:18 +00:00
|
|
|
};
|
|
|
|
|
2006-06-24 08:07:48 +00:00
|
|
|
//} // End of namespace Common
|
2004-11-20 21:35:49 +00:00
|
|
|
|
2002-11-13 17:16:18 +00:00
|
|
|
#endif
|