diff options
author | Strangerke | 2015-05-13 22:57:15 +0200 |
---|---|---|
committer | Strangerke | 2015-05-13 22:58:08 +0200 |
commit | fab0e75c292887254493f0efc6a5a40c851aba53 (patch) | |
tree | 2bf4e9eece09338e7b1e5385183919b49305e2f9 | |
parent | 6f263e5774f7f4f8877932bb136621ac9606d11e (diff) | |
download | scummvm-rg350-fab0e75c292887254493f0efc6a5a40c851aba53.tar.gz scummvm-rg350-fab0e75c292887254493f0efc6a5a40c851aba53.tar.bz2 scummvm-rg350-fab0e75c292887254493f0efc6a5a40c851aba53.zip |
SHERLOCK: Rework a bit Cache::load to use MKTAG, add support for compressed sub-files in Resources::load
-rw-r--r-- | engines/sherlock/resources.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/engines/sherlock/resources.cpp b/engines/sherlock/resources.cpp index f50f780195..e990013cb3 100644 --- a/engines/sherlock/resources.cpp +++ b/engines/sherlock/resources.cpp @@ -66,18 +66,15 @@ void Cache::load(const Common::String &name, Common::SeekableReadStream &stream) if (_resources.contains(name)) return; - // Check whether the file is compressed - const char LZW_HEADER[5] = { "LZV\x1a" }; - char header[5]; - stream.read(header, 5); - bool isCompressed = !strncmp(header, LZW_HEADER, 5); + int32 signature = stream.readUint32BE(); stream.seek(0); // Allocate a new cache entry _resources[name] = CacheEntry(); CacheEntry &cacheEntry = _resources[name]; - if (isCompressed) { + // Check whether the file is compressed + if (signature == MKTAG('L', 'Z', 'V', 26)) { // It's compressed, so decompress the file and store it's data in the cache entry Common::SeekableReadStream *decompressed = decompressLZ(stream); cacheEntry.resize(decompressed->size()); @@ -168,8 +165,19 @@ Common::SeekableReadStream *Resources::load(const Common::String &filename) { stream->seek(entry._offset); Common::SeekableReadStream *resStream = stream->readStream(entry._size); - delete stream; - return resStream; + // Check whether the file is compressed + if (resStream->readUint32BE() == MKTAG('L', 'Z', 'V', 26)) { + resStream->seek(0); + // It's compressed, so decompress the sub-file and return it + Common::SeekableReadStream *decompressed = decompressLZ(*resStream); + delete stream; + delete resStream; + return decompressed; + } else { + resStream->seek(0); + delete stream; + return resStream; + } } } |