ScummVM API documentation
barchive.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef DRACI_BARCHIVE_H
23 #define DRACI_BARCHIVE_H
24 
25 #include "common/str.h"
26 #include "common/file.h"
27 
28 namespace Draci {
29 
33 struct BAFile {
34  uint _compLength;
35  uint _length;
36  uint32 _offset;
37  byte *_data;
38  byte _crc;
39  byte _stopper;
40 
42  void close() {
43  delete[] _data;
44  _data = NULL;
45  }
46 };
47 
48 class BArchive {
49 public:
50  BArchive() : _files(NULL), _fileCount(0), _opened(false) {}
51 
52  BArchive(const Common::Path &path) :
53  _files(NULL), _fileCount(0), _opened(false) {
54  openArchive(path);
55  }
56 
57  ~BArchive() { closeArchive(); }
58 
59  void openArchive(const Common::Path &path);
60  void closeArchive();
61  uint size() const { return _fileCount; }
62 
67  bool isOpen() const { return _opened; }
68 
69  void clearCache();
70 
71  const BAFile *getFile(uint i);
72 
73 private:
74  // Archive header data
75  static const char _magicNumber[];
76  static const char _dfwMagicNumber[];
77  static const uint _archiveHeaderSize = 10;
78 
79  // File stream header data
80  static const uint _fileHeaderSize = 6;
81 
82  Common::Path _path;
83  BAFile *_files;
84  uint _fileCount;
85  bool _isDFW;
86  bool _opened;
87  Common::File _f;
88 
89  void openDFW(const Common::Path &path);
90  BAFile *loadFileDFW(uint i);
91  BAFile *loadFileBAR(uint i);
92 };
93 
94 } // End of namespace Draci
95 
96 #endif // DRACI_BARCHIVE_H
byte _stopper
Not used in BAR files, needed for DFW.
Definition: barchive.h:39
Definition: path.h:52
Definition: barchive.h:33
Definition: file.h:47
uint32 _offset
Offset of file inside archive.
Definition: barchive.h:36
uint _compLength
Compressed length (the same as _length if the file is uncompressed)
Definition: barchive.h:34
Definition: barchive.h:48
Definition: animation.h:30
bool isOpen() const
Definition: barchive.h:67
uint _length
Uncompressed length.
Definition: barchive.h:35
void close()
Definition: barchive.h:42