diff options
author | Filippos Karapetis | 2013-11-02 19:19:00 +0200 |
---|---|---|
committer | Filippos Karapetis | 2013-11-02 19:19:26 +0200 |
commit | 732fb69b1cc3a5022d7ed96eb83b84d2043c4240 (patch) | |
tree | 9b76e19bb89f2afc7c0103f3b95a49c9f7771b97 | |
parent | 16a2a0babaacf2e19f993465c4c676f0d36e73fc (diff) | |
download | scummvm-rg350-732fb69b1cc3a5022d7ed96eb83b84d2043c4240.tar.gz scummvm-rg350-732fb69b1cc3a5022d7ed96eb83b84d2043c4240.tar.bz2 scummvm-rg350-732fb69b1cc3a5022d7ed96eb83b84d2043c4240.zip |
COMMON: Reenable SEEK_END seeking in GZipReadStream()
This is needed by the "Mirage" Wintermute game.
Vorbis can do backward seeking, thus we need to enable this for ZIP
streams. Since this can be a potentially slow operation, we throw a
warning (once per stream) when it occurs. Originally, SEEK_END seeks
in GZipReadStream were disabled by commit 9138128f. Refer to patch
#2050337 for more information.
-rw-r--r-- | common/zlib.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/common/zlib.cpp b/common/zlib.cpp index 920338e57e..1c7e8437fe 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -27,6 +27,7 @@ #include "common/ptr.h" #include "common/util.h" #include "common/stream.h" +#include "common/textconsole.h" #if defined(USE_ZLIB) #ifdef __SYMBIAN32__ @@ -158,10 +159,11 @@ protected: uint32 _pos; uint32 _origSize; bool _eos; + bool _shownBackwardSeekingWarning; public: - GZipReadStream(SeekableReadStream *w, uint32 knownSize = 0) : _wrapped(w), _stream() { + GZipReadStream(SeekableReadStream *w, uint32 knownSize = 0) : _wrapped(w), _stream(), _shownBackwardSeekingWarning(false) { assert(w != 0); // Verify file header is correct @@ -241,13 +243,17 @@ public: } bool seek(int32 offset, int whence = SEEK_SET) { int32 newPos = 0; - assert(whence != SEEK_END); // SEEK_END not supported switch (whence) { case SEEK_SET: newPos = offset; break; case SEEK_CUR: newPos = _pos + offset; + break; + case SEEK_END: + // NOTE: This can be an expensive operation (see below). + newPos = size() - offset; + break; } assert(newPos >= 0); @@ -256,9 +262,15 @@ public: // To search backward, we have to restart the whole decompression // from the start of the file. A rather wasteful operation, best // to avoid it. :/ -#if DEBUG - warning("Backward seeking in GZipReadStream detected"); -#endif + + if (!_shownBackwardSeekingWarning) { + // We only throw this warning once per stream, to avoid + // getting the console swarmed with warnings when consecutive + // seeks are made. + warning("Backward seeking in GZipReadStream detected"); + _shownBackwardSeekingWarning = true; + } + _pos = 0; _wrapped->seek(0, SEEK_SET); _zlibErr = inflateReset(&_stream); |