aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDavid Corrales2007-06-05 21:02:35 +0000
committerDavid Corrales2007-06-05 21:02:35 +0000
commit3b96c7fad54ff7f5000667be494e50e7ca11e69a (patch)
tree265263a7fc44ca51c2391e929e7c4fd0da676315 /common
parent716bcd0b2bcd4d04489bc2fc23a948fad3e2c02a (diff)
downloadscummvm-rg350-3b96c7fad54ff7f5000667be494e50e7ca11e69a.tar.gz
scummvm-rg350-3b96c7fad54ff7f5000667be494e50e7ca11e69a.tar.bz2
scummvm-rg350-3b96c7fad54ff7f5000667be494e50e7ca11e69a.zip
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
Diffstat (limited to 'common')
-rw-r--r--common/advancedDetector.cpp6
-rw-r--r--common/file.cpp14
-rw-r--r--common/fs.cpp106
-rw-r--r--common/fs.h48
-rw-r--r--common/md5.cpp2
5 files changed, 97 insertions, 79 deletions
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) {