diff options
-rw-r--r-- | common/unarj.cpp | 17 | ||||
-rw-r--r-- | common/unarj.h | 6 |
2 files changed, 21 insertions, 2 deletions
diff --git a/common/unarj.cpp b/common/unarj.cpp index 58f326c1ac..57673341f7 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -78,6 +78,7 @@ static uint32 GetCRC(byte *data, int len) { ArjFile::ArjFile() { InitCRC(); _isOpen = false; + _fallBack = false; } ArjFile::~ArjFile() { @@ -234,6 +235,15 @@ bool ArjFile::open(const Common::String &filename, AccessMode mode) { _isOpen = false; + if (_fallBack) { + _currArchive.open(filename); + if (_currArchive.isOpen()) { + _isOpen = true; + _uncompressed = &_currArchive; + return true; + } + } + if (!_fileMap.contains(filename)) return false; @@ -279,7 +289,12 @@ bool ArjFile::open(const Common::String &filename, AccessMode mode) { void ArjFile::close() { _isOpen = false; - delete _uncompressed; + if (_fallBack) { + _currArchive.close(); + } else { + delete _uncompressed; + } + _uncompressed = NULL; free(_uncompressedData); diff --git a/common/unarj.h b/common/unarj.h index 289ab52ad0..b015999671 100644 --- a/common/unarj.h +++ b/common/unarj.h @@ -106,6 +106,8 @@ public: ArjFile(); ~ArjFile(); + void enableFallback(bool val) { _fallBack = val; } + void registerArchive(const String &filename); bool open(const Common::String &filename, AccessMode mode = kFileReadMode); @@ -119,6 +121,8 @@ public: bool isOpen() { return _isOpen; } private: + bool _fallBack; + File _currArchive; Array<ArjHeader *> _headers; ArjFilesMap _fileMap; @@ -128,7 +132,7 @@ private: byte *_compressedData; MemoryWriteStream *_outstream; MemoryReadStream *_compressed; - MemoryReadStream *_uncompressed; + SeekableReadStream *_uncompressed; bool _isOpen; |