ScummVM API documentation
files.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 XEEN_FILES_H
23#define XEEN_FILES_H
24
25#include "common/scummsys.h"
26#include "common/array.h"
27#include "common/file.h"
28#include "common/memstream.h"
29#include "common/savefile.h"
30#include "common/serializer.h"
31#include "common/str-array.h"
32#include "graphics/surface.h"
33#include "mm/shared/xeen/cc_archive.h"
34#include "mm/shared/xeen/file.h"
35
36namespace MM {
37namespace Xeen {
38
39using Shared::Xeen::BaseCCArchive;
40using Shared::Xeen::CCArchive;
41using Shared::Xeen::CCEntry;
42using Shared::Xeen::File;
43
44class XeenEngine;
45class SaveArchive;
46class Party;
47class OutFile;
48class SavesManager;
49
50#define SYNC_AS(SUFFIX,STREAM,TYPE,SIZE) \
51 template<typename T> \
52 void syncAs ## SUFFIX(T &val, Version minVersion = 0, Version maxVersion = kLastVersion) { \
53 if (_version < minVersion || _version > maxVersion) \
54 return; \
55 if (_loadStream) \
56 val = static_cast<TYPE>(_loadStream->read ## STREAM()); \
57 else { \
58 TYPE tmp = (TYPE)val; \
59 _saveStream->write ## STREAM(tmp); \
60 } \
61 _bytesSynced += SIZE; \
62 }
63
64/*
65 * Main resource manager
66 */
68public:
69 int _ccNum = 0;
70 CCArchive *_xeenCc = nullptr, *_darkCc = nullptr,
71 *_introCc = nullptr;
72 SaveArchive *_xeenSave = nullptr, *_darkSave = nullptr;
73 BaseCCArchive *_currentArchive = nullptr;
74 SaveArchive *_currentSave = nullptr;
75
76public:
81
86
91 bool setup();
92
97 void setGameCc(int ccMode);
98
103
108};
109
116class SubWriteStream : virtual public Common::WriteStream {
117protected:
118 Common::WriteStream *_parentStream;
119 uint32 _begin;
120public:
121 SubWriteStream(Common::WriteStream *parentStream) :
122 _parentStream(parentStream), _begin(parentStream->pos()) {
123 }
124
125 uint32 write(const void *dataPtr, uint32 dataSize) override {
126 return _parentStream->write(dataPtr, dataSize);
127 }
128 bool flush() override { return _parentStream->flush(); }
129 void finalize() override {}
130 int64 pos() const override { return _parentStream->pos() - _begin; }
131};
132
134private:
136 int _filesize;
137public:
139 Common::Serializer(in, out), _in(in), _filesize(-1) {}
140
141 SYNC_AS(Sint8, Byte, int8, 1)
142
143 bool finished() {
144 if (_in && _filesize == -1)
145 _filesize = _in->size();
146 return _in != nullptr && _in->pos() >= _filesize;
147 }
148};
149
151 friend class OutFile;
152private:
153 Party *_party;
154 byte *_data;
155 uint32 _dataSize;
157public:
158 SaveArchive(Party *party);
159 ~SaveArchive() override;
160
164 void reset(CCArchive *src);
165
170
175
180
185
189 void loadParty();
190
194 void replaceEntry(uint16 id, const byte *data, size_t size);
195};
196
201private:
202 SaveArchive *_archive;
203 Common::Path _filename;
205public:
206 OutFile(const Common::Path &filename);
207 OutFile(const Common::Path &filename, SaveArchive *archive);
208 OutFile(const Common::Path &filename, int ccMode);
209
213 void finalize() override;
214
218 uint32 write(const void *dataPtr, uint32 dataSize) override;
219
223 int64 pos() const override;
224};
225
226} // End of namespace Xeen
227} // End of namespace MM
228
229#endif
Definition: memstream.h:194
Definition: path.h:52
Definition: stream.h:745
virtual int64 pos() const =0
virtual int64 size() const =0
Definition: serializer.h:80
Definition: stream.h:77
virtual bool flush()
Definition: stream.h:103
virtual int64 pos() const =0
virtual uint32 write(const void *dataPtr, uint32 dataSize)=0
Definition: cc_archive.h:51
Definition: cc_archive.h:94
Definition: files.h:67
FileManager(XeenEngine *vm)
void save(Common::WriteStream &s)
void setGameCc(int ccMode)
void load(Common::SeekableReadStream &stream)
Definition: files.h:200
int64 pos() const override
uint32 write(const void *dataPtr, uint32 dataSize) override
void finalize() override
Definition: party.h:159
Definition: files.h:150
void load(Common::SeekableReadStream &stream)
virtual Common::SeekableReadStream * createReadStreamForMember(uint16 id) const
void save(Common::WriteStream &s)
Common::SeekableReadStream * createReadStreamForMember(const Common::Path &path) const override
void replaceEntry(uint16 id, const byte *data, size_t size)
void reset(CCArchive *src)
Definition: files.h:116
uint32 write(const void *dataPtr, uint32 dataSize) override
Definition: files.h:125
bool flush() override
Definition: files.h:128
int64 pos() const override
Definition: files.h:130
void finalize() override
Definition: files.h:129
Definition: xeen.h:107
Definition: files.h:133
Definition: detection.h:27