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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Apr 30 16:09:09 CEST 2006


Revision: 22251
Author:   fingolfin
Date:     2006-04-30 16:08:37 -0700 (Sun, 30 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22251&view=rev

Log Message:
-----------
Add a File::open variant that takes a FilesystemNode as parameter

Modified Paths:
--------------
    scummvm/trunk/common/file.cpp
    scummvm/trunk/common/file.h
Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2006-04-30 22:58:44 UTC (rev 22250)
+++ scummvm/trunk/common/file.cpp	2006-04-30 23:08:37 UTC (rev 22251)
@@ -195,6 +195,7 @@
 		error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
 	}
 
+	_name.clear();
 	clearIOFailed();
 
 	String fname(filename);
@@ -261,6 +262,40 @@
 	return true;
 }
 
+bool File::open(const FilesystemNode &node, AccessMode mode) {
+	assert(mode == kFileReadMode || mode == kFileWriteMode);
+	String filename(node.displayName());
+
+	if (_handle) {
+		error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
+	}
+
+	clearIOFailed();
+	_name.clear();
+
+	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());
+		else
+			debug(2, "File %s not opened", filename.c_str());
+		return false;
+	}
+
+	_name = filename;
+
+#ifdef DEBUG_FILE_REFCOUNT
+	warning("File::open on file '%s'", _name.c_str());
+#endif
+
+	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.
@@ -296,6 +331,7 @@
 	if (_handle)
 		fclose(_handle);
 	_handle = NULL;
+	_name.clear();
 }
 
 bool File::isOpen() const {

Modified: scummvm/trunk/common/file.h
===================================================================
--- scummvm/trunk/common/file.h	2006-04-30 22:58:44 UTC (rev 22250)
+++ scummvm/trunk/common/file.h	2006-04-30 23:08:37 UTC (rev 22251)
@@ -28,6 +28,8 @@
 #include "common/str.h"
 #include "common/stream.h"
 
+class FilesystemNode;
+
 namespace Common {
 
 class File : public SeekableReadStream, public WriteStream {
@@ -61,6 +63,7 @@
 	void decRef();
 
 	virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
+	virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
 	static bool exists(const String &filename);
 
 	virtual void close();


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