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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-06-17 05:18:48 +00:00
|
|
|
#ifndef DRACI_BARCHIVE_H
|
|
|
|
#define DRACI_BARCHIVE_H
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
#include "common/str.h"
|
2009-10-22 06:05:34 +00:00
|
|
|
#include "common/file.h"
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
namespace Draci {
|
|
|
|
|
|
|
|
/**
|
2009-06-12 09:45:12 +00:00
|
|
|
* Represents individual files inside the archive.
|
2009-06-08 22:18:52 +00:00
|
|
|
*/
|
|
|
|
struct BAFile {
|
2009-10-08 21:28:57 +00:00
|
|
|
uint _compLength; ///< Compressed length (the same as _length if the file is uncompressed)
|
|
|
|
uint _length; ///< Uncompressed length
|
|
|
|
uint32 _offset; ///< Offset of file inside archive
|
2009-06-08 22:18:52 +00:00
|
|
|
byte *_data;
|
|
|
|
byte _crc;
|
2009-10-08 21:28:57 +00:00
|
|
|
byte _stopper; ///< Not used in BAR files, needed for DFW
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-06-12 09:45:12 +00:00
|
|
|
/** Releases the file data (for memory considerations) */
|
2009-11-02 21:54:57 +00:00
|
|
|
void close() {
|
2009-07-07 21:46:34 +00:00
|
|
|
delete[] _data;
|
2009-06-08 22:18:52 +00:00
|
|
|
_data = NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BArchive {
|
|
|
|
public:
|
2009-06-15 17:08:39 +00:00
|
|
|
BArchive() : _files(NULL), _fileCount(0), _opened(false) {}
|
|
|
|
|
2009-07-02 16:15:32 +00:00
|
|
|
BArchive(const Common::String &path) :
|
2009-09-30 16:04:21 +00:00
|
|
|
_files(NULL), _fileCount(0), _opened(false) {
|
|
|
|
openArchive(path);
|
2009-06-15 17:08:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
~BArchive() { closeArchive(); }
|
|
|
|
|
|
|
|
void openArchive(const Common::String &path);
|
2009-11-02 21:54:57 +00:00
|
|
|
void closeArchive();
|
2009-08-02 05:11:15 +00:00
|
|
|
uint size() const { return _fileCount; }
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-09-30 16:04:21 +00:00
|
|
|
/**
|
2009-06-15 17:08:39 +00:00
|
|
|
* Checks whether there is an archive opened. Should be called before reading
|
|
|
|
* from the archive to check whether openArchive() succeeded.
|
2009-09-30 10:45:14 +00:00
|
|
|
*/
|
2009-06-15 17:08:39 +00:00
|
|
|
bool isOpen() const { return _opened; }
|
|
|
|
|
2009-07-02 10:39:51 +00:00
|
|
|
void clearCache();
|
|
|
|
|
2009-10-11 22:30:40 +00:00
|
|
|
const BAFile *getFile(uint i);
|
2009-06-08 22:18:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Archive header data
|
|
|
|
static const char _magicNumber[];
|
2009-06-15 03:48:16 +00:00
|
|
|
static const char _dfwMagicNumber[];
|
2009-09-30 10:45:14 +00:00
|
|
|
static const uint _archiveHeaderSize = 10;
|
2009-09-30 16:04:21 +00:00
|
|
|
|
2009-06-08 22:18:52 +00:00
|
|
|
// File stream header data
|
2009-09-30 10:45:14 +00:00
|
|
|
static const uint _fileHeaderSize = 6;
|
2009-06-08 22:18:52 +00:00
|
|
|
|
2009-10-08 21:28:57 +00:00
|
|
|
Common::String _path; ///< Path to file
|
|
|
|
BAFile *_files; ///< Internal array of files
|
|
|
|
uint _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
|
2009-10-22 06:05:34 +00:00
|
|
|
Common::File _f; ///< Opened file handle
|
2009-06-15 03:48:16 +00:00
|
|
|
|
|
|
|
void openDFW(const Common::String &path);
|
2009-10-11 22:30:40 +00:00
|
|
|
BAFile *loadFileDFW(uint i);
|
|
|
|
BAFile *loadFileBAR(uint i);
|
2009-06-08 22:18:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Draci
|
|
|
|
|
2009-06-17 05:18:48 +00:00
|
|
|
#endif // DRACI_BARCHIVE_H
|