aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2015-05-17 14:01:35 -0400
committerPaul Gilbert2015-05-17 14:01:35 -0400
commit2abb5f19772125ec5b91619e39ffd2fd4b733641 (patch)
tree9cf2a7a2191baa104e5036c7cf4f432a5e80071d
parent7cd4d1561032104657544d3deda9aada5c06da45 (diff)
downloadscummvm-rg350-2abb5f19772125ec5b91619e39ffd2fd4b733641.tar.gz
scummvm-rg350-2abb5f19772125ec5b91619e39ffd2fd4b733641.tar.bz2
scummvm-rg350-2abb5f19772125ec5b91619e39ffd2fd4b733641.zip
SHERLOCK: Fix decompression of resources from library files
-rw-r--r--engines/sherlock/resources.cpp32
-rw-r--r--engines/sherlock/resources.h2
2 files changed, 21 insertions, 13 deletions
diff --git a/engines/sherlock/resources.cpp b/engines/sherlock/resources.cpp
index b5f4f5f6dd..f6fbded9b1 100644
--- a/engines/sherlock/resources.cpp
+++ b/engines/sherlock/resources.cpp
@@ -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,11 +178,26 @@ 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
*/
Common::SeekableReadStream *Resources::load(const Common::String &filename, const Common::String &libraryFile) {
@@ -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;
diff --git a/engines/sherlock/resources.h b/engines/sherlock/resources.h
index d5e83a1745..6bb0682f8d 100644
--- a/engines/sherlock/resources.h
+++ b/engines/sherlock/resources.h
@@ -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);