diff --git a/common/macresman.cpp b/common/macresman.cpp index cb3f1c5b8a4..de78cedf61f 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -110,6 +110,7 @@ bool MacResManager::open(Common::String filename) { _baseFileName = filename; return true; } + delete macResForkRawStream; #endif Common::File *file = new Common::File(); @@ -119,18 +120,21 @@ bool MacResManager::open(Common::String filename) { _baseFileName = filename; return true; } + file->close(); // Check .bin too if (file->open(filename + ".bin") && loadFromMacBinary(*file)) { _baseFileName = filename; return true; } - + file->close(); + // Maybe we have a dumped fork? if (file->open(filename + ".rsrc") && loadFromRawFork(*file)) { _baseFileName = filename; return true; } + file->close(); // Fine, what about just the data fork? if (file->open(filename)) { @@ -138,13 +142,15 @@ bool MacResManager::open(Common::String filename) { if (isMacBinary(*file)) { file->seek(0, SEEK_SET); - loadFromMacBinary(*file); - } else { - _stream = file; + if (loadFromMacBinary(*file)) + return true; } + + file->seek(0, SEEK_SET); + _stream = file; return true; } - + delete file; // The file doesn't exist @@ -163,39 +169,56 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) { _baseFileName = filename; return true; } + delete macResForkRawStream; #endif // First, let's try to see if the Mac converted name exists Common::FSNode fsNode = path.getChild("._" + filename); - if (fsNode.exists() && !fsNode.isDirectory() && loadFromAppleDouble(*fsNode.createReadStream())) { - _baseFileName = filename; - return true; + if (fsNode.exists() && !fsNode.isDirectory()) { + SeekableReadStream *stream = fsNode.createReadStream(); + if (loadFromAppleDouble(*stream)) { + _baseFileName = filename; + return true; + } + delete stream; } // Check .bin too fsNode = path.getChild(filename + ".bin"); - if (fsNode.exists() && !fsNode.isDirectory() && loadFromMacBinary(*fsNode.createReadStream())) { - _baseFileName = filename; - return true; + if (fsNode.exists() && !fsNode.isDirectory()) { + SeekableReadStream *stream = fsNode.createReadStream(); + if (loadFromMacBinary(*stream)) { + _baseFileName = filename; + return true; + } + delete stream; } - + // Maybe we have a dumped fork? fsNode = path.getChild(filename + ".rsrc"); - if (fsNode.exists() && !fsNode.isDirectory() && loadFromRawFork(*fsNode.createReadStream())) { - _baseFileName = filename; - return true; + if (fsNode.exists() && !fsNode.isDirectory()) { + SeekableReadStream *stream = fsNode.createReadStream(); + if (loadFromRawFork(*stream)) { + _baseFileName = filename; + return true; + } + delete stream; } // Fine, what about just the data fork? fsNode = path.getChild(filename); if (fsNode.exists() && !fsNode.isDirectory()) { + SeekableReadStream *stream = fsNode.createReadStream(); _baseFileName = filename; - if (isMacBinary(*fsNode.createReadStream())) { - loadFromMacBinary(*fsNode.createReadStream()); - } else { - _stream = fsNode.createReadStream(); + if (isMacBinary(*stream)) { + stream->seek(0, SEEK_SET); + if (loadFromMacBinary(*stream)) + return true; } + + stream->seek(0, SEEK_SET); + _stream = stream; return true; } @@ -313,7 +336,7 @@ bool MacResManager::load(Common::SeekableReadStream &stream) { debug(7, "got header: data %d [%d] map %d [%d]", _dataOffset, _dataLength, _mapOffset, _mapLength); - + _stream = &stream; readMap(); diff --git a/common/macresman.h b/common/macresman.h index 613c26625b0..c067b6d2b8b 100644 --- a/common/macresman.h +++ b/common/macresman.h @@ -45,7 +45,7 @@ class MacResManager { public: MacResManager(); ~MacResManager(); - + bool open(Common::String filename); bool open(Common::FSNode path, Common::String filename); void close(); @@ -53,7 +53,7 @@ public: bool hasDataFork(); bool hasResFork(); - bool isMacBinary(Common::SeekableReadStream &stream); + static bool isMacBinary(Common::SeekableReadStream &stream); /** * Read resource from the Mac Binary file @@ -76,7 +76,7 @@ public: bool getResForkMD5(char *md5str, uint32 length); Common::String getBaseFileName() { return _baseFileName; } - + /** * Convert cursor from crsr format to format suitable for feeding to CursorMan * @param data Pointer to the cursor data @@ -125,7 +125,7 @@ private: } _mode; void readMap(); - + struct ResMap { uint16 resAttr; uint16 typeOffset; @@ -148,7 +148,7 @@ private: }; typedef Resource *ResPtr; - + int32 _resForkOffset; uint32 _resForkSize;