[Scummvm-cvs-logs] SF.net SVN: scummvm: [23567] scummvm/trunk/common

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Jul 22 19:02:00 CEST 2006


Revision: 23567
Author:   lordhoto
Date:     2006-07-22 10:01:50 -0700 (Sat, 22 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23567&view=rev

Log Message:
-----------
Added isValid to FilesystemNode and AbstractFilesystemNode. See my mail to -devel for more information.

Modified Paths:
--------------
    scummvm/trunk/backends/fs/abstract-fs.h
    scummvm/trunk/backends/fs/gp32/gp32-fs.cpp
    scummvm/trunk/common/file.cpp
    scummvm/trunk/common/fs.cpp
    scummvm/trunk/common/fs.h
Modified: scummvm/trunk/backends/fs/abstract-fs.h
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.h	2006-07-22 17:00:36 UTC (rev 23566)
+++ scummvm/trunk/backends/fs/abstract-fs.h	2006-07-22 17:01:50 UTC (rev 23567)
@@ -104,6 +104,8 @@
 	// 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;
 	
 	/**

Modified: scummvm/trunk/backends/fs/gp32/gp32-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/gp32/gp32-fs.cpp	2006-07-22 17:00:36 UTC (rev 23566)
+++ scummvm/trunk/backends/fs/gp32/gp32-fs.cpp	2006-07-22 17:01:50 UTC (rev 23567)
@@ -40,6 +40,8 @@
 
 	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; }

Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2006-07-22 17:00:36 UTC (rev 23566)
+++ scummvm/trunk/common/file.cpp	2006-07-22 17:01:50 UTC (rev 23567)
@@ -277,6 +277,15 @@
 
 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 @@
 
 	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 @@
 	// 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;
 

Modified: scummvm/trunk/common/fs.cpp
===================================================================
--- scummvm/trunk/common/fs.cpp	2006-07-22 17:00:36 UTC (rev 23566)
+++ scummvm/trunk/common/fs.cpp	2006-07-22 17:01:50 UTC (rev 23567)
@@ -77,6 +77,12 @@
 	return *this;
 }
 
+bool FilesystemNode::isValid() const {
+	if (_realNode == 0)
+		return false;
+	return _realNode->isValid();
+}
+
 FilesystemNode FilesystemNode::getParent() const {
 	if (_realNode == 0)
 		return *this;

Modified: scummvm/trunk/common/fs.h
===================================================================
--- scummvm/trunk/common/fs.h	2006-07-22 17:00:36 UTC (rev 23566)
+++ scummvm/trunk/common/fs.h	2006-07-22 17:01:50 UTC (rev 23567)
@@ -114,6 +114,11 @@
 	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.
 	 */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list