ScummVM API documentation
dat_file.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BOFLIB_DAT_FILE_H
24 #define BAGEL_BOFLIB_DAT_FILE_H
25 
26 #include "common/serializer.h"
27 #include "bagel/boflib/file.h"
28 
29 namespace Bagel {
30 
31 #define CDF_NOFLAGS 0x00000000
32 #define CDF_READONLY CBF_READONLY // Open for Read-only access
33 #define CDF_OVERWRITE CBF_OVERWRITE // *Overwrite any existing data-file
34 #define CDF_SHARED CBF_SHARED // *Open for Shared access
35 #define CDF_CREATE CBF_CREATE // *Create new file if not exist
36 #define CDF_SAVEFILE CBF_SAVEFILE
37 
38 #define CDF_MEMORY 0x00010000 // *header/footer should stay in memory
39 #define CDF_ENCRYPT 0x00020000 // Specifies if data should use encryption
40 #define CDF_KEEPOPEN 0x00040000 // File should be kept open after construction
41 #define CDF_COMPRESSED 0x00080000 // *Specifies if data should be compressed
42 // * = indicates feature not yet implemented
43 
44 #define CDF_DEFAULT (CDF_MEMORY | CDF_ENCRYPT | CDF_SHARED | CDF_KEEPOPEN | CDF_READONLY)
45 
46 #define MAX_PW_LEN 32 // Max Password length
47 
48 struct HeaderRec {
49 public:
50  int32 _lOffset;
51  int32 _lLength;
52  uint32 _lCrc;
53  uint32 _lKey;
54 
55  void synchronize(Common::Serializer &s);
56  static int size() { return 16; }
57 };
58 
59 struct HeadInfo {
60  int32 _lNumRecs; // Number of records in this file
61  int32 _lAddress; // starting address of footer
62  uint32 _lFlags; // contains flags for this file
63  uint32 _lFootCrc; // CRC of the footer
64 
65  void synchronize(Common::Serializer &s);
66  static int size() { return 16; }
67 };
68 
69 class CBofDataFile : public CBofFile {
70 private:
71  char _szPassWord[MAX_PW_LEN];
72  int32 _lHeaderLength = 0;
73  int32 _lHeaderStart = 0;
74  int32 _lNumRecs = 0;
75  HeaderRec *_pHeader = nullptr;
76 
77  bool _bHeaderDirty;
78 
79 protected:
84  ErrorCode readHeader();
85 
90  ErrorCode writeHeader();
91 
92 public:
96  CBofDataFile();
97 
101  virtual ~CBofDataFile();
102 
109  ErrorCode setFile(const char *pszFileName, uint32 lFlags);
110 
115  ErrorCode releaseFile();
116 
122  int32 getRecSize(int32 lRecNum);
123  int32 getNumberOfRecs() const {
124  return _lNumRecs;
125  }
126 
131  int32 getMaxRecSize() const;
132 
137  ErrorCode open();
138 
143  ErrorCode close() override;
144 
149  ErrorCode create();
150 
157  ErrorCode readRecord(int32 lRecNum, void *pBuf);
158 
164  ErrorCode readFromFile(int32 lRecNum, void *pBuf, int32 lBytes);
165 
175  ErrorCode writeRecord(int32 lRecNum, void *pBuf, int32 lSize = -1, bool bUpdateHeader = false, uint32 lKey = 0xFFFFFFFF);
176 
182  ErrorCode verifyRecord(int32 lRecNum);
183 
188  ErrorCode verifyAllRecords();
189 
198  ErrorCode addRecord(void *pBuf, int32 lLength, bool bUpdateHeader = false, uint32 lKey = 0xFFFFFFFF);
199 
205  int32 findRecord(uint32 lKey);
206 
211  void setPassword(const char *pszPassword);
212  const char *getPassword() const {
213  return _szPassWord;
214  }
215 
222  ErrorCode read(void *pDestBuf, int32 lBytes) override;
223  ErrorCode read(HeaderRec &rec);
224  ErrorCode read(HeadInfo &rec);
225 
232  ErrorCode write(const void *pSrcBuf, int32 lBytes) override;
233  ErrorCode write(HeaderRec &rec);
234  ErrorCode write(HeadInfo &rec);
235 };
236 
237 } // namespace Bagel
238 
239 #endif
Definition: dat_file.h:69
Definition: serializer.h:79
Definition: file.h:98
Definition: bagel.h:31
Definition: dat_file.h:48
Definition: dat_file.h:59