SHERLOCK: Fix decompression of resources from library files

This commit is contained in:
Paul Gilbert 2015-05-17 14:01:35 -04:00
parent 7cd4d15610
commit 2abb5f1977
2 changed files with 21 additions and 13 deletions

View File

@ -164,20 +164,10 @@ Common::SeekableReadStream *Resources::load(const Common::String &filename) {
stream->seek(entry._offset);
Common::SeekableReadStream *resStream = stream->readStream(entry._size);
decompressIfNecessary(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;
}
delete stream;
return resStream;
}
}
@ -188,10 +178,25 @@ Common::SeekableReadStream *Resources::load(const Common::String &filename) {
Common::SeekableReadStream *stream = f.readStream(f.size());
f.close();
decompressIfNecessary(stream);
return stream;
}
/**
* Checks the passed stream, and if is compressed, deletes it and replaces it with it's uncompressed data
*/
void Resources::decompressIfNecessary(Common::SeekableReadStream *&stream) {
bool isCompressed = stream->readUint32BE() == MKTAG('L', 'Z', 'V', 26);
stream->seek(-4, SEEK_CUR);
if (isCompressed) {
Common::SeekableReadStream *newStream = decompressLZ(*stream);
delete stream;
stream = newStream;
}
}
/**
* Loads a specific resource from a given library file
*/
@ -207,6 +212,7 @@ Common::SeekableReadStream *Resources::load(const Common::String &filename, cons
LibraryEntry &entry = _indexes[libraryFile][filename];
libStream->seek(entry._offset);
Common::SeekableReadStream *stream = libStream->readStream(entry._size);
decompressIfNecessary(stream);
delete libStream;
return stream;

View File

@ -81,6 +81,8 @@ public:
void addToCache(const Common::String &filename, Common::SeekableReadStream &stream);
bool isInCache(const Common::String &filename) const { return _cache.isCached(filename); }
void decompressIfNecessary(Common::SeekableReadStream *&stream);
Common::SeekableReadStream *load(const Common::String &filename);
Common::SeekableReadStream *load(const Common::String &filename, const Common::String &libraryFile);