diff options
author | Sven Hesse | 2009-07-24 21:34:43 +0000 |
---|---|---|
committer | Sven Hesse | 2009-07-24 21:34:43 +0000 |
commit | 6a28c0af12bc98c8b2bc8f31f3d6fb63c9efaf9a (patch) | |
tree | 8260a06bed82334ecb81d6907ea287336f74b1bc | |
parent | b2154f612da6d92cb86338accd8a23f51c49e1f4 (diff) | |
download | scummvm-rg350-6a28c0af12bc98c8b2bc8f31f3d6fb63c9efaf9a.tar.gz scummvm-rg350-6a28c0af12bc98c8b2bc8f31f3d6fb63c9efaf9a.tar.bz2 scummvm-rg350-6a28c0af12bc98c8b2bc8f31f3d6fb63c9efaf9a.zip |
Added a method to easily dump resources to file
svn-id: r42711
-rw-r--r-- | engines/gob/resources.cpp | 44 | ||||
-rw-r--r-- | engines/gob/resources.h | 6 |
2 files changed, 45 insertions, 5 deletions
diff --git a/engines/gob/resources.cpp b/engines/gob/resources.cpp index c52b65f0d7..2f3b1b23e7 100644 --- a/engines/gob/resources.cpp +++ b/engines/gob/resources.cpp @@ -144,8 +144,6 @@ Resources::~Resources() { bool Resources::load(const Common::String &fileName) { unload(); - Common::String fileBase; - _totFile = TOTFile::createFileName(fileName, _hasLOM); if (_hasLOM) { @@ -154,9 +152,9 @@ bool Resources::load(const Common::String &fileName) { 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 @@ bool Resources::load(const Common::String &fileName) { return false; if (hasTOTRes) { - if (!loadTOTTextTable(fileBase)) { + if (!loadTOTTextTable(_fileBase)) { unload(); return false; } @@ -195,6 +193,7 @@ void Resources::unload(bool del) { delete[] _totData; delete[] _imData; + _fileBase.clear(); _totFile.clear(); _extFile.clear(); _exFile.clear(); @@ -573,6 +572,41 @@ byte *Resources::getTexts() const { 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)", diff --git a/engines/gob/resources.h b/engines/gob/resources.h index d316be83e5..7511185954 100644 --- a/engines/gob/resources.h +++ b/engines/gob/resources.h @@ -91,6 +91,11 @@ public: 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 @@ private: GobEngine *_vm; + Common::String _fileBase; Common::String _totFile; Common::String _extFile; Common::String _exFile; |