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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jul 29 18:09:12 CEST 2008


Revision: 33412
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33412&view=rev
Author:   fingolfin
Date:     2008-07-29 16:09:10 +0000 (Tue, 29 Jul 2008)

Log Message:
-----------
Changed class File (and derived classes) to only support read-only access; added a new class DumpFile for writing

Modified Paths:
--------------
    scummvm/trunk/common/config-file.cpp
    scummvm/trunk/common/config-manager.cpp
    scummvm/trunk/common/file.cpp
    scummvm/trunk/common/file.h
    scummvm/trunk/common/unarj.cpp
    scummvm/trunk/common/unarj.h
    scummvm/trunk/engines/agos/debug.cpp
    scummvm/trunk/engines/agos/saveload.cpp
    scummvm/trunk/engines/cine/part.cpp
    scummvm/trunk/engines/cine/script_fw.cpp
    scummvm/trunk/engines/cruise/volume.cpp
    scummvm/trunk/engines/gob/dataio.cpp
    scummvm/trunk/engines/gob/dataio.h
    scummvm/trunk/engines/scumm/charset.cpp
    scummvm/trunk/engines/scumm/debugger.cpp
    scummvm/trunk/engines/scumm/file.cpp
    scummvm/trunk/engines/scumm/file.h
    scummvm/trunk/engines/scumm/file_nes.cpp
    scummvm/trunk/engines/scumm/file_nes.h
    scummvm/trunk/engines/scumm/he/script_v60he.cpp
    scummvm/trunk/engines/scumm/he/script_v72he.cpp
    scummvm/trunk/engines/scumm/he/script_v80he.cpp
    scummvm/trunk/engines/scumm/he/wiz_he.cpp
    scummvm/trunk/engines/scumm/resource.cpp
    scummvm/trunk/engines/sky/disk.cpp
    scummvm/trunk/engines/sword1/resman.cpp
    scummvm/trunk/engines/sword2/resman.cpp
    scummvm/trunk/engines/tinsel/music.cpp
    scummvm/trunk/graphics/font.cpp
    scummvm/trunk/sound/softsynth/mt32.cpp

