[Scummvm-cvs-logs] SF.net SVN: scummvm:[54418] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Mon Nov 22 19:07:34 CET 2010


Revision: 54418
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54418&view=rev
Author:   mthreepwood
Date:     2010-11-22 18:07:33 +0000 (Mon, 22 Nov 2010)

Log Message:
-----------
MOHAWK: Have MohawkResource::open() return a bool for success/failure

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/livingbooks.cpp
    scummvm/trunk/engines/mohawk/myst.cpp
    scummvm/trunk/engines/mohawk/resource.cpp
    scummvm/trunk/engines/mohawk/resource.h
    scummvm/trunk/engines/mohawk/riven.cpp
    scummvm/trunk/engines/mohawk/riven_saveload.cpp

Modified: scummvm/trunk/engines/mohawk/livingbooks.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/livingbooks.cpp	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/livingbooks.cpp	2010-11-22 18:07:33 UTC (rev 54418)
@@ -149,10 +149,12 @@
 	if (filename.empty())
 		filename = getFileNameFromConfig("Intro", "Page1.r");
 
-	if (!filename.empty() && Common::File::exists(filename)) {
+	if (!filename.empty()) {
 		MohawkArchive *introArchive = createMohawkArchive();
-		introArchive->open(filename);
-		_mhk.push_back(introArchive);
+		if (introArchive->open(filename))
+			_mhk.push_back(introArchive);
+		else
+			delete introArchive;
 	}
 
 	filename = getFileNameFromConfig("Intro", "Page2");
@@ -160,10 +162,12 @@
 	if (filename.empty())
 		filename = getFileNameFromConfig("Intro", "Page2.r");
 
-	if (!filename.empty() && Common::File::exists(filename)) {
+	if (!filename.empty()) {
 		MohawkArchive *coverArchive = createMohawkArchive();
-		coverArchive->open(filename);
-		_mhk.push_back(coverArchive);
+		if (coverArchive->open(filename))
+			_mhk.push_back(coverArchive);
+		else
+			delete coverArchive;
 	}
 }
 

Modified: scummvm/trunk/engines/mohawk/myst.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/myst.cpp	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/myst.cpp	2010-11-22 18:07:33 UTC (rev 54418)
@@ -264,7 +264,8 @@
 	// Load Help System (Masterpiece Edition Only)
 	if (getFeatures() & GF_ME) {
 		MohawkArchive *mhk = new MohawkArchive();
-		mhk->open("help.dat");
+		if (!mhk->open("help.dat"))
+			error("Could not load help.dat");
 		_mhk.push_back(mhk);
 	}
 
@@ -360,7 +361,8 @@
 		_mhk[0] = new MohawkArchive();
 	}
 
-	_mhk[0]->open(mystFiles[_curStack]);
+	if (!_mhk[0]->open(mystFiles[_curStack]))
+		error("Could not open %s", mystFiles[_curStack]);
 
 	if (getPlatform() == Common::kPlatformMacintosh)
 		_gfx->loadExternalPictureFile(_curStack);

Modified: scummvm/trunk/engines/mohawk/resource.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/resource.cpp	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/resource.cpp	2010-11-22 18:07:33 UTC (rev 54418)
@@ -36,14 +36,22 @@
 	_fileTable = NULL;
 }
 
-void MohawkArchive::open(Common::String filename) {
+bool MohawkArchive::open(Common::String filename) {
 	Common::File *file = new Common::File();
-	if (!file->open(filename.c_str()))
-		error ("Could not open file \'%s\'", filename.c_str());
 
+	if (!file->open(filename)) {
+		delete file;
+		return false;
+	}
+
 	_curFile = filename;
 
-	open(file);
+	if (!open(file)) {
+		close();
+		return false;
+	}
+
+	return true;
 }
 
 void MohawkArchive::close() {
@@ -54,23 +62,29 @@
 	_curFile.clear();
 }
 
-void MohawkArchive::open(Common::SeekableReadStream *stream) {
+bool MohawkArchive::open(Common::SeekableReadStream *stream) {
 	// Make sure no other file is open...
 	close();
 	_mhk = stream;
 
-	if (_mhk->readUint32BE() != ID_MHWK)
-		error ("Could not find tag \'MHWK\'");
+	if (_mhk->readUint32BE() != ID_MHWK) {
+		warning("Could not find tag 'MHWK'");
+		return false;
+	}
 
-	_fileSize = _mhk->readUint32BE();
+	/* uint32 fileSize = */ _mhk->readUint32BE();
 
-	if (_mhk->readUint32BE() != ID_RSRC)
-		error ("Could not find tag \'RSRC\'");
+	if (_mhk->readUint32BE() != ID_RSRC) {
+		warning("Could not find tag \'RSRC\'");
+		return false;
+	}
 
 	_rsrc.version = _mhk->readUint16BE();
 	
-	if (_rsrc.version != 0x100)
-		error("Unsupported Mohawk resource version %d.%d", (_rsrc.version >> 8) & 0xff, _rsrc.version & 0xff);
+	if (_rsrc.version != 0x100) {
+		warning("Unsupported Mohawk resource version %d.%d", (_rsrc.version >> 8) & 0xff, _rsrc.version & 0xff);
+		return false;
+	}
 	
 	_rsrc.compaction = _mhk->readUint16BE(); // Only used in creation, not in reading
 	_rsrc.filesize = _mhk->readUint32BE();
@@ -171,6 +185,8 @@
 
 		debug (4, "File[%02x]: Offset = %08x  DataSize = %07x  Flags = %02x  Unk = %04x", i, _fileTable[i].offset, _fileTable[i].dataSize, _fileTable[i].flags, _fileTable[i].unk);
 	}
+
+	return true;
 }
 
 int MohawkArchive::getTypeIndex(uint32 tag) {
@@ -287,7 +303,7 @@
 	return new Common::SeekableSubReadStream(_mhk, _fileTable[fileTableIndex].offset, _fileTable[fileTableIndex].offset + _fileTable[fileTableIndex].dataSize);
 }
 
-void LivingBooksArchive_v1::open(Common::SeekableReadStream *stream) {
+bool LivingBooksArchive_v1::open(Common::SeekableReadStream *stream) {
 	close();
 	_mhk = stream;
 
@@ -368,9 +384,12 @@
 			_mhk->seek(oldPos);
 			debug (3, "\n");
 		}
-	} else
-		error("Could not determine type of Old Mohawk resource");
+	} else {
+		warning("Could not determine type of Old Mohawk resource");
+		return false;
+	}
 
