From c459f054b46b8791ce206c2ee13d455a9c10fe4d Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 3 May 2007 02:39:33 +0000 Subject: Use abstract factories to initialize FilesystemNode objects. svn-id: r26739 --- common/fs.cpp | 23 +++++++-------- common/fs.h | 90 +++++++++++++++++++++++++++++++---------------------------- 2 files changed, 59 insertions(+), 54 deletions(-) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index 10087cd91c..cdc3e5f799 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -23,7 +23,7 @@ #include "backends/fs/abstract-fs.h" #include "common/util.h" - +#include "backends/fs/FilesystemFactoryMaker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { _realNode = realNode; @@ -43,10 +43,12 @@ FilesystemNode::FilesystemNode(const FilesystemNode &node) { } FilesystemNode::FilesystemNode(const Common::String &p) { + AbstractFilesystemFactory *factory = FilesystemFactoryMaker::makeFactory(); + if (p.empty() || p == ".") - _realNode = AbstractFilesystemNode::getCurrentDirectory(); + _realNode = factory->makeCurrentDirectoryFileNode(); else - _realNode = AbstractFilesystemNode::getNodeForPath(p); + _realNode = factory->makeFileNodePath(p); _refCount = new int(1); } @@ -65,7 +67,7 @@ void FilesystemNode::decRefCount() { } } -FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) { +FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { if (node._refCount) ++(*node._refCount); @@ -87,7 +89,7 @@ FilesystemNode FilesystemNode::getParent() const { if (_realNode == 0) return *this; - AbstractFilesystemNode *node = _realNode->parent(); + AbstractFilesystemNode *node = _realNode->getParent(); if (node == 0) { return *this; } else { @@ -100,7 +102,7 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return *this; assert(_realNode->isDirectory()); - AbstractFilesystemNode *node = _realNode->child(n); + AbstractFilesystemNode *node = _realNode->getChild(n); return FilesystemNode(node); } @@ -110,7 +112,7 @@ bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { AbstractFSList tmp; - if (!_realNode->listDir(tmp, mode)) + if (!_realNode->getChildren(tmp, mode)) return false; fslist.clear(); @@ -129,20 +131,19 @@ bool FilesystemNode::isDirectory() const { Common::String FilesystemNode::displayName() const { assert(_realNode); - return _realNode->displayName(); + return _realNode->getDisplayName(); } Common::String FilesystemNode::name() const { assert(_realNode); - return _realNode->name(); + return _realNode->getName(); } Common::String FilesystemNode::path() const { assert(_realNode); - return _realNode->path(); + return _realNode->getPath(); } - bool FilesystemNode::operator< (const FilesystemNode& node) const { if (isDirectory() && !node.isDirectory()) diff --git a/common/fs.h b/common/fs.h index 2d906431ca..6a89bfcdaf 100644 --- a/common/fs.h +++ b/common/fs.h @@ -30,7 +30,6 @@ 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 @@ -38,9 +37,8 @@ class AbstractFilesystemNode; */ class FSList : public Common::Array {}; - /** - * FilesystemNode provides an abstraction for file pathes, allowing for portable + * FilesystemNode provides an abstraction for file paths, allowing for portable * file system browsing. To this ends, multiple or single roots have to be supported * (compare Unix with a single root, Windows with multiple roots C:, D:, ...). * @@ -64,8 +62,8 @@ class FSList : public Common::Array {}; */ class FilesystemNode { private: - AbstractFilesystemNode *_realNode; int *_refCount; + AbstractFilesystemNode *_realNode; FilesystemNode(AbstractFilesystemNode *realNode); @@ -110,43 +108,13 @@ public: /** * Copy operator. */ - FilesystemNode &operator =(const FilesystemNode &node); - - /** - * Checks if the FilesystemNode is valid for any usage - */ - bool isValid() const; - - /** - * Get the parent node of this node. If this node has no parent node, - * then it returns a duplicate of this node. - */ - FilesystemNode getParent() const; - - /** - * 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 Common::String &name) const; - - /** - * 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). - * @todo Rename this to listChildren or getChildren. - */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; - + FilesystemNode &operator= (const FilesystemNode &node); + /** - * 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. + * Compare the name of this node to the name of another. Directories + * go before normal files. */ - virtual bool isDirectory() const; + bool operator< (const FilesystemNode& node) const; /** * Return a human readable string for this node, usable for display (e.g. @@ -180,15 +148,51 @@ public: virtual Common::String path() const; /** - * Compare the name of this node to the name of another. Directories - * go before normal files. + * Fetch a child node of this node, with the given name. Only valid for + * directory nodes (an assertion is triggered otherwise). + * If no child node with the given name exists, an invalid node is returned. */ - bool operator< (const FilesystemNode& node) const; + FilesystemNode getChild(const Common::String &name) const; + + /** + * 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). + * @todo Rename this to listChildren or getChildren. + */ + virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + + /** + * Get the parent node of this node. If this node has no parent node, + * then it returns a duplicate of this node. + */ + FilesystemNode getParent() const; + + /** + * Indicates whether this path refers to a directory or not. + * + * @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; + + /** + * Indicates whether this path is valid or not for usage. + */ + bool isValid() const; protected: + /** + * Decreases the reference count to the FilesystemNode, and if necessary, + * deletes the corresponding underlying references. + */ void decRefCount(); }; //} // End of namespace Common -#endif +#endif //COMMON_FS_H -- cgit v1.2.3 From 86324f00bc561c03b281170125ef2fde14cae132 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 18:17:40 +0000 Subject: Renamed files and minor tweaks. Thanks LordHoto :) svn-id: r26810 --- common/fs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index cdc3e5f799..07fafa9aa8 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -23,7 +23,7 @@ #include "backends/fs/abstract-fs.h" #include "common/util.h" -#include "backends/fs/FilesystemFactoryMaker.cpp" +#include "backends/fs/fs-factory-maker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { _realNode = realNode; -- cgit v1.2.3 From d1f56d93f934150f4b579c2e90564e2bf035f113 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 12 May 2007 20:00:52 +0000 Subject: Use common/singleton.h in the concrete fs factories. svn-id: r26814 --- common/fs.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index 07fafa9aa8..e9c673abb2 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -20,9 +20,8 @@ */ #include "common/stdafx.h" - -#include "backends/fs/abstract-fs.h" #include "common/util.h" +#include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { -- cgit v1.2.3 From 716bcd0b2bcd4d04489bc2fc23a948fad3e2c02a Mon Sep 17 00:00:00 2001 From: David Corrales Date: Mon, 4 Jun 2007 22:16:17 +0000 Subject: Expose new fs backend methods in the FilesystemNode class. svn-id: r27089 --- common/fs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common') diff --git a/common/fs.h b/common/fs.h index 5e441a212f..c78980a813 100644 --- a/common/fs.h +++ b/common/fs.h @@ -127,6 +127,11 @@ public: */ virtual Common::String displayName() const; + /* + * Indicates whether the object refered by this path exists in the filesystem or not. + */ + virtual bool exists() const; + /** * 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 @@ -183,10 +188,20 @@ public: */ virtual bool isDirectory() const; + /** + * Indicates whether this path can be read from or not. + */ + virtual bool isReadable() const; + /** * Indicates whether this path is valid or not for usage. */ bool isValid() const; + + /** + * Indicates whether this path can be written to or not. + */ + virtual bool isWritable() const; protected: /** -- cgit v1.2.3 From 3b96c7fad54ff7f5000667be494e50e7ca11e69a Mon Sep 17 00:00:00 2001 From: David Corrales Date: Tue, 5 Jun 2007 21:02:35 +0000 Subject: Renamed methods in the FilesystemNode class to match the AbstractFSNode implementations. Also exposed the new methods (exists, isReadable and isWritable) in FilesystemNode. svn-id: r27113 --- common/advancedDetector.cpp | 6 +-- common/file.cpp | 14 +++--- common/fs.cpp | 106 ++++++++++++++++++++++++++------------------ common/fs.h | 48 ++++++++++---------- common/md5.cpp | 2 +- 5 files changed, 97 insertions(+), 79 deletions(-) (limited to 'common') diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 24e884a164..d6b622451a 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -227,7 +227,7 @@ PluginError detectGameForEngineCreation( FSList fslist; FilesystemNode dir(ConfMan.get("path")); - if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { + if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { return kInvalidPathError; } @@ -285,7 +285,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p // Get the information of the existing files for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { if (file->isDirectory()) continue; - tstr = file->name(); + tstr = file->getName(); tstr.toLowercase(); // Strip any trailing dot @@ -304,7 +304,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p debug(3, "> %s: %s", tstr.c_str(), md5str); - if (testFile.open(file->path())) { + if (testFile.open(file->getPath())) { filesSize[tstr] = (int32)testFile.size(); testFile.close(); } diff --git a/common/file.cpp b/common/file.cpp index 2eba1bcb3d..c04c579535 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -226,7 +226,7 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co return; FSList fslist; - if (!dir.listDir(fslist, FilesystemNode::kListAll)) { + if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { // Failed listing the contents of this node, so it is either not a // directory, or just doesn't exist at all. return; @@ -237,7 +237,7 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co // Do not add directories multiple times, unless this time they are added // with a bigger depth. - const String &directory(dir.path()); + const String &directory(dir.getPath()); if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level) return; (*_defaultDirectories)[directory] = level; @@ -247,13 +247,13 @@ void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level, co for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (file->isDirectory()) { - addDefaultDirectoryRecursive(file->path(), level - 1, prefix + file->name() + "/"); + addDefaultDirectoryRecursive(file->getPath(), level - 1, prefix + file->getName() + "/"); } else { String lfn(prefix); - lfn += file->name(); + lfn += file->getName(); lfn.toLowercase(); if (!_filesMap->contains(lfn)) { - (*_filesMap)[lfn] = file->path(); + (*_filesMap)[lfn] = file->getPath(); } } } @@ -372,7 +372,7 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return false; } - String filename(node.name()); + String filename(node.getName()); if (_handle) { error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); @@ -383,7 +383,7 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; - _handle = fopen(node.path().c_str(), modeStr); + _handle = fopen(node.getPath().c_str(), modeStr); if (_handle == NULL) { if (mode == kFileReadMode) diff --git a/common/fs.cpp b/common/fs.cpp index ef106c2488..fdc485a06f 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -27,16 +27,16 @@ #include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" -FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { - _realNode = realNode; - _refCount = new int(1); -} - FilesystemNode::FilesystemNode() { _realNode = 0; _refCount = 0; } +FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { + _realNode = realNode; + _refCount = new int(1); +} + FilesystemNode::FilesystemNode(const FilesystemNode &node) { _realNode = node._realNode; _refCount = node._refCount; @@ -58,17 +58,6 @@ FilesystemNode::~FilesystemNode() { decRefCount(); } -void FilesystemNode::decRefCount() { - if (_refCount) { - assert(*_refCount > 0); - --(*_refCount); - if (*_refCount == 0) { - delete _refCount; - delete _realNode; - } - } -} - FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { if (node._refCount) ++(*node._refCount); @@ -81,24 +70,32 @@ FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { return *this; } -bool FilesystemNode::isValid() const { - if (_realNode == 0) +bool FilesystemNode::operator< (const FilesystemNode& node) const +{ + if (isDirectory() && !node.isDirectory()) + return true; + if (!isDirectory() && node.isDirectory()) return false; - return _realNode->isValid(); + return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; } -FilesystemNode FilesystemNode::getParent() const { - if (_realNode == 0) - return *this; - - AbstractFilesystemNode *node = _realNode->getParent(); - if (node == 0) { - return *this; - } else { - return FilesystemNode(node); +void FilesystemNode::decRefCount() { + if (_refCount) { + assert(*_refCount > 0); + --(*_refCount); + if (*_refCount == 0) { + delete _refCount; + delete _realNode; + } } } +bool FilesystemNode::exists() const { + if (_realNode == 0) + return false; + return _realNode->exists(); +} + FilesystemNode FilesystemNode::getChild(const Common::String &n) const { if (_realNode == 0) return *this; @@ -108,7 +105,7 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return FilesystemNode(node); } -bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { +bool FilesystemNode::getChildren(FSList &fslist, ListMode mode) const { if (!_realNode || !_realNode->isDirectory()) return false; @@ -125,32 +122,53 @@ bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { return true; } -bool FilesystemNode::isDirectory() const { - if (_realNode == 0) - return false; - return _realNode->isDirectory(); -} - -Common::String FilesystemNode::displayName() const { +Common::String FilesystemNode::getDisplayName() const { assert(_realNode); return _realNode->getDisplayName(); } -Common::String FilesystemNode::name() const { +Common::String FilesystemNode::getName() const { assert(_realNode); return _realNode->getName(); } -Common::String FilesystemNode::path() const { +FilesystemNode FilesystemNode::getParent() const { + if (_realNode == 0) + return *this; + + AbstractFilesystemNode *node = _realNode->getParent(); + if (node == 0) { + return *this; + } else { + return FilesystemNode(node); + } +} + +Common::String FilesystemNode::getPath() const { assert(_realNode); return _realNode->getPath(); } -bool FilesystemNode::operator< (const FilesystemNode& node) const -{ - if (isDirectory() && !node.isDirectory()) - return true; - if (!isDirectory() && node.isDirectory()) +bool FilesystemNode::isDirectory() const { + if (_realNode == 0) + return false; + return _realNode->isDirectory(); +} + +bool FilesystemNode::isReadable() const { + if (_realNode == 0) + return false; + return _realNode->isReadable(); +} + +bool FilesystemNode::isValid() const { + if (_realNode == 0) + return false; + return _realNode->isValid(); +} + +bool FilesystemNode::isWritable() const { + if (_realNode == 0) return false; - return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0; + return _realNode->isWritable(); } diff --git a/common/fs.h b/common/fs.h index c78980a813..6b0a587e1b 100644 --- a/common/fs.h +++ b/common/fs.h @@ -119,18 +119,34 @@ public: */ bool operator< (const FilesystemNode& node) const; + /* + * Indicates whether the object refered by this path exists in the filesystem or not. + */ + virtual bool exists() const; + + /** + * Fetch a child node of this node, with the given name. Only valid for + * directory nodes (an assertion is triggered otherwise). + * If no child node with the given name exists, an invalid node is returned. + */ + FilesystemNode getChild(const Common::String &name) const; + + /** + * 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). + * @todo Rename this to listChildren or getChildren. + */ + virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + /** * 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 */ - virtual Common::String displayName() const; - - /* - * Indicates whether the object refered by this path exists in the filesystem or not. - */ - virtual bool exists() const; + virtual Common::String getDisplayName() const; /** * Return a string representation of the name of the file. This is can be @@ -140,7 +156,7 @@ public: * * @return the file name */ - virtual Common::String name() const; + virtual Common::String getName() const; /** * Return a string representation of the file which can be passed to fopen(), @@ -153,23 +169,7 @@ public: * * @return the 'path' represented by this filesystem node */ - virtual Common::String path() const; - - /** - * Fetch a child node of this node, with the given name. Only valid for - * directory nodes (an assertion is triggered otherwise). - * If no child node with the given name exists, an invalid node is returned. - */ - FilesystemNode getChild(const Common::String &name) const; - - /** - * 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). - * @todo Rename this to listChildren or getChildren. - */ - virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + virtual Common::String getPath() const; /** * Get the parent node of this node. If this node has no parent node, diff --git a/common/md5.cpp b/common/md5.cpp index a48ecb4948..35fbe0b9ab 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -254,7 +254,7 @@ bool md5_file(const FilesystemNode &file, uint8 digest[16], uint32 length) { return false; } - return md5_file(file.path().c_str(), digest, length); + return md5_file(file.getPath().c_str(), digest, length); } bool md5_file(const char *name, uint8 digest[16], uint32 length) { -- cgit v1.2.3 From f7ea7e666da6e484577d0341fb0331dff75c69f7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:31:36 +0000 Subject: Removed the isValid operation from the FilesystemNode class in favor of the much richer combinations possible with the new operations (exists, isReadable and isWritable). The work on the Common::File class is far from complete. Only the necessary was updated. svn-id: r27473 --- common/file.cpp | 14 ++++++++++---- common/fs.cpp | 6 ------ common/fs.h | 5 ----- common/md5.cpp | 9 ++++++--- 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index c04c579535..0df575ac82 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -364,13 +364,19 @@ bool File::open(const String &filename, AccessMode mode) { bool File::open(const FilesystemNode &node, AccessMode mode) { assert(mode == kFileReadMode || mode == kFileWriteMode); - if (!node.isValid()) { - warning("File::open: Trying to open an invalid FilesystemNode object"); + if (!node.exists()) { + warning("File::open: Trying to open a FilesystemNode which does not exist"); return false; } else if (node.isDirectory()) { warning("File::open: Trying to open a FilesystemNode which is a directory"); return false; - } + } /*else if (!node.isReadable() && mode == kFileReadMode) { + warning("File::open: Trying to open an unreadable FilesystemNode object for reading"); + return false; + } else if (!node.isWritable() && mode == kFileWriteMode) { + warning("File::open: Trying to open an unwritable FilesystemNode object for writing"); + return false; + }*/ String filename(node.getName()); @@ -409,7 +415,7 @@ bool File::exists(const String &filename) { // FIXME: can't use isValid() here since at the time of writing // FilesystemNode is to be unable to find for example files // added in extrapath - if (file.isDirectory()) + if (file.isDirectory() && !file.exists()) return false; // Next, try to locate the file by *opening* it in read mode. This has diff --git a/common/fs.cpp b/common/fs.cpp index fdc485a06f..fc091262d7 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -161,12 +161,6 @@ bool FilesystemNode::isReadable() const { return _realNode->isReadable(); } -bool FilesystemNode::isValid() const { - if (_realNode == 0) - return false; - return _realNode->isValid(); -} - bool FilesystemNode::isWritable() const { if (_realNode == 0) return false; diff --git a/common/fs.h b/common/fs.h index 6b0a587e1b..328bebb15b 100644 --- a/common/fs.h +++ b/common/fs.h @@ -193,11 +193,6 @@ public: */ virtual bool isReadable() const; - /** - * Indicates whether this path is valid or not for usage. - */ - bool isValid() const; - /** * Indicates whether this path can be written to or not. */ diff --git a/common/md5.cpp b/common/md5.cpp index 35fbe0b9ab..32acdc5b8c 100644 --- a/common/md5.cpp +++ b/common/md5.cpp @@ -246,11 +246,14 @@ void md5_finish(md5_context *ctx, uint8 digest[16]) { } bool md5_file(const FilesystemNode &file, uint8 digest[16], uint32 length) { - if (!file.isValid()) { - warning("md5_file: using an invalid FilesystemNode"); + if(!file.exists()) { + warning("md5_file: using an inexistent FilesystemNode"); + return false; + } else if (!file.isReadable()) { + warning("md5_file: using an unreadable FilesystemNode"); return false; } else if (file.isDirectory()) { - warning("md5_file: using a diretory FilesystemNode"); + warning("md5_file: using a directory FilesystemNode"); return false; } -- cgit v1.2.3 From fe4ee4740d76b0aee2032814095f1d2b81dbde14 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 16 Jun 2007 17:41:31 +0000 Subject: Small bugfix. Wrong logical operator. svn-id: r27474 --- common/file.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index 0df575ac82..238c3a4bb3 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -415,7 +415,7 @@ bool File::exists(const String &filename) { // FIXME: can't use isValid() here since at the time of writing // FilesystemNode is to be unable to find for example files // added in extrapath - if (file.isDirectory() && !file.exists()) + if (file.isDirectory() || !file.exists()) return false; // Next, try to locate the file by *opening* it in read mode. This has -- cgit v1.2.3 From 8ebf479bc5db8cf4996cc0820269aaf04139b940 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 17 Jun 2007 17:17:38 +0000 Subject: Added a new parameter to the getChildren function, which allows including hidden files in the results. svn-id: r27514 --- common/fs.cpp | 4 ++-- common/fs.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index fc091262d7..6eaa35e67f 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -105,13 +105,13 @@ FilesystemNode FilesystemNode::getChild(const Common::String &n) const { return FilesystemNode(node); } -bool FilesystemNode::getChildren(FSList &fslist, ListMode mode) const { +bool FilesystemNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const { if (!_realNode || !_realNode->isDirectory()) return false; AbstractFSList tmp; - if (!_realNode->getChildren(tmp, mode)) + if (!_realNode->getChildren(tmp, mode, hidden)) return false; fslist.clear(); diff --git a/common/fs.h b/common/fs.h index 328bebb15b..7291fb75fc 100644 --- a/common/fs.h +++ b/common/fs.h @@ -67,7 +67,6 @@ class FilesystemNode { private: int *_refCount; AbstractFilesystemNode *_realNode; - FilesystemNode(AbstractFilesystemNode *realNode); public: @@ -136,14 +135,14 @@ public: * that does not represent a directory, false is returned. * * @return true if succesful, false otherwise (e.g. when the directory does not exist). - * @todo Rename this to listChildren or getChildren. */ - virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; + virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const; /** * 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 */ virtual Common::String getDisplayName() const; -- cgit v1.2.3 From 0ac96302fe9c04df79cb01a77d19535b45fe2db0 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 20 Jun 2007 00:28:04 +0000 Subject: Initial implementation of the lookupFile() function. It's meant to search recursively for given filename within a set of directories. svn-id: r27551 --- common/fs.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/fs.h | 37 +++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) (limited to 'common') diff --git a/common/fs.cpp b/common/fs.cpp index 6eaa35e67f..28f3e11f0b 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -27,6 +27,43 @@ #include "backends/fs/abstract-fs.h" #include "backends/fs/fs-factory-maker.cpp" +/* + * Simple DOS-style pattern matching function (understands * and ? like used in DOS). + * Taken from exult/files/listfiles.cc + */ +static bool matchString(const char *str, const char *pat) { + const char *p = 0; + const char *q = 0; + + for (;;) { + switch (*pat) { + case '*': + p = ++pat; + q = str; + break; + + default: + if (*pat != *str) { + if (p) { + pat = p; + str = ++q; + if(!*str) + return !*pat; + break; + } + else + return false; + } + // fallthrough + case '?': + if(!*str) + return !*pat; + pat++; + str++; + } + } +} + FilesystemNode::FilesystemNode() { _realNode = 0; _refCount = 0; @@ -166,3 +203,48 @@ bool FilesystemNode::isWritable() const { return false; return _realNode->isWritable(); } + +bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const +{ + for(FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) + { + if(entry->isDirectory()) { + lookupFileRec(results, *entry, filename, hidden, exhaustive); + } + } + + //TODO: we would return true even if no matches were found, if the initial results list isn't empty + return ((results.size() > 0) ? true : false); +} + +bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +{ + lookupFileRec(results, dir, filename, hidden, exhaustive); + + //TODO: we would return true even if no matches were found, if the initial results list isn't empty + return ((results.size() > 0) ? true : false); +} + +void FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +{ + FSList entries; + dir.getChildren(entries, FilesystemNode::kListAll, hidden); + + for(FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) + { + if(entry->isDirectory()) { + lookupFileRec(results, *entry, filename, hidden, exhaustive); + } else { + //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, + // so it might be a good idea to include it inside the backend class. This would enforce its + // implementation by all ports. + if(matchString(lastPathComponent(entry->getPath()), filename.c_str())) { + results.push_back(*entry); + + if(!exhaustive) { + break; + } + } + } + } +} diff --git a/common/fs.h b/common/fs.h index 7291fb75fc..6a2f049be1 100644 --- a/common/fs.h +++ b/common/fs.h @@ -196,6 +196,32 @@ public: * Indicates whether this path can be written to or not. */ virtual bool isWritable() const; + + /** + * Searches recursively for a filename inside the given directories. + * + * @param results List to put the matches in. + * @param fslist List of directories to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const; + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. Default: false + * @param exhaustive Whether to continue searching after one match has been found. Default: false + * + * @return true if matches could be found, false otherwise. + */ + virtual bool lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; protected: /** @@ -203,6 +229,17 @@ protected: * deletes the corresponding underlying references. */ void decRefCount(); + + /** + * Searches recursively for a filename inside the given directory. + * + * @param results List to put the matches in. + * @param FilesystemNode Directory to search within. + * @param filename Name of the file to look for. + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. + */ + void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; }; //} // End of namespace Common -- cgit v1.2.3 From 720c974fafaca16b6e86f28ffc14c8c3aa574e15 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Thu, 12 Jul 2007 17:58:15 +0000 Subject: Changed SaveFileManager::listSavegames() function to be engine agnostic. It now returns a list will the full paths of existing files that match a given regex. Additionally, modified the 5 engines which use the default manager (Agos, Queen, Saga, Scumm and Touche) to parse the filename list and mark the available saves bool array correctly. svn-id: r28046 --- common/savefile.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/savefile.h b/common/savefile.h index 612d6ae210..fec6fc697b 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -30,6 +30,7 @@ #include "common/noncopyable.h" #include "common/scummsys.h" #include "common/stream.h" +#include "common/str.h" namespace Common { @@ -94,12 +95,11 @@ public: virtual InSaveFile *openForLoading(const char *filename) = 0; /** - * Request a list of available savegames with a given prefix. - * TODO: Document this better! - * TODO: Or even replace it with a better API. For example, one that - * returns a list of strings for all present file names. + * Request a list of available savegames with a given regex. + * @param regex Regular expression to match. Wildcards like * or ? are available. + * returns a list of strings for all present file names. */ - virtual void listSavefiles(const char *prefix , bool *marks, int num) = 0; + virtual Common::StringList listSavefiles(const char *regex) = 0; /** * Get the path to the save game directory. -- cgit v1.2.3 From 21f352b2df2b45b9bcff6a0c21d57a1e480d4802 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 18 Jul 2007 20:51:26 +0000 Subject: Added error codes to the SaveFileManager via the SFMError enum. Also, solved TODO's in the default-saves implementation. svn-id: r28140 --- common/savefile.h | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/savefile.h b/common/savefile.h index fec6fc697b..7c97ea5058 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -77,9 +77,51 @@ public: */ class SaveFileManager : NonCopyable { +public: + enum SFMError { + SFM_NO_ERROR, //Default state, indicates no error has been recorded + SFM_DIR_ACCESS, //stat(), mkdir()::EACCES: Search or write permission denied + SFM_DIR_LINKMAX, //mkdir()::EMLINK: The link count of the parent directory would exceed {LINK_MAX} + SFM_DIR_LOOP, //stat(), mkdir()::ELOOP: Too many symbolic links encountered while traversing the path + SFM_DIR_NAMETOOLONG, //stat(), mkdir()::ENAMETOOLONG: The path name is too long + SFM_DIR_NOENT, //stat(), mkdir()::ENOENT: A component of the path path does not exist, or the path is an empty string + SFM_DIR_NOTDIR, //stat(), mkdir()::ENOTDIR: A component of the path prefix is not a directory + SFM_DIR_ROFS //mkdir()::EROFS: The parent directory resides on a read-only file system + }; + +protected: + SFMError _error; + String _errorDesc; + public: virtual ~SaveFileManager() {} - + + /** + * Clears the last set error code and string. + */ + virtual void clearError() { _error = SFM_NO_ERROR; _errorDesc = ""; } + + /** + * Returns the last ocurred error code. If none ocurred, returns SFM_NO_ERROR. + * + * @return A SFMError indicating the type of the last error. + */ + virtual SFMError getError() { return _error; } + + /** + * Returns the last ocurred error description. If none ocurred, returns 0. + * + * @return A string describing the last error. + */ + virtual String getErrorDesc() { return _errorDesc; } + + /** + * Sets the last ocurred error. + * @param error Code identifying the last error. + * @param errorDesc String describing the last error. + */ + virtual void setError(SFMError error, String errorDesc) { _error = error; _errorDesc = errorDesc; } + /** * Open the file with name filename in the given directory for saving. * @param filename the filename -- cgit v1.2.3 From f42108e63399f4329bb1cadfd2e21d808aea8a89 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Fri, 20 Jul 2007 19:42:38 +0000 Subject: Added a remove() function to the Common::File class. Also changed the exists() function to account for new capabilities in the FSNode layer. svn-id: r28150 --- common/file.cpp | 40 ++++++++++++++++++++++++++++++++++------ common/file.h | 3 +++ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index 238c3a4bb3..30ac870f05 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -29,6 +29,10 @@ #include "common/util.h" #include "common/hash-str.h" +#if defined(UNIX) || defined(__SYMBIAN32__) +#include +#endif + #ifdef MACOSX #include "CoreFoundation/CoreFoundation.h" #endif @@ -408,16 +412,40 @@ bool File::open(const FilesystemNode &node, AccessMode mode) { return true; } +bool File::remove(const String &filename){ + if (remove(filename.c_str()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + +bool File::remove(const FilesystemNode &node){ + if (remove(node.getPath()) != 0) { + if(errno == EACCES) + ;//TODO: read-only file + if(errno == ENOENT) + ;//TODO: non-existent file + + return false; + } else { + return true; + } +} + bool File::exists(const String &filename) { // First try to find the file it via a FilesystemNode (in case an absolute // path was passed). But we only use this to filter out directories. FilesystemNode file(filename); - // FIXME: can't use isValid() here since at the time of writing - // FilesystemNode is to be unable to find for example files - // added in extrapath - if (file.isDirectory() || !file.exists()) - return false; - + + return (!file.isDirectory() && file.exists()); + + //***DEPRECATED COMMENTS BELOW, LEFT FOR DISCUSSION*** // Next, try to locate the file by *opening* it in read mode. This has // multiple effects: // 1) It takes _filesMap and _defaultDirectories into consideration -> good diff --git a/common/file.h b/common/file.h index 3d816a6104..4d519be475 100644 --- a/common/file.h +++ b/common/file.h @@ -86,6 +86,9 @@ public: virtual void close(); + virtual bool remove(const String &filename); + virtual bool remove(const FilesystemNode &node); + /** * Checks if the object opened a file successfully. * -- cgit v1.2.3 From 9752c75f407c8bd82006222433fcc3618b9e82bb Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sun, 29 Jul 2007 01:36:59 +0000 Subject: Add a removeSavefile() to the default savefile manager based on the new Common::File::remove(). svn-id: r28282 --- common/savefile.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'common') diff --git a/common/savefile.h b/common/savefile.h index 7c97ea5058..3e1b9ffaaa 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -136,6 +136,13 @@ public: */ virtual InSaveFile *openForLoading(const char *filename) = 0; + /** + * Removes the given savefile from the filesystem. + * @param filename Filename path pointing to the savefile. + * @return true if no error ocurred. false otherwise. + */ + virtual bool removeSavefile(const char *filename) = 0; + /** * Request a list of available savegames with a given regex. * @param regex Regular expression to match. Wildcards like * or ? are available. -- cgit v1.2.3 From 1400d28bfb37fc94f3c44dec0a4d0cef65fb8fb7 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Wed, 1 Aug 2007 22:07:50 +0000 Subject: Initial commit of the new BaseFile implementation. It provides a common ground for file objects across platforms and divides responsibilities between the Common::File class and a base file implementation. Also rearranged the factories into a new directory for clarity. Note 1: The posix-file.h and cpp files are for testing only. Only the ds, ps2 and symbian architecture will use special BaseFile based objects. Note 2: The current code does not yet make use of this new structure, since the Common::File remains intact. svn-id: r28395 --- common/file.h | 7 ++++++- common/fs.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/file.h b/common/file.h index 4d519be475..d2eae1f28c 100644 --- a/common/file.h +++ b/common/file.h @@ -30,6 +30,8 @@ #include "common/scummsys.h" #include "common/str.h" #include "common/stream.h" +#include "backends/file/base-file.h" +//#include "backends/factories/fs-factory-maker.cpp" class FilesystemNode; @@ -37,6 +39,9 @@ namespace Common { class File : public SeekableReadStream, public WriteStream { protected: + /** File handle to the actual file; 0 if no file is open. */ + //BaseFile *_test; + /** File handle to the actual file; 0 if no file is open. */ void *_handle; @@ -52,7 +57,7 @@ private: // code that accidentally copied File objects tended to break in strange // ways. File(const File &f); - File &operator =(const File &f); + File &operator =(const File &f); public: enum AccessMode { diff --git a/common/fs.cpp b/common/fs.cpp index 28f3e11f0b..40d9e4de14 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -25,7 +25,7 @@ #include "common/stdafx.h" #include "common/util.h" #include "backends/fs/abstract-fs.h" -#include "backends/fs/fs-factory-maker.cpp" +#include "backends/factories/fs-factory-maker.cpp" /* * Simple DOS-style pattern matching function (understands * and ? like used in DOS). -- cgit v1.2.3 From 1dc13a641dd82825334e81bb3eb3b4ebd69d2552 Mon Sep 17 00:00:00 2001 From: David Corrales Date: Sat, 18 Aug 2007 05:24:18 +0000 Subject: Merged some of the changes from the trunk patch back in to the GSoC fsnode branch. svn-id: r28649 --- common/file.cpp | 4 ---- common/file.h | 5 ++++- common/fs.cpp | 57 +++++++++++++++++++++++++++++++++----------------- common/fs.h | 65 ++++++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 90 insertions(+), 41 deletions(-) (limited to 'common') diff --git a/common/file.cpp b/common/file.cpp index 30ac870f05..e70a9328cb 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -24,14 +24,10 @@ */ #include "common/file.h" -#include "common/fs.h" #include "common/hashmap.h" #include "common/util.h" #include "common/hash-str.h" - -#if defined(UNIX) || defined(__SYMBIAN32__) #include -#endif #ifdef MACOSX #include "CoreFoundation/CoreFoundation.h" diff --git a/common/file.h b/common/file.h index c18776a377..19b1d45144 100644 --- a/common/file.h +++ b/common/file.h @@ -30,6 +30,9 @@ #include "common/scummsys.h" #include "common/str.h" #include "common/stream.h" +#include "common/fs.h" +#include "backends/file/base-file.h" +//#include "backends/factories/fs-factory-maker.h" class FilesystemNode; @@ -38,7 +41,7 @@ namespace Common { class File : public SeekableReadStream, public WriteStream { protected: /** File handle to the actual file; 0 if no file is open. */ - //BaseFile *_test; + BaseFile *_test; /** File handle to the actual file; 0 if no file is open. */ void *_handle; diff --git a/common/fs.cpp b/common/fs.cpp index 40d9e4de14..442e3ed4d7 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -24,6 +24,7 @@ #include "common/stdafx.h" #include "common/util.h" +#include "common/fs.h" #include "backends/fs/abstract-fs.h" #include "backends/factories/fs-factory-maker.cpp" @@ -107,12 +108,13 @@ FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { return *this; } -bool FilesystemNode::operator< (const FilesystemNode& node) const +bool FilesystemNode::operator<(const FilesystemNode& node) const { if (isDirectory() && !node.isDirectory()) return true; if (!isDirectory() && node.isDirectory()) return false; + return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; } @@ -130,6 +132,7 @@ void FilesystemNode::decRefCount() { bool FilesystemNode::exists() const { if (_realNode == 0) return false; + return _realNode->exists(); } @@ -189,62 +192,78 @@ Common::String FilesystemNode::getPath() const { bool FilesystemNode::isDirectory() const { if (_realNode == 0) return false; + return _realNode->isDirectory(); } bool FilesystemNode::isReadable() const { if (_realNode == 0) return false; + return _realNode->isReadable(); } bool FilesystemNode::isWritable() const { if (_realNode == 0) return false; + return _realNode->isWritable(); } bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const { - for(FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) - { - if(entry->isDirectory()) { - lookupFileRec(results, *entry, filename, hidden, exhaustive); + int matches = 0; + + for (FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) { + if (entry->isDirectory()) { + matches += lookupFileRec(results, *entry, filename, hidden, exhaustive); } } - - //TODO: we would return true even if no matches were found, if the initial results list isn't empty - return ((results.size() > 0) ? true : false); + + return ((matches > 0) ? true : false); } bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const { - lookupFileRec(results, dir, filename, hidden, exhaustive); + int matches; + + if (!dir.isDirectory()) + return false; + + matches = lookupFileRec(results, dir, filename, hidden, exhaustive); - //TODO: we would return true even if no matches were found, if the initial results list isn't empty - return ((results.size() > 0) ? true : false); + return ((matches > 0) ? true : false); } -void FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const +int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const { FSList entries; + FSList children; + int matches = 0; dir.getChildren(entries, FilesystemNode::kListAll, hidden); - for(FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) - { - if(entry->isDirectory()) { - lookupFileRec(results, *entry, filename, hidden, exhaustive); + //Breadth search (entries in the same level) + for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) { + if (entry->isDirectory()) { + children.push_back(*entry); } else { //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, // so it might be a good idea to include it inside the backend class. This would enforce its // implementation by all ports. - if(matchString(lastPathComponent(entry->getPath()), filename.c_str())) { + if(matchString(_realNode->getLastPathComponent(entry->getPath()), filename.c_str())) { results.push_back(*entry); + matches++; - if(!exhaustive) { + if (!exhaustive) break; - } } } } + + //Depth search (entries in lower levels) + for (FSList::iterator child = children.begin(); child != children.end(); ++child) { + matches += lookupFileRec(results, *child, filename, hidden, exhaustive); + } + + return matches; } diff --git a/common/fs.h b/common/fs.h index 6a2f049be1..7f634791d6 100644 --- a/common/fs.h +++ b/common/fs.h @@ -62,6 +62,8 @@ class FSList : public Common::Array {}; * paths (MacOS 9 doesn't even have the notion of a "current directory"). * And if we ever want to support devices with no FS in the classical sense (Palm...), * we can build upon this. + * + * This class acts as a wrapper around the AbstractFilesystemNode class defined in backends/fs. */ class FilesystemNode { private: @@ -80,9 +82,9 @@ public: }; /** - * 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. + * Create a new pathless FilesystemNode. Since there's no path associated + * with this node, path-related operations (i.e. exists(), isDirectory(), + * getPath()) will always return false or raise an assertion. */ FilesystemNode(); @@ -116,10 +118,12 @@ public: * Compare the name of this node to the name of another. Directories * go before normal files. */ - bool operator< (const FilesystemNode& node) const; + bool operator<(const FilesystemNode& node) const; /* - * Indicates whether the object refered by this path exists in the filesystem or not. + * Indicates whether the object referred by this path exists in the filesystem or not. + * + * @return bool true if the path exists, false otherwise. */ virtual bool exists() const; @@ -177,34 +181,53 @@ public: FilesystemNode getParent() const; /** - * Indicates whether this path refers to a directory or not. + * Indicates whether the path refers to a directory or not. * - * @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 + * @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 * kDirNodeType, kFileNodeType, kInvalidNodeType. */ virtual bool isDirectory() const; /** - * Indicates whether this path can be read from or not. + * Indicates whether the object referred by this path can be read from or not. + * + * If the path refers to a directory, readability implies being able to read + * and list the directory entries. + * + * If the path refers to a file, readability implies being able to read the + * contents of the file. + * + * @return bool true if the object can be read, false otherwise. */ virtual bool isReadable() const; /** - * Indicates whether this path can be written to or not. + * Indicates whether the object referred by this path can be written to or not. + * + * If the path refers to a directory, writability implies being able to modify + * the directory entry (i.e. rename the directory, remove it or write files inside of it). + * + * If the path refers to a file, writability implies being able to write data + * to the file. + * + * @return bool true if the object can be written to, false otherwise. */ virtual bool isWritable() const; /** * Searches recursively for a filename inside the given directories. * + * For each directory in the directory list a breadth-first search is performed, + * that is, the current directory entries are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param fslist List of directories to search within. * @param filename Name of the file to look for. - * @param hidden Whether to search hidden files or not. Default: false - * @param exhaustive Whether to continue searching after one match has been found. Default: false + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. * * @return true if matches could be found, false otherwise. */ @@ -213,11 +236,14 @@ public: /** * Searches recursively for a filename inside the given directory. * + * The search is performed breadth-first, that is, the current directory entries + * are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param FilesystemNode Directory to search within. * @param filename Name of the file to look for. - * @param hidden Whether to search hidden files or not. Default: false - * @param exhaustive Whether to continue searching after one match has been found. Default: false + * @param hidden Whether to search hidden files or not. + * @param exhaustive Whether to continue searching after one match has been found. * * @return true if matches could be found, false otherwise. */ @@ -233,13 +259,18 @@ protected: /** * Searches recursively for a filename inside the given directory. * + * The search is performed breadth-first, that is, the current directory entries + * are scanned before going into subdirectories. + * * @param results List to put the matches in. * @param FilesystemNode Directory to search within. * @param filename Name of the file to look for. * @param hidden Whether to search hidden files or not. * @param exhaustive Whether to continue searching after one match has been found. + * + * @return The number of matches found. */ - void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; + int lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; }; //} // End of namespace Common -- cgit v1.2.3