Modified: scummvm/trunk/common/config-file.cpp
===================================================================
--- scummvm/trunk/common/config-file.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/config-file.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -58,7 +58,7 @@
 
 bool ConfigFile::loadFromFile(const String &filename) {
 	File file;
-	if (file.open(filename, File::kFileReadMode))
+	if (file.open(filename))
 		return loadFromStream(file);
 	else
 		return false;
@@ -171,8 +171,8 @@
 }
 
 bool ConfigFile::saveToFile(const String &filename) {
-	File file;
-	if (file.open(filename, File::kFileWriteMode))
+	DumpFile file;
+	if (file.open(filename))
 		return saveToStream(file);
 	else
 		return false;

Modified: scummvm/trunk/common/config-manager.cpp
===================================================================
--- scummvm/trunk/common/config-manager.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/config-manager.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -289,13 +289,9 @@
 
 void ConfigManager::flushToDisk() {
 #ifndef __DC__
-	File cfg_file;
+	DumpFile cfg_file;
 
-// TODO
-//	if (!willwrite)
-//		return;
-
-	if (!cfg_file.open(_filename, File::kFileWriteMode)) {
+	if (!cfg_file.open(_filename)) {
 		warning("Unable to write configuration file: %s", _filename.c_str());
 	} else {
 		// First write the domains in _domainSaveOrder, in that order.

Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/file.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -104,7 +104,7 @@
 	//#define fgets(str, size, file)				DS::std_fgets(str, size, file)	// not used
 	//#define getc(handle)						DS::std_getc(handle)	// not used
 	//#define getcwd(dir, dunno)					DS::std_getcwd(dir, dunno)	// not used
-	//#define ferror(handle)						DS::std_ferror(handle)	// not used
+	#define ferror(handle)						DS::std_ferror(handle)
 
 #endif
 
@@ -273,59 +273,44 @@
 	: _handle(0), _ioFailed(false) {
 }
 
-//#define DEBUG_FILE_REFCOUNT
-
 File::~File() {
-#ifdef DEBUG_FILE_REFCOUNT
-	warning("File::~File on file '%s'", _name.c_str());
-#endif
 	close();
 }
 
 
-bool File::open(const String &filename, AccessMode mode) {
-	assert(mode == kFileReadMode || mode == kFileWriteMode);
+bool File::open(const String &filename) {
+	assert(!filename.empty());
+	assert(!_handle);
 
-	if (filename.empty()) {
-		error("File::open: No filename was specified");
-	}
-
-	if (_handle) {
-		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);
 	fname.toLowercase();
 
-	const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
-	if (mode == kFileWriteMode) {
-		_handle = fopenNoCase(filename, "", modeStr);
-	} else if (_filesMap && _filesMap->contains(fname)) {
+	if (_filesMap && _filesMap->contains(fname)) {
 		fname = (*_filesMap)[fname];
 		debug(3, "Opening hashed: %s", fname.c_str());
-		_handle = fopen(fname.c_str(), modeStr);
+		_handle = fopen(fname.c_str(), "rb");
 	} else if (_filesMap && _filesMap->contains(fname + ".")) {
 		// WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails"
 		// sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot)
 		fname = (*_filesMap)[fname + "."];
 		debug(3, "Opening hashed: %s", fname.c_str());
-		_handle = fopen(fname.c_str(), modeStr);
+		_handle = fopen(fname.c_str(), "rb");
 	} else {
 
 		if (_defaultDirectories) {
 			// Try all default directories
 			StringIntMap::const_iterator x(_defaultDirectories->begin());
 			for (; _handle == NULL && x != _defaultDirectories->end(); ++x) {
-				_handle = fopenNoCase(filename, x->_key, modeStr);
+				_handle = fopenNoCase(filename, x->_key, "rb");
 			}
 		}
 
 		// Last resort: try the current directory
 		if (_handle == NULL)
-			_handle = fopenNoCase(filename, "", modeStr);
+			_handle = fopenNoCase(filename, "", "rb");
 
 		// Last last (really) resort: try looking inside the application bundle on Mac OS X for the lowercase file.
 #if defined(MACOSX) || defined(IPHONE)
@@ -335,7 +320,7 @@
 			if (fileUrl) {
 				UInt8 buf[256];
 				if (CFURLGetFileSystemRepresentation(fileUrl, false, (UInt8 *)buf, 256)) {
-					_handle = fopen((char *)buf, modeStr);
+					_handle = fopen((char *)buf, "rb");
 				}
 				CFRelease(fileUrl);
 			}
@@ -345,26 +330,15 @@
 
 	}
 
-	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;
-	}
+	if (_handle == NULL)
+		debug(2, "File %s not opened", filename.c_str());
+	else
+		_name = filename;
 
-
-	_name = filename;
-
-#ifdef DEBUG_FILE_REFCOUNT
-	warning("File::open on file '%s'", _name.c_str());
-#endif
-
-	return true;
+	return _handle != NULL;
 }
 
-bool File::open(const FilesystemNode &node, AccessMode mode) {
-	assert(mode == kFileReadMode || mode == kFileWriteMode);
+bool File::open(const FilesystemNode &node) {
 
 	if (!node.exists()) {
 		warning("File::open: Trying to open a FilesystemNode which does not exist");
@@ -389,25 +363,14 @@
 	clearIOFailed();
 	_name.clear();
 
-	const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
+	_handle = fopen(node.getPath().c_str(), "rb");
 
-	_handle = fopen(node.getPath().c_str(), modeStr);
+	if (_handle == NULL)
+		debug(2, "File %s not found", filename.c_str());
+	else
+		_name = filename;
 
-	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;
+	return _handle != NULL;
 }
 
 bool File::exists(const String &filename) {
@@ -438,7 +401,7 @@
 
 	//Try opening the file inside the local directory as a last resort
 	File tmp;
-	return tmp.open(filename, kFileReadMode);
+	return tmp.open(filename);
 }
 
 void File::close() {
@@ -462,28 +425,19 @@
 }
 
 bool File::eof() const {
-	if (_handle == NULL) {
-		error("File::eof: File is not open!");
-		return false;
-	}
+	assert(_handle);
 
 	return feof((FILE *)_handle) != 0;
 }
 
 uint32 File::pos() const {
-	if (_handle == NULL) {
-		error("File::pos: File is not open!");
-		return 0;
-	}
+	assert(_handle);
 
 	return ftell((FILE *)_handle);
 }
 
 uint32 File::size() const {
-	if (_handle == NULL) {
-		error("File::size: File is not open!");
-		return 0;
-	}
+	assert(_handle);
 
 	uint32 oldPos = ftell((FILE *)_handle);
 	fseek((FILE *)_handle, 0, SEEK_END);
@@ -494,10 +448,7 @@
 }
 
 void File::seek(int32 offs, int whence) {
-	if (_handle == NULL) {
-		error("File::seek: File is not open!");
-		return;
-	}
+	assert(_handle);
 
 	if (fseek((FILE *)_handle, offs, whence) != 0)
 		clearerr((FILE *)_handle);
@@ -507,10 +458,7 @@
 	byte *ptr2 = (byte *)ptr;
 	uint32 real_len;
 
-	if (_handle == NULL) {
-		error("File::read: File is not open!");
-		return 0;
-	}
+	assert(_handle);
 
 	if (len == 0)
 		return 0;
@@ -523,20 +471,62 @@
 	return real_len;
 }
 
-uint32 File::write(const void *ptr, uint32 len) {
-	if (_handle == NULL) {
-		error("File::write: File is not open!");
-		return 0;
-	}
 
+DumpFile::DumpFile() : _handle(0) {
+}
+
+DumpFile::~DumpFile() {
+	close();
+}
+
+bool DumpFile::open(const String &filename) {
+	assert(!filename.empty());
+	assert(!_handle);
+
+	String fname(filename);
+	fname.toLowercase();
+	
+	_handle = fopenNoCase(filename, "", "wb");
+
+	if (_handle == NULL)
+		debug(2, "Failed to open '%s' for writing", filename.c_str());
+
+	return _handle != NULL;
+}
+
+void DumpFile::close() {
+	if (_handle)
+		fclose((FILE *)_handle);
+	_handle = NULL;
+}
+
+bool DumpFile::isOpen() const {
+	return _handle != NULL;
+}
+
+bool DumpFile::ioFailed() const {
+	assert(_handle);
+	return ferror((FILE *)_handle) != 0;
+}
+
+void DumpFile::clearIOFailed() {
+	assert(_handle);
+	clearerr((FILE *)_handle);
+}
+
+bool DumpFile::eof() const {
+	assert(_handle);
+	return feof((FILE *)_handle) != 0;
+}
+
+uint32 DumpFile::write(const void *ptr, uint32 len) {
+	assert(_handle);
+
 	if (len == 0)
 		return 0;
 
-	if ((uint32)fwrite(ptr, 1, len, (FILE *)_handle) != len) {
-		_ioFailed = true;
-	}
-
-	return len;
+	return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
 }
 
+
 }	// End of namespace Common

Modified: scummvm/trunk/common/file.h
===================================================================
--- scummvm/trunk/common/file.h	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/file.h	2008-07-29 16:09:10 UTC (rev 33412)
@@ -27,6 +27,7 @@
 #define COMMON_FILE_H
 
 #include "common/scummsys.h"
+#include "common/noncopyable.h"
 #include "common/str.h"
 #include "common/stream.h"
 
@@ -34,7 +35,10 @@
 
 namespace Common {
 
-class File : public SeekableReadStream, public WriteStream {
+/**
+ * TODO: vital to document this core class properly!!! For both users and implementors
+ */
+class File : public SeekableReadStream, public NonCopyable {
 protected:
 	/** File handle to the actual file; 0 if no file is open. */
 	void *_handle;
@@ -45,19 +49,7 @@
 	/** The name of this file, for debugging. */
 	String _name;
 
-private:
-	// Disallow copying File objects. There is not strict reason for this,
-	// except that so far we never had real need for such a feature, and
-	// code that accidentally copied File objects tended to break in strange
-	// ways.
-	File(const File &f);
-	File &operator =(const File &f);
-
 public:
-	enum AccessMode {
-		kFileReadMode = 1,
-		kFileWriteMode = 2
-	};
 
 	static void addDefaultDirectory(const String &directory);
 	static void addDefaultDirectoryRecursive(const String &directory, int level = 4, const String &prefix = "");
@@ -80,8 +72,8 @@
 	 */
 	static bool exists(const String &filename);
 
-	virtual bool open(const String &filename, AccessMode mode = kFileReadMode);
-	virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode);
+	virtual bool open(const String &filename);
+	virtual bool open(const FilesystemNode &node);
 
 	virtual void close();
 
@@ -114,9 +106,52 @@
 	virtual uint32 size() const;
 	void seek(int32 offs, int whence = SEEK_SET);
 	uint32 read(void *dataPtr, uint32 dataSize);
+};
+
+
+/**
+ * TODO: document this class
+ *
+ * Some design ideas:
+ *  - automatically drop all files into dumps/ dir? Might not be desired in all cases
+ */
+class DumpFile : public WriteStream, public NonCopyable {
+protected:
+	/** File handle to the actual file; 0 if no file is open. */
+	void *_handle;
+
+public:
+	DumpFile();
+	virtual ~DumpFile();
+
+	virtual bool open(const String &filename);
+	//virtual bool open(const FilesystemNode &node);
+
+	virtual void close();
+
+	/**
+	 * Checks if the object opened a file successfully.
+	 *
+	 * @return: true if any file is opened, false otherwise.
+	 */
+	bool isOpen() const;
+
+
+	bool ioFailed() const;
+	void clearIOFailed();
+	bool eos() const { return eof(); }
+
+	/**
+	 * Checks for end of file.
+	 *
+	 * @return: true if the end of file is reached, false otherwise.
+	 */
+	virtual bool eof() const;
+
 	uint32 write(const void *dataPtr, uint32 dataSize);
 };
 
+
 } // End of namespace Common
 
 #endif

Modified: scummvm/trunk/common/unarj.cpp
===================================================================
--- scummvm/trunk/common/unarj.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/unarj.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -231,7 +231,7 @@
 }
 
 
-bool ArjFile::open(const Common::String &filename, AccessMode mode) {
+bool ArjFile::open(const Common::String &filename) {
 	if (_isOpen)
 		error("Attempt to open another instance of archive");
 

Modified: scummvm/trunk/common/unarj.h
===================================================================
--- scummvm/trunk/common/unarj.h	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/common/unarj.h	2008-07-29 16:09:10 UTC (rev 33412)
@@ -110,7 +110,7 @@
 
 	void registerArchive(const String &filename);
 
-	bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
+	bool open(const Common::String &filename);
 	void close();
 
 	uint32 read(void *dataPtr, uint32 dataSize);

Modified: scummvm/trunk/engines/agos/debug.cpp
===================================================================
--- scummvm/trunk/engines/agos/debug.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/agos/debug.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -393,11 +393,11 @@
 };
 
 void dumpBMP(const char *filename, int w, int h, const byte *bytes, const uint32 *palette) {
-	Common::File out;
+	Common::DumpFile out;
 	byte my_hdr[sizeof(bmp_hdr)];
 	int i;
 
-	out.open(filename, Common::File::kFileWriteMode);
+	out.open(filename);
 	if (!out.isOpen())
 		return;
 

Modified: scummvm/trunk/engines/agos/saveload.cpp
===================================================================
--- scummvm/trunk/engines/agos/saveload.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/agos/saveload.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -978,7 +978,7 @@
 	if (restartMode) {
 		// Load restart state
 		Common::File *file = new Common::File();
-		file->open(filename, Common::File::kFileReadMode);
+		file->open(filename);
 		f = file;
 	} else {
 		f = _saveFileMan->openForLoading(filename);
@@ -1154,7 +1154,7 @@
 	if (restartMode) {
 		// Load restart state
 		Common::File *file = new Common::File();
-		file->open(filename, Common::File::kFileReadMode);
+		file->open(filename);
 		f = file;
 	} else {
 		f = _saveFileMan->openForLoading(filename);

Modified: scummvm/trunk/engines/cine/part.cpp
===================================================================
--- scummvm/trunk/engines/cine/part.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/cine/part.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -289,8 +289,8 @@
 
 		debug(0, "%s", partBuffer[i].partName);
 
-		Common::File out;
-		if (out.open(Common::String("dumps/") + partBuffer[i].partName, Common::File::kFileWriteMode)) {
+		Common::DumpFile out;
+		if (out.open(Common::String("dumps/") + partBuffer[i].partName)) {
 			out.write(data, partBuffer[i].unpackedSize);
 			out.close();
 		}

Modified: scummvm/trunk/engines/cine/script_fw.cpp
===================================================================
--- scummvm/trunk/engines/cine/script_fw.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/cine/script_fw.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -2957,10 +2957,10 @@
 }
 
 void dumpScript(char *dumpName) {
-    Common::File fHandle;
+    Common::DumpFile fHandle;
 	uint16 i;
 
-	fHandle.open(dumpName, Common::File::kFileWriteMode);
+	fHandle.open(dumpName);
 
 	for (i = 0; i < decompileBufferPosition; i++) {
 		fHandle.writeString(Common::String(decompileBuffer[i]));

Modified: scummvm/trunk/engines/cruise/volume.cpp
===================================================================
--- scummvm/trunk/engines/cruise/volume.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/cruise/volume.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -456,8 +456,8 @@
 			sprintf(nameBuffer, "%s", buffer[j].name);
 
 			if (buffer[j].size == buffer[j].extSize) {
-				Common::File fout;
-				fout.open(nameBuffer, Common::File::kFileWriteMode);
+				Common::DumpFile fout;
+				fout.open(nameBuffer);
 				if(fout.isOpen())
 					fout.write(bufferLocal, buffer[j].size);
 			} else {

Modified: scummvm/trunk/engines/gob/dataio.cpp
===================================================================
--- scummvm/trunk/engines/gob/dataio.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/gob/dataio.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -202,7 +202,7 @@
 	return &_filesHandles[handle];
 }
 
-int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) {
+int16 DataIO::file_open(const char *path) {
 	int16 i;
 
 	for (i = 0; i < MAX_FILES; i++) {
@@ -212,7 +212,7 @@
 	if (i == MAX_FILES)
 		return -1;
 
-	file_getHandle(i)->open(path, mode);
+	file_getHandle(i)->open(path);
 
 	if (file_getHandle(i)->isOpen())
 		return i;
@@ -467,17 +467,14 @@
 		file_getHandle(handle)->close();
 }
 
-int16 DataIO::openData(const char *path, Common::File::AccessMode mode) {
+int16 DataIO::openData(const char *path) {
 	int16 handle;
 
-	if (mode != Common::File::kFileReadMode)
-		return file_open(path, mode);
-
 	handle = getChunk(path);
 	if (handle >= 0)
 		return handle;
 
-	return file_open(path, mode);
+	return file_open(path);
 }
 
 DataStream *DataIO::openAsStream(int16 handle, bool dispose) {

Modified: scummvm/trunk/engines/gob/dataio.h
===================================================================
--- scummvm/trunk/engines/gob/dataio.h	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/gob/dataio.h	2008-07-29 16:09:10 UTC (rev 33412)
@@ -79,8 +79,7 @@
 	void closeDataFile(bool itk = 0);
 	byte *getUnpackedData(const char *name);
 	void closeData(int16 handle);
-	int16 openData(const char *path,
-			Common::File::AccessMode mode = Common::File::kFileReadMode);
+	int16 openData(const char *path);
 	DataStream *openAsStream(int16 handle, bool dispose = false);
 
 	int32 getDataSize(const char *name);
@@ -104,8 +103,7 @@
 
 	class GobEngine *_vm;
 
-	int16 file_open(const char *path,
-			Common::File::AccessMode mode = Common::File::kFileReadMode);
+	int16 file_open(const char *path);
 	Common::File *file_getHandle(int16 handle);
 	const Common::File *file_getHandle(int16 handle) const;
 

Modified: scummvm/trunk/engines/scumm/charset.cpp
===================================================================
--- scummvm/trunk/engines/scumm/charset.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/charset.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -56,7 +56,7 @@
 		_2byteWidth = 16;
 		_2byteHeight = 16;
 		// use FM-TOWNS font rom, since game files don't have kanji font resources
-		if (fp.open("fmt_fnt.rom", Common::File::kFileReadMode)) {
+		if (fp.open("fmt_fnt.rom")) {
 			_useCJKMode = true;
 			debug(2, "Loading FM-TOWNS Kanji rom");
 			_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];

Modified: scummvm/trunk/engines/scumm/debugger.cpp
===================================================================
--- scummvm/trunk/engines/scumm/debugger.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/debugger.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -298,7 +298,7 @@
 	// FIXME add bounds check
 
 	if (!strncmp(argv[1], "scr", 3)) {
-		file.open(argv[2], Common::File::kFileReadMode);
+		file.open(argv[2]);
 		if (file.isOpen() == false) {
 			DebugPrintf("Could not open file %s\n", argv[2]);
 			return true;

Modified: scummvm/trunk/engines/scumm/file.cpp
===================================================================
--- scummvm/trunk/engines/scumm/file.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/file.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -58,8 +58,8 @@
 	seek(0, SEEK_SET);
 }
 
-bool ScummFile::open(const Common::String &filename, AccessMode mode) {
-	if (File::open(filename, mode)) {
+bool ScummFile::open(const Common::String &filename) {
+	if (File::open(filename)) {
 		resetSubfile();
 		return true;
 	} else {
@@ -187,11 +187,6 @@
 	return realLen;
 }
 
-uint32 ScummFile::write(const void *, uint32) {
-	error("ScummFile does not support writing!");
-	return 0;
-}
-
 #pragma mark -
 #pragma mark --- ScummDiskImage ---
 #pragma mark -
@@ -250,11 +245,6 @@
 	}
 }
 
-uint32 ScummDiskImage::write(const void *, uint32) {
-	error("ScummDiskImage does not support writing!");
-	return 0;
-}
-
 void ScummDiskImage::setEnc(byte enc) {
 	_stream->setEnc(enc);
 }
@@ -300,7 +290,7 @@
 	return true;
 }
 
-bool ScummDiskImage::open(const Common::String &filename, AccessMode mode) {
+bool ScummDiskImage::open(const Common::String &filename) {
 	uint16 signature;
 
 	// check signature

Modified: scummvm/trunk/engines/scumm/file.h
===================================================================
--- scummvm/trunk/engines/scumm/file.h	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/file.h	2008-07-29 16:09:10 UTC (rev 33412)
@@ -36,7 +36,7 @@
 public:
 	virtual void setEnc(byte value) = 0;
 
-	virtual bool open(const Common::String &filename, AccessMode mode = kFileReadMode) = 0;
+	virtual bool open(const Common::String &filename) = 0;
 	virtual bool openSubFile(const Common::String &filename) = 0;
 
 	virtual bool eof() = 0;
@@ -44,7 +44,6 @@
 	virtual uint32 size() = 0;
 	virtual void seek(int32 offs, int whence = SEEK_SET) = 0;
 	virtual uint32 read(void *dataPtr, uint32 dataSize) = 0;
-	virtual uint32 write(const void *dataPtr, uint32 dataSize) = 0;
 };
 
 class ScummFile : public BaseScummFile {
@@ -59,7 +58,7 @@
 	void setSubfileRange(uint32 start, uint32 len);
 	void resetSubfile();
 
-	bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
+	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
 
 	bool eof();
@@ -67,7 +66,6 @@
 	uint32 size();
 	void seek(int32 offs, int whence = SEEK_SET);
 	uint32 read(void *dataPtr, uint32 dataSize);
-	uint32 write(const void *dataPtr, uint32 dataSize);
 };
 
 class ScummDiskImage : public BaseScummFile {
@@ -104,7 +102,7 @@
 	ScummDiskImage(const char *disk1, const char *disk2, GameSettings game);
 	void setEnc(byte value);
 
-	bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
+	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
 
 	void close();
@@ -113,7 +111,6 @@
 	uint32 size() { return _stream->size(); }
 	void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
 	uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
-	uint32 write(const void *dataPtr, uint32 dataSize);
 };
 
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/file_nes.cpp
===================================================================
--- scummvm/trunk/engines/scumm/file_nes.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/file_nes.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -62,11 +62,6 @@
 ScummNESFile::ScummNESFile() : _stream(0), _buf(0), _ROMset(kROMsetNum) {
 }
 
-uint32 ScummNESFile::write(const void *, uint32) {
-	error("ScummNESFile does not support writing!");
-	return 0;
-}
-
 void ScummNESFile::setEnc(byte enc) {
 	_stream->setEnc(enc);
 }
@@ -1234,7 +1229,7 @@
 	return true;
 }
 
-bool ScummNESFile::open(const Common::String &filename, AccessMode mode) {
+bool ScummNESFile::open(const Common::String &filename) {
 
 	if (_ROMset == kROMsetNum) {
 		char md5str[32+1];
@@ -1267,9 +1262,8 @@
 		}
 	}
 
-	if (File::open(filename, mode)) {
-		if (_stream)
-			delete _stream;
+	if (File::open(filename)) {
+		delete _stream;
 		_stream = 0;
 
 		free(_buf);
@@ -1282,8 +1276,7 @@
 }
 
 void ScummNESFile::close() {
-	if (_stream)
-		delete _stream;
+	delete _stream;
 	_stream = 0;
 
 	free(_buf);

Modified: scummvm/trunk/engines/scumm/file_nes.h
===================================================================
--- scummvm/trunk/engines/scumm/file_nes.h	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/file_nes.h	2008-07-29 16:09:10 UTC (rev 33412)
@@ -64,7 +64,7 @@
 	ScummNESFile();
 	void setEnc(byte value);
 
-	bool open(const Common::String &filename, AccessMode mode = kFileReadMode);
+	bool open(const Common::String &filename);
 	bool openSubFile(const Common::String &filename);
 
 	void close();
@@ -73,7 +73,6 @@
 	uint32 size() { return _stream->size(); }
 	void seek(int32 offs, int whence = SEEK_SET) { _stream->seek(offs, whence); }
 	uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); }
-	uint32 write(const void *dataPtr, uint32 dataSize);
 };
 
 } // End of namespace Scumm

Modified: scummvm/trunk/engines/scumm/he/script_v60he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v60he.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/he/script_v60he.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -1012,7 +1012,7 @@
 			_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
 			if (_hInFileTable[slot] == 0) {
 				Common::File *f = new Common::File();
-				f->open(filename, Common::File::kFileReadMode);
+				f->open(filename);
 				if (!f->isOpen())
 					delete f;
 				else

Modified: scummvm/trunk/engines/scumm/he/script_v72he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v72he.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/he/script_v72he.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -1692,7 +1692,7 @@
 			_hInFileTable[slot] = _saveFileMan->openForLoading(filename);
 			if (_hInFileTable[slot] == 0) {
 				Common::File *f = new Common::File();
-				f->open(filename, Common::File::kFileReadMode);
+				f->open(filename);
 				if (!f->isOpen())
 					delete f;
 				else

Modified: scummvm/trunk/engines/scumm/he/script_v80he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/script_v80he.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/he/script_v80he.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -409,7 +409,7 @@
 	Common::SeekableReadStream *f = _saveFileMan->openForLoading((const char *)filename);
 	if (!f) {
 		Common::File *file = new Common::File();
-		file->open((const char *)filename, Common::File::kFileReadMode);
+		file->open((const char *)filename);
 		if (!file->isOpen())
 			delete f;
 		else

Modified: scummvm/trunk/engines/scumm/he/wiz_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/wiz_he.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/he/wiz_he.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -1881,7 +1881,7 @@
 			memcpy(filename, params->filename, 260);
 			_vm->convertFilePath(filename);
 
-			if (f.open((const char *)filename, Common::File::kFileReadMode)) {
+			if (f.open((const char *)filename)) {
 				uint32 id = f.readUint32BE();
 				if (id == MKID_BE('AWIZ') || id == MKID_BE('MULT')) {
 					uint32 size = f.readUint32BE();
@@ -1911,7 +1911,7 @@
 		break;
 	case 4:
 		if (params->processFlags & kWPFUseFile) {
-			Common::File f;
+			Common::DumpFile f;
 
 			switch (params->fileWriteMode) {
 			case 2:
@@ -1924,7 +1924,7 @@
 				memcpy(filename, params->filename, 260);
 				_vm->convertFilePath(filename);
 
-				if (!f.open((const char *)filename, Common::File::kFileWriteMode)) {
+				if (!f.open((const char *)filename)) {
 					debug(0, "Unable to open for write '%s'", filename);
 					_vm->VAR(119) = -3;
 				} else {

Modified: scummvm/trunk/engines/scumm/resource.cpp
===================================================================
--- scummvm/trunk/engines/scumm/resource.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/scumm/resource.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -1299,7 +1299,7 @@
 
 void ScummEngine::dumpResource(const char *tag, int idx, const byte *ptr, int length) {
 	char buf[256];
-	Common::File out;
+	Common::DumpFile out;
 
 	uint32 size;
 	if (length >= 0)
@@ -1313,7 +1313,7 @@
 
 	sprintf(buf, "dumps/%s%d.dmp", tag, idx);
 
-	out.open(buf, Common::File::kFileWriteMode);
+	out.open(buf);
 	if (out.isOpen() == false)
 		return;
 	out.write(ptr, size);

Modified: scummvm/trunk/engines/sky/disk.cpp
===================================================================
--- scummvm/trunk/engines/sky/disk.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/sky/disk.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -326,14 +326,14 @@
 
 void Disk::dumpFile(uint16 fileNr) {
 	char buf[128];
-	Common::File out;
+	Common::DumpFile out;
 	byte* filePtr;
 
 	filePtr = loadFile(fileNr);
 	sprintf(buf, "dumps/file-%d.dmp", fileNr);
 
 	if (!Common::File::exists(buf)) {
-		if (out.open(buf, Common::File::kFileWriteMode))
+		if (out.open(buf))
 			out.write(filePtr, _lastLoadedFileSize);
 	}
 	free(filePtr);

Modified: scummvm/trunk/engines/sword1/resman.cpp
===================================================================
--- scummvm/trunk/engines/sword1/resman.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/sword1/resman.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -212,8 +212,8 @@
 void ResMan::dumpRes(uint32 id) {
 	char outn[30];
 	sprintf(outn, "DUMP%08X.BIN", id);
-	Common::File outf;
-	if (outf.open(outn, Common::File::kFileWriteMode)) {
+	Common::DumpFile outf;
+	if (outf.open(outn)) {
 		resOpen(id);
 		MemHandle *memHandle = resHandle(id);
 		outf.write(memHandle->data, memHandle->size);

Modified: scummvm/trunk/engines/sword2/resman.cpp
===================================================================
--- scummvm/trunk/engines/sword2/resman.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/sword2/resman.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -234,7 +234,6 @@
 /**
  * Returns the address of a resource. Loads if not in memory. Retains a count.
  */
-
 byte *ResourceManager::openResource(uint32 res, bool dump) {
 	assert(res < _totalResFiles);
 
@@ -287,7 +286,6 @@
 		if (dump) {
 			char buf[256];
 			const char *tag;
-			Common::File out;
 
 			switch (fetchType(_resList[res].ptr)) {
 			case ANIMATION_FILE:
@@ -337,7 +335,8 @@
 			sprintf(buf, "dumps/%s-%d.dmp", tag, res);
 
 			if (!Common::File::exists(buf)) {
-				if (out.open(buf, Common::File::kFileWriteMode))
+				Common::DumpFile out;
+				if (out.open(buf))
 					out.write(_resList[res].ptr, len);
 			}
 		}

Modified: scummvm/trunk/engines/tinsel/music.cpp
===================================================================
--- scummvm/trunk/engines/tinsel/music.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/engines/tinsel/music.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -507,7 +507,7 @@
 // Dumps all of the game's music in external XMIDI *.xmi files
 void dumpMusic() {
 	Common::File midiFile;
-	Common::File outFile;
+	Common::DumpFile outFile;
 	char outName[20];
 	midiFile.open(MIDI_FILE);
 	int outFileSize = 0;
@@ -519,7 +519,7 @@
 
 	for (int i = 0; i < total; i++) {
 		sprintf(outName, "track%03d.xmi", i + 1);
-		outFile.open(outName, Common::File::kFileWriteMode);
+		outFile.open(outName);
 
 		if (_vm->getFeatures() & GF_SCNFILES) {
 			if (i < total - 1)

Modified: scummvm/trunk/graphics/font.cpp
===================================================================
--- scummvm/trunk/graphics/font.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/graphics/font.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -585,8 +585,8 @@
 }
 
 bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
-	Common::File cacheFile;
-	if (!cacheFile.open(filename, Common::File::kFileWriteMode)) {
+	Common::DumpFile cacheFile;
+	if (!cacheFile.open(filename)) {
 		warning("Couldn't open file '%s' for writing", filename.c_str());
 		return false;
 	}

Modified: scummvm/trunk/sound/softsynth/mt32.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32.cpp	2008-07-29 14:57:13 UTC (rev 33411)
+++ scummvm/trunk/sound/softsynth/mt32.cpp	2008-07-29 16:09:10 UTC (rev 33412)
@@ -80,37 +80,41 @@
 };
 
 class MT32File : public MT32Emu::File {
-	Common::File file;
+	Common::File _in;
+	Common::DumpFile _out;
 public:
 	bool open(const char *filename, OpenMode mode) {
-		Common::File::AccessMode accessMode = mode == OpenMode_read ? Common::File::kFileReadMode : Common::File::kFileWriteMode;
-		return file.open(filename, accessMode);
+		if (mode == OpenMode_read)
+			return _in.open(filename);
+		else
+			return _out.open(filename);
 	}
 	void close() {
-		return file.close();
+		_in.close();
+		_out.close();
 	}
 	size_t read(void *in, size_t size) {
-		return file.read(in, size);
+		return _in.read(in, size);
 	}
 	bool readLine(char *in, size_t size) {
-		return file.readLine(in, size) != NULL;
+		return _in.readLine(in, size) != NULL;
 	}
 	bool readBit8u(MT32Emu::Bit8u *in) {
-		byte b = file.readByte();
-		if (file.eof())
+		byte b = _in.readByte();
+		if (_in.eof())
 			return false;
 		*in = b;
 		return true;
 	}
 	size_t write(const void *in, size_t size) {
-		return file.write(in, size);
+		return _out.write(in, size);
 	}
 	bool writeBit8u(MT32Emu::Bit8u out) {
-		file.writeByte(out);
-		return !file.ioFailed();
+		_out.writeByte(out);
+		return !_out.ioFailed();
 	}
 	bool isEOF() {
-		return file.eof();
+		return _in.isOpen() ? _in.eof() : _out.eof();
 	}
 };
 


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