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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Sep 3 12:40:47 CEST 2008


Revision: 34301
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34301&view=rev
Author:   fingolfin
Date:     2008-09-03 10:40:46 +0000 (Wed, 03 Sep 2008)

Log Message:
-----------
Added new AbstractFilesystemNode::openForReading & ::openForWriting method, based on StdioStream; changed FilesystemNode to use them

Modified Paths:
--------------
    scummvm/trunk/backends/fs/abstract-fs.cpp
    scummvm/trunk/backends/fs/abstract-fs.h
    scummvm/trunk/common/fs.cpp

Modified: scummvm/trunk/backends/fs/abstract-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.cpp	2008-09-03 10:11:36 UTC (rev 34300)
+++ scummvm/trunk/backends/fs/abstract-fs.cpp	2008-09-03 10:40:46 UTC (rev 34301)
@@ -23,6 +23,7 @@
  */
 
 #include "backends/fs/abstract-fs.h"
+#include "common/file.h"
 
 const char *AbstractFilesystemNode::lastPathComponent(const Common::String &str, const char sep) {
 	if(str.empty())
@@ -37,3 +38,21 @@
 
 	return cur + 1;
 }
+
+Common::SeekableReadStream *AbstractFilesystemNode::openForReading() {
+	// FIXME: Until openForReading is supported by all AbstractFilesystemNode
+	// implementations, we provide this "generic" one, using Common::File.
+	FILE *handle = fopen(getPath().c_str(), "rb");
+	if (handle)
+		return new Common::StdioStream(handle);
+	return 0;
+}
+
+Common::WriteStream *AbstractFilesystemNode::openForWriting() {
+	// FIXME: Until openForWriting is supported by all AbstractFilesystemNode
+	// implementations, we provide this "generic" one.
+	FILE *handle = fopen(getPath().c_str(), "wb");
+	if (handle)
+		return new Common::StdioStream(handle);
+	return 0;
+}

Modified: scummvm/trunk/backends/fs/abstract-fs.h
===================================================================
--- scummvm/trunk/backends/fs/abstract-fs.h	2008-09-03 10:11:36 UTC (rev 34300)
+++ scummvm/trunk/backends/fs/abstract-fs.h	2008-09-03 10:40:46 UTC (rev 34301)
@@ -162,9 +162,24 @@
 	 */
 	virtual bool isWritable() const = 0;
 
-	/* TODO:
-	bool isFile();
-	*/
+
+	/**
+	 * Creates a SeekableReadStream instance corresponding to the file
+	 * referred by this node. This assumes that the node actually refers
+	 * to a readable file. If this is not the case, 0 is returned.
+	 *
+	 * @return pointer to the stream object, 0 in case of a failure
+	 */
+	virtual Common::SeekableReadStream *openForReading();
+
+	/**
+	 * Creates a WriteStream instance corresponding to the file
+	 * referred by this node. This assumes that the node actually refers
+	 * to a readable file. If this is not the case, 0 is returned.
+	 *
+	 * @return pointer to the stream object, 0 in case of a failure
+	 */
+	virtual Common::WriteStream *openForWriting();
 };
 
 

Modified: scummvm/trunk/common/fs.cpp
===================================================================
--- scummvm/trunk/common/fs.cpp	2008-09-03 10:11:36 UTC (rev 34300)
+++ scummvm/trunk/common/fs.cpp	2008-09-03 10:40:46 UTC (rev 34301)
@@ -23,7 +23,6 @@
  */
 
 #include "common/util.h"
-#include "common/file.h"
 #include "common/system.h"
 #include "backends/fs/abstract-fs.h"
 #include "backends/fs/fs-factory.h"
@@ -177,37 +176,28 @@
 Common::SeekableReadStream *FilesystemNode::openForReading() {
 	if (_realNode == 0)
 		return 0;
-#if 0
-	return _realNode->openForReading();
-#else
-	// FIXME: Until we support openForReading in AbstractFilesystemNode,
-	// we just use Common::File.
-	Common::File *confFile = new Common::File();
-	assert(confFile);
-	if (!confFile->open(*this)) {
-		delete confFile;
-		confFile = 0;
+
+	if (!_realNode->exists()) {
+		warning("File::open: Trying to open a FilesystemNode which does not exist");
+		return false;
+	} else if (_realNode->isDirectory()) {
+		warning("File::open: Trying to open a FilesystemNode which is a directory");
+		return false;
 	}
-	return confFile;
-#endif
+
+	return _realNode->openForReading();
 }
 
 Common::WriteStream *FilesystemNode::openForWriting() {
 	if (_realNode == 0)
 		return 0;
-#if 0
-	return _realNode->openForWriting();
-#else
-	// FIXME: Until we support openForWriting in AbstractFilesystemNode,
-	// we just use Common::DumpFile.
-	Common::DumpFile *confFile = new Common::DumpFile();
-	assert(confFile);
-	if (!confFile->open(*this)) {
-		delete confFile;
-		confFile = 0;
+
+	if (_realNode->isDirectory()) {
+		warning("File::open: Trying to open a FilesystemNode which is a directory");
+		return 0;
 	}
-	return confFile;
-#endif
+
+	return _realNode->openForWriting();
 }
 
 //}	// End of namespace Common


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