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/spacebar/boflib/file.h"
28 
29 namespace Bagel {
30 namespace SpaceBar {
31 
32 #define CDF_NOFLAGS 0x00000000
33 #define CDF_READONLY CBF_READONLY // Open for Read-only access
34 #define CDF_OVERWRITE CBF_OVERWRITE // *Overwrite any existing data-file
35 #define CDF_SHARED CBF_SHARED // *Open for Shared access
36 #define CDF_CREATE CBF_CREATE // *Create new file if not exist
37 #define CDF_SAVEFILE CBF_SAVEFILE
38 
39 #define CDF_MEMORY 0x00010000 // *header/footer should stay in memory
40 #define CDF_ENCRYPT 0x00020000 // Specifies if data should use encryption
41 #define CDF_KEEPOPEN 0x00040000 // File should be kept open after construction
42 #define CDF_COMPRESSED 0x00080000 // *Specifies if data should be compressed
43 // * = indicates feature not yet implemented
44 
45 #define CDF_DEFAULT (CDF_MEMORY | CDF_ENCRYPT | CDF_SHARED | CDF_KEEPOPEN | CDF_READONLY)
46 
47 #define MAX_PW_LEN 32 // Max Password length
48 
49 struct HeaderRec {
50 public:
51  int32 _lOffset;
52  int32 _lLength;
53  uint32 _lCrc;
54  uint32 _lKey;
55 
56  void synchronize(Common::Serializer &s);
57  static int size() {
58  return 16;
59  }
60 };
61 
62 struct HeadInfo {
63  int32 _lNumRecs; // Number of records in this file
64  int32 _lAddress; // starting address of footer
65  uint32 _lFlags; // contains flags for this file
66  uint32 _lFootCrc; // CRC of the footer
67 
68  void synchronize(Common::Serializer &s);
69  static int size() {
70  return 16;
71  }
72 };
73 
74 class CBofDataFile : public CBofFile {
75 private:
76  char _szPassWord[MAX_PW_LEN];
77  int32 _lHeaderLength = 0;
78  int32 _lHeaderStart = 0;
79  int32 _lNumRecs = 0;
80  HeaderRec *_pHeader = nullptr;
81 
82  bool _bHeaderDirty;
83 
84 protected:
89  ErrorCode readHeader();
90 
95  ErrorCode writeHeader();
96 
97 public:
101  CBofDataFile();
102 
106  virtual ~CBofDataFile();
107 
114  ErrorCode setFile(const char *pszFileName, uint32 lFlags);
115 
120  ErrorCode releaseFile();
121 
127  int32 getRecSize(int32 lRecNum);
128  int32 getNumberOfRecs() const {
129  return _lNumRecs;
130  }
131 
136  int32 getMaxRecSize() const;
137 
142  ErrorCode open();
143 
148  ErrorCode close() override;
149 
154  ErrorCode create();
155 
162  ErrorCode readRecord(int32 lRecNum, void *pBuf);
163 
169  ErrorCode readFromFile(int32 lRecNum, void *pBuf, int32 lBytes);
170 
180  ErrorCode writeRecord(int32 lRecNum, void *pBuf, int32 lSize = -1, bool bUpdateHeader = false, uint32 lKey = 0xFFFFFFFF);
181 
187  ErrorCode verifyRecord(int32 lRecNum);
188 
193  ErrorCode verifyAllRecords();
194 
203  ErrorCode addRecord(void *pBuf, int32 lLength, bool bUpdateHeader = false, uint32 lKey = 0xFFFFFFFF);
204 
210  int32 findRecord(uint32 lKey);
211 
216  void setPassword(const char *pszPassword);
217  const char *getPassword() const {
218  return _szPassWord;
219  }
220 
227  ErrorCode read(void *pDestBuf, int32 lBytes) override;
228  ErrorCode read(HeaderRec &rec);
229  ErrorCode read(HeadInfo &rec);
230 
237  ErrorCode write(const void *pSrcBuf, int32 lBytes) override;
238  ErrorCode write(HeaderRec &rec);
239  ErrorCode write(HeadInfo &rec);
240 };
241 
242 } // namespace SpaceBar
243 } // namespace Bagel
244 
245 #endif
Definition: dat_file.h:74
Definition: serializer.h:79
Definition: dat_file.h:49
Definition: file.h:100
Definition: afxwin.h:27
Definition: dat_file.h:62