diff options
author | Matthew Hoops | 2010-11-22 18:07:33 +0000 |
---|---|---|
committer | Matthew Hoops | 2010-11-22 18:07:33 +0000 |
commit | cb843daec0e87747350c4432d9c4111b894c04b5 (patch) | |
tree | 22f10d70588674c497d5c96b75226d4c9ec7705e /engines | |
parent | 9d4827b5e1b56b5922aeced5a1d80cbfeaeb1405 (diff) | |
download | scummvm-rg350-cb843daec0e87747350c4432d9c4111b894c04b5.tar.gz scummvm-rg350-cb843daec0e87747350c4432d9c4111b894c04b5.tar.bz2 scummvm-rg350-cb843daec0e87747350c4432d9c4111b894c04b5.zip |
MOHAWK: Have MohawkResource::open() return a bool for success/failure
svn-id: r54418
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/livingbooks.cpp | 16 | ||||
-rw-r--r-- | engines/mohawk/myst.cpp | 6 | ||||
-rw-r--r-- | engines/mohawk/resource.cpp | 49 | ||||
-rw-r--r-- | engines/mohawk/resource.h | 8 | ||||
-rw-r--r-- | engines/mohawk/riven.cpp | 13 | ||||
-rw-r--r-- | engines/mohawk/riven_saveload.cpp | 7 |
6 files changed, 65 insertions, 34 deletions
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index d95decfc2a..1c562a96a0 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -149,10 +149,12 @@ void MohawkEngine_LivingBooks::loadIntro() { 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 @@ void MohawkEngine_LivingBooks::loadIntro() { 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; } } diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index 7778aff954..ba5e71be53 100644 --- a/engines/mohawk/myst.cpp +++ b/engines/mohawk/myst.cpp @@ -264,7 +264,8 @@ Common::Error MohawkEngine_Myst::run() { // 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 @@ void MohawkEngine_Myst::changeToStack(uint16 stack) { _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); diff --git a/engines/mohawk/resource.cpp b/engines/mohawk/resource.cpp index e9e1c6b792..e14eabcf45 100644 --- a/engines/mohawk/resource.cpp +++ b/engines/mohawk/resource.cpp @@ -36,14 +36,22 @@ MohawkArchive::MohawkArchive() { _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 @@ void MohawkArchive::close() { _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 @@ void MohawkArchive::open(Common::SeekableReadStream *stream) { 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 @@ Common::SeekableReadStream *MohawkArchive::getResource(uint32 tag, uint16 id) { 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 @@ void LivingBooksArchive_v1::open(Common::SeekableReadStream *stream) { _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) { diff --git a/engines/mohawk/resource.h b/engines/mohawk/resource.h index 00cd46ba1c..a1a2aadf72 100644 --- a/engines/mohawk/resource.h +++ b/engines/mohawk/resource.h @@ -179,8 +179,8 @@ public: 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 @@ protected: Common::String _curFile; private: - bool _hasData; - uint32 _fileSize; RSRC_Header _rsrc; Type *_types; FileTable *_fileTable; @@ -216,7 +214,7 @@ public: 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); diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 986f753c0e..8888200d8b 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -119,7 +119,9 @@ Common::Error MohawkEngine_Riven::run() { // 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 @@ void MohawkEngine_Riven::changeToStack(uint16 n) { // 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 diff --git a/engines/mohawk/riven_saveload.cpp b/engines/mohawk/riven_saveload.cpp index 40062ad27a..881e171b84 100644 --- a/engines/mohawk/riven_saveload.cpp +++ b/engines/mohawk/riven_saveload.cpp @@ -102,7 +102,12 @@ bool RivenSaveLoad::loadGame(Common::String filename) { 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); |