[Scummvm-cvs-logs] SF.net SVN: scummvm:[42711] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Fri Jul 24 23:34:43 CEST 2009


Revision: 42711
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42711&view=rev
Author:   drmccoy
Date:     2009-07-24 21:34:43 +0000 (Fri, 24 Jul 2009)

Log Message:
-----------
Added a method to easily dump resources to file

Modified Paths:
--------------
    scummvm/trunk/engines/gob/resources.cpp
    scummvm/trunk/engines/gob/resources.h

Modified: scummvm/trunk/engines/gob/resources.cpp
===================================================================
--- scummvm/trunk/engines/gob/resources.cpp	2009-07-24 21:34:17 UTC (rev 42710)
+++ scummvm/trunk/engines/gob/resources.cpp	2009-07-24 21:34:43 UTC (rev 42711)
@@ -144,8 +144,6 @@
 bool Resources::load(const Common::String &fileName) {
 	unload();
 
-	Common::String fileBase;
-
 	_totFile = TOTFile::createFileName(fileName, _hasLOM);
 
 	if (_hasLOM) {
@@ -154,9 +152,9 @@
 		return false;
 	}
 
-	fileBase = TOTFile::getFileBase(fileName);
+	_fileBase = TOTFile::getFileBase(fileName);
 
-	_extFile = fileBase + ".ext";
+	_extFile = _fileBase + ".ext";
 
 	bool hasTOTRes = loadTOTResourceTable();
 	bool hasEXTRes = loadEXTResourceTable();
@@ -165,7 +163,7 @@
 		return false;
 
 	if (hasTOTRes) {
-		if (!loadTOTTextTable(fileBase)) {
+		if (!loadTOTTextTable(_fileBase)) {
 			unload();
 			return false;
 		}
@@ -195,6 +193,7 @@
 		delete[] _totData;
 		delete[] _imData;
 
+		_fileBase.clear();
 		_totFile.clear();
 		_extFile.clear();
 		_exFile.clear();
@@ -573,6 +572,41 @@
 	return _totTextTable->data;
 }
 
+bool Resources::dumpResource(const Resource &resource,
+		const Common::String &fileName) const {
+
+	Common::DumpFile dump;
+
+	if (!dump.open(fileName))
+		return false;
+
+	if (dump.write(resource.getData(), resource.getSize()) != ((uint32) resource.getSize()))
+		return false;
+
+	if (!dump.flush())
+		return false;
+	if (dump.err())
+		return false;
+
+	dump.close();
+	return true;
+}
+
+bool Resources::dumpResource(const Resource &resource, uint16 id,
+		const Common::String &ext) const {
+
+	Common::String fileName = _fileBase;
+
+	char idStr[7];
+
+	snprintf(idStr, 7, "_%05d", id);
+	fileName += idStr;
+	fileName += ".";
+	fileName += ext;
+
+	return dumpResource(resource, fileName);
+}
+
 Resource *Resources::getTOTResource(uint16 id) const {
 	if (id >= _totResourceTable->itemsCount) {
 		warning("Trying to load non-existent TOT resource (%s, %d/%d)",

Modified: scummvm/trunk/engines/gob/resources.h
===================================================================
--- scummvm/trunk/engines/gob/resources.h	2009-07-24 21:34:17 UTC (rev 42710)
+++ scummvm/trunk/engines/gob/resources.h	2009-07-24 21:34:43 UTC (rev 42711)
@@ -91,6 +91,11 @@
 
 	byte *getTexts() const;
 
+	bool dumpResource(const Resource &resource,
+			const Common::String &fileName) const;
+	bool dumpResource(const Resource &resource, uint16 id,
+			const Common::String &ext = "dmp") const;
+
 private:
 	// Structure sizes in the files
 	static const int kTOTResItemSize   = 4 + 2 + 2 + 2;
@@ -166,6 +171,7 @@
 
 	GobEngine *_vm;
 
+	Common::String _fileBase;
 	Common::String _totFile;
 	Common::String _extFile;
 	Common::String _exFile;


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