diff options
author | Denis Kasak | 2009-06-15 17:08:39 +0000 |
---|---|---|
committer | Denis Kasak | 2009-06-15 17:08:39 +0000 |
commit | 30ef3a122369ab3002b2e718934afea676a48fe7 (patch) | |
tree | a84fd84860ace0e8b7d3c8cc4a933c8e525c3dd6 /engines | |
parent | a8c784245c1b5a277fdea098ff19c4bd53aac70c (diff) | |
download | scummvm-rg350-30ef3a122369ab3002b2e718934afea676a48fe7.tar.gz scummvm-rg350-30ef3a122369ab3002b2e718934afea676a48fe7.tar.bz2 scummvm-rg350-30ef3a122369ab3002b2e718934afea676a48fe7.zip |
Added BArchive::isOpen() method. Modified DraciEngine::go() to use it. Updated BArchive docs.
svn-id: r41550
Diffstat (limited to 'engines')
-rw-r--r-- | engines/draci/barchive.cpp | 34 | ||||
-rw-r--r-- | engines/draci/barchive.h | 16 |
2 files changed, 39 insertions, 11 deletions
diff --git a/engines/draci/barchive.cpp b/engines/draci/barchive.cpp index df527221cd..4b9a1d9807 100644 --- a/engines/draci/barchive.cpp +++ b/engines/draci/barchive.cpp @@ -115,8 +115,11 @@ void BArchive::openDFW(const Common::String &path) { _files[i]._crc = 0; // Dummy value; not used in DFW archives } + // Indicate that the archive was successfully opened + _opened = true; + + // Cleanup delete[] table; - f.close(); } @@ -173,12 +176,17 @@ void BArchive::openArchive(const Common::String &path) { f.read(buf, 4); if (memcmp(buf, _magicNumber, 4) == 0) { debugC(2, kDraciArchiverDebugLevel, "Success"); + + // Indicate this archive is a BAR _isDFW = false; } else { debugC(2, kDraciArchiverDebugLevel, "Not a BAR archive"); debugCN(2, kDraciArchiverDebugLevel, "Retrying as DFW: "); f.close(); + + // Try to open as DFW openDFW(_path); + return; } @@ -203,25 +211,30 @@ void BArchive::openArchive(const Common::String &path) { uint32 fileOffset; fileOffset = reader.readUint32LE(); - f.seek(fileOffset); // Seek to next file in archive + f.seek(fileOffset); // Seek to next file in archive + _files[i]._compLength = f.readUint16LE(); // Compressed size // should be the same as uncompressed - _files[i]._length = f.readUint16LE(); // Original size - _files[i]._offset = fileOffset; + + _files[i]._length = f.readUint16LE(); // Original size + + _files[i]._offset = fileOffset; // Offset of file from start assert(f.readByte() == 0 && "Compression type flag is non-zero (file is compressed)"); - _files[i]._crc = f.readByte(); // CRC checksum of the file - _files[i]._data = NULL; // File data will be read in on demand - _files[i]._stopper = 0; // Dummy value; not used in BAR files, needed in DFW + _files[i]._crc = f.readByte(); // CRC checksum of the file + _files[i]._data = NULL; // File data will be read in on demand + _files[i]._stopper = 0; // Dummy value; not used in BAR files, needed in DFW } // Last footer item should be equal to footerOffset assert(reader.readUint32LE() == footerOffset && "Footer offset mismatch"); + + // Indicate that the archive has been successfully opened + _opened = true; delete[] footer; - f.close(); } @@ -232,7 +245,7 @@ void BArchive::openArchive(const Common::String &path) { * free up memory. */ void BArchive::closeArchive(void) { - if (!_files) { + if (!_opened) { return; } @@ -244,6 +257,7 @@ void BArchive::closeArchive(void) { delete[] _files; + _opened = false; _files = NULL; _fileCount = 0; } @@ -382,6 +396,8 @@ BAFile *BArchive::operator[](unsigned int i) const { } BAFile *file; + + // file will be NULL if something goes wrong if (_isDFW) { file = loadFileDFW(i); } else { diff --git a/engines/draci/barchive.h b/engines/draci/barchive.h index 0971375c7b..a53fb79ee1 100644 --- a/engines/draci/barchive.h +++ b/engines/draci/barchive.h @@ -51,14 +51,25 @@ struct BAFile { class BArchive { public: - BArchive() : _files(NULL), _fileCount(0) {} - BArchive(Common::String &path) : _files(NULL), _fileCount(0) { openArchive(path); } + BArchive() : _files(NULL), _fileCount(0), _opened(false) {} + + BArchive(Common::String &path) : + _files(NULL), _fileCount(0), _opened(false) { + openArchive(path); + } + ~BArchive() { closeArchive(); } void openArchive(const Common::String &path); void closeArchive(void); uint16 size() const { return _fileCount; } + /** + * Checks whether there is an archive opened. Should be called before reading + * from the archive to check whether openArchive() succeeded. + */ + bool isOpen() const { return _opened; } + BAFile *operator[](unsigned int i) const; private: @@ -74,6 +85,7 @@ private: BAFile *_files; //!< Internal array of files uint16 _fileCount; //!< Number of files in archive bool _isDFW; //!< True if the archive is in DFW format, false otherwise + bool _opened; //!< True if the archive is opened, false otherwise void openDFW(const Common::String &path); BAFile *loadFileDFW(unsigned int i) const; |