2009-06-08 22:18:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/stream.h"
|
|
|
|
|
|
|
|
#include "draci/barchive.h"
|
|
|
|
#include "draci/draci.h"
|
|
|
|
|
|
|
|
namespace Draci {
|
|
|
|
|
|
|
|
const char BArchive::_magicNumber[] = "BAR!";
|
2009-06-15 03:48:16 +00:00
|
|
|
const char BArchive::_dfwMagicNumber[] = "BS";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Loads a DFW archive
|
|
|
|
* @param path Path to input file
|
|
|
|
*
|
|
|
|
* Tries to load the file as a DFW archive if opening as BAR fails. Should only be called
|
|
|
|
* from openArchive(). Only one of the game files appears to use this format (HRA.DFW)
|
|
|
|
* and this file is compressed using a simple run-length scheme.
|
|
|
|
*
|
|
|
|
* archive format: header
|
2009-09-30 10:45:14 +00:00
|
|
|
* index table
|
|
|
|
* file0, file1, ...
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
|
|
|
* header format: [uint16LE] file count
|
2009-09-30 10:45:14 +00:00
|
|
|
* [uint16LE] index table size
|
2009-09-30 16:04:21 +00:00
|
|
|
* [2 bytes] magic number "BS"
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
|
|
|
* index table format: entry0, entry1, ...
|
|
|
|
*
|
2009-09-30 16:04:21 +00:00
|
|
|
* entry<N> format: [uint16LE] compressed size (not including the 2 bytes for the
|
2009-09-30 10:45:14 +00:00
|
|
|
* "uncompressed size" field)
|
|
|
|
* [uint32LE] fileN offset from start of file
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
|
|
|
* file<N> format: [uint16LE] uncompressed size
|
2009-09-30 10:45:14 +00:00
|
|
|
* [uint16LE] compressed size (the same as in the index table entry)
|
|
|
|
* [byte] stopper mark (for run-length compression)
|
|
|
|
* [multiple bytes] compressed data
|
2009-06-15 03:48:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void BArchive::openDFW(const Common::String &path) {
|
|
|
|
byte *table;
|
|
|
|
uint16 tableSize;
|
|
|
|
byte buf[2];
|
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.open(path);
|
|
|
|
if (!_f.isOpen()) {
|
2009-06-15 03:48:16 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Error opening file");
|
|
|
|
return;
|
|
|
|
}
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_fileCount = _f.readUint16LE();
|
|
|
|
tableSize = _f.readUint16LE();
|
2009-06-15 03:48:16 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.read(buf, 2);
|
2009-06-15 03:48:16 +00:00
|
|
|
if (memcmp(buf, _dfwMagicNumber, 2) == 0) {
|
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Success");
|
|
|
|
_isDFW = true;
|
|
|
|
} else {
|
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Not a DFW archive");
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.close();
|
2009-06-15 03:48:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Archive info (DFW): %d files", _fileCount);
|
|
|
|
|
|
|
|
// Read in index table
|
|
|
|
table = new byte[tableSize];
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.read(table, tableSize);
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
// Read in file headers, but do not read the actual data yet
|
|
|
|
// The data will be read on demand to save memory
|
|
|
|
_files = new BAFile[_fileCount];
|
|
|
|
Common::MemoryReadStream tableReader(table, tableSize);
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint i = 0; i < _fileCount; ++i) {
|
2009-06-15 03:48:16 +00:00
|
|
|
_files[i]._compLength = tableReader.readUint16LE();
|
|
|
|
_files[i]._offset = tableReader.readUint32LE();
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
// Seek to the current file
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.seek(_files[i]._offset);
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_files[i]._length = _f.readUint16LE(); // Read in uncompressed length
|
|
|
|
_f.readUint16LE(); // Compressed length again (already read from the index table)
|
|
|
|
_files[i]._stopper = _f.readByte();
|
2009-06-15 03:48:16 +00:00
|
|
|
|
|
|
|
_files[i]._data = NULL; // File data will be read in on demand
|
|
|
|
_files[i]._crc = 0; // Dummy value; not used in DFW archives
|
|
|
|
}
|
|
|
|
|
2009-06-15 17:08:39 +00:00
|
|
|
// Indicate that the archive was successfully opened
|
|
|
|
_opened = true;
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-15 17:08:39 +00:00
|
|
|
// Cleanup
|
2009-06-15 03:48:16 +00:00
|
|
|
delete[] table;
|
2009-09-30 10:45:14 +00:00
|
|
|
}
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief BArchive open method
|
|
|
|
* @param path Path to input file
|
|
|
|
*
|
|
|
|
* Opens a BAR (Bob's Archiver) archive, which is the game's archiving format.
|
2009-06-15 03:48:16 +00:00
|
|
|
* BAR archives have a .DFW file extension, due to a historical interface.
|
2009-09-30 16:04:21 +00:00
|
|
|
*
|
|
|
|
* archive format: header,
|
2009-06-08 22:18:52 +00:00
|
|
|
* file0, file1, ...
|
|
|
|
* footer
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
2009-06-08 22:18:52 +00:00
|
|
|
* header format: [4 bytes] magic number "BAR!"
|
|
|
|
* [uint16LE] file count (number of archived streams),
|
|
|
|
* [uint32LE] footer offset from start of file
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
2009-06-08 22:18:52 +00:00
|
|
|
* file<N> format: [2 bytes] compressed length
|
|
|
|
* [2 bytes] original length
|
|
|
|
* [1 byte] compression type
|
|
|
|
* [1 byte] CRC
|
2009-09-30 10:45:14 +00:00
|
|
|
* [multiple bytes] actual data
|
2009-06-15 03:48:16 +00:00
|
|
|
*
|
2009-09-30 16:04:21 +00:00
|
|
|
* footer format: [array of uint32LE] offsets of individual files from start of archive
|
2009-06-08 22:18:52 +00:00
|
|
|
* (last entry is footer offset again)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void BArchive::openArchive(const Common::String &path) {
|
|
|
|
byte buf[4];
|
|
|
|
byte *footer;
|
|
|
|
uint32 footerOffset, footerSize;
|
|
|
|
|
|
|
|
// Close previously opened archive (if any)
|
|
|
|
closeArchive();
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Loading archive %s: ", path.c_str());
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.open(path);
|
|
|
|
if (_f.isOpen()) {
|
2009-06-10 18:18:09 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Success");
|
2009-06-08 22:18:52 +00:00
|
|
|
} else {
|
2009-06-10 18:18:09 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Error");
|
2009-06-08 22:18:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save path for reading in files later on
|
|
|
|
_path = path;
|
|
|
|
|
|
|
|
// Read archive header
|
2009-06-15 03:48:16 +00:00
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Checking for BAR magic number: ");
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.read(buf, 4);
|
2009-06-08 22:18:52 +00:00
|
|
|
if (memcmp(buf, _magicNumber, 4) == 0) {
|
2009-06-10 18:18:09 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Success");
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-09-30 10:45:14 +00:00
|
|
|
// Indicate this archive is a BAR
|
2009-06-15 03:48:16 +00:00
|
|
|
_isDFW = false;
|
2009-06-08 22:18:52 +00:00
|
|
|
} else {
|
2009-06-15 03:48:16 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Not a BAR archive");
|
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Retrying as DFW: ");
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.close();
|
2009-06-15 17:08:39 +00:00
|
|
|
|
|
|
|
// Try to open as DFW
|
2009-06-15 03:48:16 +00:00
|
|
|
openDFW(_path);
|
2009-06-15 17:08:39 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_fileCount = _f.readUint16LE();
|
|
|
|
footerOffset = _f.readUint32LE();
|
|
|
|
footerSize = _f.size() - footerOffset;
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-10 18:18:09 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Archive info: %d files, %d data bytes",
|
2009-06-08 22:18:52 +00:00
|
|
|
_fileCount, footerOffset - _archiveHeaderSize);
|
|
|
|
|
2009-09-30 10:45:14 +00:00
|
|
|
// Read in footer
|
|
|
|
footer = new byte[footerSize];
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.seek(footerOffset);
|
|
|
|
_f.read(footer, footerSize);
|
2009-06-08 22:18:52 +00:00
|
|
|
Common::MemoryReadStream reader(footer, footerSize);
|
|
|
|
|
|
|
|
// Read in file headers, but do not read the actual data yet
|
|
|
|
// The data will be read on demand to save memory
|
|
|
|
_files = new BAFile[_fileCount];
|
|
|
|
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint i = 0; i < _fileCount; i++) {
|
|
|
|
uint32 fileOffset;
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
fileOffset = reader.readUint32LE();
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.seek(fileOffset); // Seek to next file in archive
|
2009-06-15 17:08:39 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_files[i]._compLength = _f.readUint16LE(); // Compressed size
|
2009-06-15 03:48:16 +00:00
|
|
|
// should be the same as uncompressed
|
2009-06-15 17:08:39 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_files[i]._length = _f.readUint16LE(); // Original size
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-15 17:08:39 +00:00
|
|
|
_files[i]._offset = fileOffset; // Offset of file from start
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
assert(_f.readByte() == 0 &&
|
2009-06-08 22:18:52 +00:00
|
|
|
"Compression type flag is non-zero (file is compressed)");
|
|
|
|
|
2009-10-22 06:05:34 +00:00
|
|
|
_files[i]._crc = _f.readByte(); // CRC checksum of the file
|
2009-06-15 17:08:39 +00:00
|
|
|
_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
|
2009-09-30 10:45:14 +00:00
|
|
|
}
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
// Last footer item should be equal to footerOffset
|
|
|
|
assert(reader.readUint32LE() == footerOffset && "Footer offset mismatch");
|
2009-06-15 17:08:39 +00:00
|
|
|
|
|
|
|
// Indicate that the archive has been successfully opened
|
2009-09-30 16:04:21 +00:00
|
|
|
_opened = true;
|
|
|
|
|
2009-06-15 03:53:03 +00:00
|
|
|
delete[] footer;
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief BArchive close method
|
|
|
|
*
|
|
|
|
* Closes the currently opened archive. It can be called explicitly to
|
|
|
|
* free up memory.
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
void BArchive::closeArchive() {
|
2009-06-15 17:08:39 +00:00
|
|
|
if (!_opened) {
|
2009-06-08 22:18:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint i = 0; i < _fileCount; ++i) {
|
2009-06-08 22:18:52 +00:00
|
|
|
if (_files[i]._data) {
|
2009-09-30 16:04:21 +00:00
|
|
|
delete[] _files[i]._data;
|
2009-06-08 22:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] _files;
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.close();
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-06-15 17:08:39 +00:00
|
|
|
_opened = false;
|
2009-06-08 22:18:52 +00:00
|
|
|
_files = NULL;
|
|
|
|
_fileCount = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
/**
|
|
|
|
* @brief On-demand BAR file loader
|
|
|
|
* @param i Index of file inside an archive
|
|
|
|
* @return Pointer to a BAFile coresponding to the opened file or NULL (on failure)
|
|
|
|
*
|
2009-09-30 16:04:21 +00:00
|
|
|
* Loads individual BAR files from an archive to memory on demand.
|
2009-10-11 23:01:59 +00:00
|
|
|
* Should not be called directly.
|
2009-06-15 03:48:16 +00:00
|
|
|
*/
|
2009-10-11 22:30:40 +00:00
|
|
|
BAFile *BArchive::loadFileBAR(uint i) {
|
2009-06-08 22:18:52 +00:00
|
|
|
// Else open archive and read in requested file
|
2009-10-22 06:05:34 +00:00
|
|
|
if (!_f.isOpen()) {
|
2009-06-10 18:18:09 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Error");
|
2009-06-08 22:18:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read in the file (without the file header)
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.seek(_files[i]._offset + _fileHeaderSize);
|
2009-06-08 22:18:52 +00:00
|
|
|
_files[i]._data = new byte[_files[i]._length];
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.read(_files[i]._data, _files[i]._length);
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
// Calculate CRC
|
|
|
|
byte tmp = 0;
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint j = 0; j < _files[i]._length; j++) {
|
2009-06-08 22:18:52 +00:00
|
|
|
tmp ^= _files[i]._data[j];
|
|
|
|
}
|
2009-09-30 16:04:21 +00:00
|
|
|
|
|
|
|
debugC(3, kDraciArchiverDebugLevel, "Cached file %d from archive %s",
|
2009-06-10 18:18:09 +00:00
|
|
|
i, _path.c_str());
|
2009-06-08 22:18:52 +00:00
|
|
|
assert(tmp == _files[i]._crc && "CRC checksum mismatch");
|
|
|
|
|
|
|
|
return _files + i;
|
|
|
|
}
|
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
/**
|
|
|
|
* @brief On-demand DFW file loader
|
|
|
|
* @param i Index of file inside an archive
|
|
|
|
* @return Pointer to a BAFile coresponding to the opened file or NULL (on failure)
|
|
|
|
*
|
2009-09-30 16:04:21 +00:00
|
|
|
* Loads individual DFW files from an archive to memory on demand.
|
2009-10-11 23:01:59 +00:00
|
|
|
* Should not be called directly.
|
2009-06-15 03:48:16 +00:00
|
|
|
*/
|
2009-10-11 22:30:40 +00:00
|
|
|
BAFile *BArchive::loadFileDFW(uint i) {
|
2009-06-15 03:48:16 +00:00
|
|
|
byte *buf;
|
|
|
|
|
|
|
|
// Else open archive and read in requested file
|
2009-10-22 06:05:34 +00:00
|
|
|
if (!_f.isOpen()) {
|
2009-06-15 03:48:16 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Error");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek to raw data of the file
|
|
|
|
// Five bytes are for the header (uncompressed and compressed length, stopper mark)
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.seek(_files[i]._offset + 5);
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
// Since we are seeking directly to raw data, we subtract 3 bytes from the length
|
|
|
|
// (to take account the compressed length and stopper mark)
|
|
|
|
uint16 compressedLength = _files[i]._compLength - 3;
|
|
|
|
uint16 uncompressedLength = _files[i]._length;
|
|
|
|
|
2009-09-30 16:04:21 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel,
|
|
|
|
"File info (DFW): uncompressed %d bytes, compressed %d bytes",
|
2009-06-15 03:48:16 +00:00
|
|
|
uncompressedLength, compressedLength);
|
|
|
|
|
|
|
|
// Allocate a buffer for the file data
|
|
|
|
buf = new byte[compressedLength];
|
|
|
|
|
|
|
|
// Read in file data into the buffer
|
2009-10-22 06:05:34 +00:00
|
|
|
_f.read(buf, compressedLength);
|
2009-06-15 03:48:16 +00:00
|
|
|
|
|
|
|
// Allocate the space for the uncompressed file
|
2009-09-30 10:45:14 +00:00
|
|
|
byte *dst;
|
2009-06-15 03:48:16 +00:00
|
|
|
dst = _files[i]._data = new byte[uncompressedLength];
|
|
|
|
|
|
|
|
Common::MemoryReadStream data(buf, compressedLength);
|
|
|
|
|
|
|
|
// Uncompress file
|
|
|
|
byte current, what;
|
|
|
|
byte stopper = _files[i]._stopper;
|
2009-09-30 10:45:14 +00:00
|
|
|
uint repeat;
|
|
|
|
uint len = 0; // Sanity check (counts uncompressed bytes)
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
current = data.readByte(); // Read initial byte
|
|
|
|
while (!data.eos()) {
|
|
|
|
if (current != stopper) {
|
|
|
|
*dst++ = current;
|
|
|
|
++len;
|
|
|
|
} else {
|
2009-09-30 10:45:14 +00:00
|
|
|
// Inflate block
|
2009-06-15 03:48:16 +00:00
|
|
|
repeat = data.readByte();
|
|
|
|
what = data.readByte();
|
|
|
|
len += repeat;
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint j = 0; j < repeat; ++j) {
|
2009-06-15 03:48:16 +00:00
|
|
|
*dst++ = what;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current = data.readByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(len == _files[i]._length && "Uncompressed file not of the expected length");
|
|
|
|
|
2009-07-17 01:05:13 +00:00
|
|
|
delete[] buf;
|
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
return _files + i;
|
|
|
|
}
|
2009-07-02 10:39:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the cache of the open files inside the archive without closing it.
|
|
|
|
* If the files are subsequently accessed, they are read from the disk.
|
|
|
|
*/
|
|
|
|
void BArchive::clearCache() {
|
|
|
|
// Delete all cached data
|
2009-09-30 10:45:14 +00:00
|
|
|
for (uint i = 0; i < _fileCount; ++i) {
|
2009-07-17 01:05:13 +00:00
|
|
|
_files[i].close();
|
2009-07-02 10:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-15 03:48:16 +00:00
|
|
|
|
2009-10-11 22:30:40 +00:00
|
|
|
const BAFile *BArchive::getFile(uint i) {
|
2009-06-15 03:48:16 +00:00
|
|
|
// Check whether requested file exists
|
|
|
|
if (i >= _fileCount) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-30 16:04:21 +00:00
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Accessing file %d from archive %s... ",
|
2009-06-15 03:48:16 +00:00
|
|
|
i, _path.c_str());
|
|
|
|
|
|
|
|
// Check if file has already been opened and return that
|
|
|
|
if (_files[i]._data) {
|
2009-09-30 10:45:14 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Success");
|
2009-06-15 03:48:16 +00:00
|
|
|
return _files + i;
|
|
|
|
}
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-06-15 03:48:16 +00:00
|
|
|
BAFile *file;
|
2009-09-30 10:45:14 +00:00
|
|
|
|
2009-06-15 17:08:39 +00:00
|
|
|
// file will be NULL if something goes wrong
|
2009-06-15 03:48:16 +00:00
|
|
|
if (_isDFW) {
|
|
|
|
file = loadFileDFW(i);
|
|
|
|
} else {
|
|
|
|
file = loadFileBAR(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
} // End of namespace Draci
|