+	return true;
 }
 
 uint32 LivingBooksArchive_v1::getOffset(uint32 tag, uint16 id) {

Modified: scummvm/trunk/engines/mohawk/resource.h
===================================================================
--- scummvm/trunk/engines/mohawk/resource.h	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/resource.h	2010-11-22 18:07:33 UTC (rev 54418)
@@ -179,8 +179,8 @@
 	MohawkArchive();
 	virtual ~MohawkArchive() { close(); }
 
-	void open(Common::String filename);
-	virtual void open(Common::SeekableReadStream *stream);
+	bool open(Common::String filename);
+	virtual bool open(Common::SeekableReadStream *stream);
 	void close();
 
 	virtual bool hasResource(uint32 tag, uint16 id);
@@ -195,8 +195,6 @@
 	Common::String _curFile;
 
 private:
-	bool _hasData;
-	uint32 _fileSize;
 	RSRC_Header _rsrc;
 	Type *_types;
 	FileTable *_fileTable;
@@ -216,7 +214,7 @@
 
 	bool hasResource(uint32 tag, uint16 id);
 	bool hasResource(uint32 tag, const Common::String &resName) { return false; }
-	void open(Common::SeekableReadStream *stream);
+	bool open(Common::SeekableReadStream *stream);
 	Common::SeekableReadStream *getResource(uint32 tag, uint16 id);
 	Common::SeekableReadStream *getResource(uint32 tag, const Common::String &resName) { return 0; }
 	uint32 getOffset(uint32 tag, uint16 id);

Modified: scummvm/trunk/engines/mohawk/riven.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven.cpp	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/riven.cpp	2010-11-22 18:07:33 UTC (rev 54418)
@@ -119,8 +119,10 @@
 
 	// Open extras.mhk for common images
 	_extrasFile = new MohawkArchive();
-	_extrasFile->open("extras.mhk");
 
+	if (!_extrasFile->open("extras.mhk"))
+		error("Could not open extras.mhk");
+
 	// Start at main cursor
 	_gfx->changeCursor(kRivenMainCursor);
 
@@ -278,11 +280,12 @@
 	// Load any file that fits the patterns
 	for (int i = 0; i < ARRAYSIZE(endings); i++) {
 		Common::String filename = Common::String(prefix) + endings[i];
-		if (Common::File::exists(filename)) {
-			MohawkArchive *mhk = new MohawkArchive();
-			mhk->open(filename);
+
+		MohawkArchive *mhk = new MohawkArchive();
+		if (mhk->open(filename))
 			_mhk.push_back(mhk);
-		}
+		else
+			delete mhk;
 	}
 
 	// Make sure we have loaded files

Modified: scummvm/trunk/engines/mohawk/riven_saveload.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/riven_saveload.cpp	2010-11-22 17:51:54 UTC (rev 54417)
+++ scummvm/trunk/engines/mohawk/riven_saveload.cpp	2010-11-22 18:07:33 UTC (rev 54418)
@@ -102,8 +102,13 @@
 	debug(0, "Loading game from \'%s\'", filename.c_str());
 
 	MohawkArchive *mhk = new MohawkArchive();
-	mhk->open(loadFile);
 
+	if (!mhk->open(loadFile)) {
+		warning("Save file is not a Mohawk archive");
+		delete mhk;
+		return false;
+	}
+
 	// First, let's make sure we're using a saved game file from this version of Riven by checking the VERS resource
 	Common::SeekableReadStream *vers = mhk->getResource(ID_VERS, 1);
 	uint32 saveGameVersion = vers->readUint32BE();


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