ScummVM API documentation
fileio.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 /*
23  * This code is based on original Sfinx source code
24  * Copyright (c) 1994-1997 Janusz B. Wisniewski and L.K. Avalon
25  */
26 
27 #ifndef CGE2_FILEIO_H
28 #define CGE2_FILEIO_H
29 
30 #include "common/file.h"
31 
32 namespace CGE2 {
33 
34 #define kBtSize 2048
35 #define kBtKeySize 13
36 #define kBtLevel 2
37 #define kBtInnerCount ((kBtSize - 4 /*sizeof(Header) */) / (kBtKeySize + 2 /*sizeof(Inner) */))
38 #define kBtLeafCount ((kBtSize - 4 /*sizeof(Header) */) / (kBtKeySize + 4 + 4 /*sizeof(BtKeypack) */))
39 #define kBtValNone 0xFFFF
40 #define kBtValRoot 0
41 #define kCatName "VOL.CAT"
42 #define kDatName "VOL.DAT"
43 #define kCryptSeed 0xA5
44 
45 enum ID {
46  kIdNear, kIdMTake, kIdFTake, kIdPhase, kIdSeq,
47  kIdName, kIdType, kIdFront, kIdEast,
48  kIdPortable, kIdTransparent,
49  kIdNone = -1
50 };
51 
52 struct BtKeypack {
53  char _key[kBtKeySize];
54  uint32 _pos;
55  uint32 _size;
56 };
57 
58 struct Inner {
59  uint8 _key[kBtKeySize];
60  uint16 _down;
61 };
62 
63 struct Header {
64  uint16 _count;
65  uint16 _down;
66 };
67 
68 struct BtPage {
69  Header _header;
70  union {
71  // dummy filler to make proper size of union
72  uint8 _data[kBtSize - 4]; /* 4 is the size of struct Header */
73  // inner version of data: key + word-sized page link
74  Inner _inner[kBtInnerCount];
75  // leaf version of data: key + all user data
76  BtKeypack _leaf[kBtLeafCount];
77  };
78 
79  void readBTree(Common::ReadStream &s);
80 };
81 
83 private:
84  struct {
85  BtPage *_page;
86  uint16 _pageNo;
87  int _index;
88  } _buff[kBtLevel];
89 
90  BtPage *getPage(int level, uint16 pageId);
91  uint16 catRead(byte *buf, uint16 length);
92  Common::File *_catFile;
93  Common::File *_datFile;
94  void xCrypt(byte *buf, uint16 length);
95 public:
97  ~ResourceManager();
98  uint16 read(byte *buf, uint16 length);
99  bool seek(int32 offs, int whence = SEEK_SET);
100 
101  BtKeypack *find(const char *key);
102  bool exist(const char *name);
103 };
104 
106 private:
107  Common::SeekableReadStream *_readStream;
108  int _lineCount;
109  bool _error;
110 public:
111  EncryptedStream(ResourceManager *resman, const char *name);
112  ~EncryptedStream();
113  bool err();
114  bool eos();
115  bool seek(int32 offset);
116  int32 pos();
117  int32 size();
118  uint32 read(byte *dataPtr, uint32 dataSize);
119  int16 readSint16LE();
120  uint32 readUint32LE();
121  Common::String readLine();
122  int getLineCount() { return _lineCount; }
123 
124  static const char *const kIdTab[];
125 };
126 
127 } // End of namespace CGE2
128 
129 #endif // CGE2_FILEIO_H
Definition: fileio.h:52
Definition: str.h:59
Definition: fileio.h:63
In find(In first, In last, const T &v)
Definition: algorithm.h:168
Definition: stream.h:745
Definition: fileio.h:68
Definition: file.h:47
Definition: fileio.h:105
Definition: bitmap.h:33
Definition: fileio.h:58
Definition: fileio.h:82
Definition: stream.h:385