mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 22:28:10 +00:00
SHERLOCK: Fix decompression of resources from library files
This commit is contained in:
parent
7cd4d15610
commit
2abb5f1977
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user