aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2006-07-22 17:01:50 +0000
committerJohannes Schickel2006-07-22 17:01:50 +0000
commit63aec29edb3e6065e5b167058247fa4cc39adef7 (patch)
tree35721f7221bf15e0a420d7fc75b432d4250e917d
parentc59e7ece0a825a75ab639edff3081465ef6b94fc (diff)
downloadscummvm-rg350-63aec29edb3e6065e5b167058247fa4cc39adef7.tar.gz
scummvm-rg350-63aec29edb3e6065e5b167058247fa4cc39adef7.tar.bz2
scummvm-rg350-63aec29edb3e6065e5b167058247fa4cc39adef7.zip
Added isValid to FilesystemNode and AbstractFilesystemNode. See my mail to -devel for more information.
svn-id: r23567
-rw-r--r--backends/fs/abstract-fs.h2
-rw-r--r--backends/fs/gp32/gp32-fs.cpp2
-rw-r--r--common/file.cpp14
-rw-r--r--common/fs.cpp6
-rw-r--r--common/fs.h5
5 files changed, 27 insertions, 2 deletions
diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h
index 7b5b7cbd1d..844d3115e1 100644
--- a/backends/fs/abstract-fs.h
+++ b/backends/fs/abstract-fs.h
@@ -104,6 +104,8 @@ public:
// By default, we use the actual file name as 'display name'.
virtual String displayName() const { return name(); }
+ virtual bool isValid() const = 0;
+
virtual bool isDirectory() const = 0;
/**
diff --git a/backends/fs/gp32/gp32-fs.cpp b/backends/fs/gp32/gp32-fs.cpp
index 4d242d339f..c94460d727 100644
--- a/backends/fs/gp32/gp32-fs.cpp
+++ b/backends/fs/gp32/gp32-fs.cpp
@@ -40,6 +40,8 @@ public:
virtual String displayName() const { return _displayName; }
virtual String name() const { return _displayName; }
+ // FIXME: isValid should return false if this Node can't be used!
+ // client code can rely on the return value.
virtual bool isValid() const { return true; }
virtual bool isDirectory() const { return _isDirectory; }
virtual String path() const { return _path; }
diff --git a/common/file.cpp b/common/file.cpp
index f8e131a80e..da682037e8 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -277,6 +277,15 @@ 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");
+ return false;
+ } else if (node.isDirectory()) {
+ warning("File::open: Trying to open a FilesystemNode which is a directory");
+ return false;
+ }
+
String filename(node.name());
if (_handle) {
@@ -288,10 +297,8 @@ bool File::open(const FilesystemNode &node, AccessMode mode) {
const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
-
_handle = fopen(node.path().c_str(), modeStr);
-
if (_handle == NULL) {
if (mode == kFileReadMode)
debug(2, "File %s not found", filename.c_str());
@@ -313,6 +320,9 @@ 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())
return false;
diff --git a/common/fs.cpp b/common/fs.cpp
index 56d7eab49b..11d580436f 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -77,6 +77,12 @@ FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) {
return *this;
}
+bool FilesystemNode::isValid() const {
+ if (_realNode == 0)
+ return false;
+ return _realNode->isValid();
+}
+
FilesystemNode FilesystemNode::getParent() const {
if (_realNode == 0)
return *this;
diff --git a/common/fs.h b/common/fs.h
index d18793f015..5d35c2581b 100644
--- a/common/fs.h
+++ b/common/fs.h
@@ -114,6 +114,11 @@ public:
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.
*/