diff options
author | Eugene Sandulenko | 2010-05-18 10:39:08 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-05-18 10:39:08 +0000 |
commit | 15986b81c2f30a52d2b7ebc90ce0eff9fe173443 (patch) | |
tree | f21a52044ce7d1b4522e8f19f29ddb15464f8de1 /common/macresman.cpp | |
parent | 7ab8f6e25bb4904140116c4a484b5a23c44d6bf5 (diff) | |
download | scummvm-rg350-15986b81c2f30a52d2b7ebc90ce0eff9fe173443.tar.gz scummvm-rg350-15986b81c2f30a52d2b7ebc90ce0eff9fe173443.tar.bz2 scummvm-rg350-15986b81c2f30a52d2b7ebc90ce0eff9fe173443.zip |
Added getBaseFileName() method and enhanced open() with trying macbinary format in plain files
svn-id: r49074
Diffstat (limited to 'common/macresman.cpp')
-rw-r--r-- | common/macresman.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/common/macresman.cpp b/common/macresman.cpp index 1daa55e5bf..cb3f1c5b8a 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -135,7 +135,13 @@ bool MacResManager::open(Common::String filename) { // Fine, what about just the data fork? if (file->open(filename)) { _baseFileName = filename; - _stream = file; + + if (isMacBinary(*file)) { + file->seek(0, SEEK_SET); + loadFromMacBinary(*file); + } else { + _stream = file; + } return true; } @@ -184,7 +190,12 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) { fsNode = path.getChild(filename); if (fsNode.exists() && !fsNode.isDirectory()) { _baseFileName = filename; - _stream = fsNode.createReadStream(); + + if (isMacBinary(*fsNode.createReadStream())) { + loadFromMacBinary(*fsNode.createReadStream()); + } else { + _stream = fsNode.createReadStream(); + } return true; } @@ -217,6 +228,34 @@ bool MacResManager::loadFromAppleDouble(Common::SeekableReadStream &stream) { return false; } +bool MacResManager::isMacBinary(Common::SeekableReadStream &stream) { + byte infoHeader[MBI_INFOHDR]; + int resForkOffset = -1; + + stream.read(infoHeader, MBI_INFOHDR); + + if (infoHeader[MBI_ZERO1] == 0 && infoHeader[MBI_ZERO2] == 0 && + infoHeader[MBI_ZERO3] == 0 && infoHeader[MBI_NAMELEN] <= MAXNAMELEN) { + + // Pull out fork lengths + uint32 dataSize = READ_BE_UINT32(infoHeader + MBI_DFLEN); + uint32 rsrcSize = READ_BE_UINT32(infoHeader + MBI_RFLEN); + + uint32 dataSizePad = (((dataSize + 127) >> 7) << 7); + uint32 rsrcSizePad = (((rsrcSize + 127) >> 7) << 7); + + // Length check + if (MBI_INFOHDR + dataSizePad + rsrcSizePad == (uint32)stream.size()) { + resForkOffset = MBI_INFOHDR + dataSizePad; + } + } + + if (resForkOffset < 0) + return false; + + return true; +} + bool MacResManager::loadFromMacBinary(Common::SeekableReadStream &stream) { byte infoHeader[MBI_INFOHDR]; stream.read(infoHeader, MBI_INFOHDR); |