ScummVM API documentation
savehandler.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, this code is also
23  * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24  * full text of the license.
25  *
26  */
27 
28 #ifndef GOB_SAVE_SAVEHANDLER_H
29 #define GOB_SAVE_SAVEHANDLER_H
30 
31 #include "common/savefile.h"
32 #include "common/array.h"
33 
34 #include "engines/gob/video.h" // for SurfacePtr
35 
36 namespace Gob {
37 
38 class GobEngine;
39 class SavePartInfo;
40 class SavePartVars;
41 class SavePartSprite;
42 class SaveConverter;
43 
45 class SlotFile {
46 public:
52  SlotFile(GobEngine *vm, uint32 slotCount, const Common::String &base);
53  virtual ~SlotFile();
54 
56  virtual int getSlot(int32 offset) const = 0;
58  virtual int getSlotRemainder(int32 offset) const = 0;
59 
60 protected:
61  GobEngine *_vm;
62  Common::String _base;
63 
64  uint32 _slotCount;
65 };
66 
68 class SlotFileIndexed : public SlotFile {
69 public:
70  SlotFileIndexed(GobEngine *vm, uint32 slotCount, const Common::String &base,
71  const Common::String &extStub);
72  ~SlotFileIndexed() override;
73 
75  Common::String build(int slot) const;
76 
78  virtual uint32 getSlotMax() const;
79 
81  virtual int32 tallyUpFiles(uint32 slotSize, uint32 indexSize) const;
82 
84  virtual void buildIndex(byte *buffer, SavePartInfo &info,
85  SaveConverter *converter = 0, bool setLongest = false) const;
86 
87  virtual bool exists(int slot) const;
88  virtual Common::InSaveFile *openRead(int slot) const;
89  virtual Common::OutSaveFile *openWrite(int slot) const;
90 
91 protected:
92  Common::String _ext;
93 };
94 
96 class SlotFileStatic : public SlotFile {
97 public:
98  SlotFileStatic(GobEngine *vm, const Common::String &base, const Common::String &ext);
99  ~SlotFileStatic() override;
100 
101  int getSlot(int32 offset) const override;
102  int getSlotRemainder(int32 offset) const override;
103 
105  Common::String build() const;
106 
107  virtual bool exists() const;
108  virtual Common::InSaveFile *openRead() const;
109  virtual Common::OutSaveFile *openWrite() const;
110 
111 protected:
112  Common::String _ext;
113 };
114 
116 class SaveHandler {
117 public:
118  SaveHandler(GobEngine *vm);
119  virtual ~SaveHandler();
120 
122  virtual int32 getSize() = 0;
124  virtual bool load(int16 dataVar, int32 size, int32 offset) = 0;
126  virtual bool save(int16 dataVar, int32 size, int32 offset) = 0;
127 
128  virtual bool loadToRaw(byte *ptr, int32 size, int32 offset);
129  virtual bool saveFromRaw(const byte *ptr, int32 size, int32 offset);
130 
132  virtual bool deleteFile();
133 
134  static uint32 getVarSize(GobEngine *vm);
135 
136 protected:
137  GobEngine *_vm;
138 };
139 
142 public:
144  ~TempSpriteHandler() override;
145 
146  int32 getSize() override;
147  bool load(int16 dataVar, int32 size, int32 offset) override;
148  bool save(int16 dataVar, int32 size, int32 offset) override;
149 
150  bool loadToRaw(byte *ptr, int32 size, int32 offset) override;
151  bool saveFromRaw(const byte *ptr, int32 size, int32 offset) override;
152 
153  bool create(uint32 width, uint32 height, bool trueColor);
154  bool createFromSprite(int16 dataVar, int32 size, int32 offset);
155 
156 protected:
157  SavePartSprite *_sprite;
158 
160  static bool isDummy(int32 size);
162  static bool isSprite(int32 size);
164  static int getIndex(int32 size);
166  static bool usesPalette(int32 size);
167 
168  SurfacePtr createSprite(int16 dataVar, int32 size, int32 offset);
169 };
170 
172 class NotesHandler : public SaveHandler {
173 public:
174  NotesHandler(uint32 notesSize, GobEngine *vm, const Common::String &target);
175  ~NotesHandler() override;
176 
177  int32 getSize() override;
178  bool load(int16 dataVar, int32 size, int32 offset) override;
179  bool save(int16 dataVar, int32 size, int32 offset) override;
180 
181 private:
182  class File : public SlotFileStatic {
183  public:
184  File(GobEngine *vm, const Common::String &base);
185  ~File() override;
186  };
187 
188  uint32 _notesSize;
189  File *_file;
190  SavePartVars *_notes;
191 };
192 
194 class FakeFileHandler : public SaveHandler {
195 public:
197  ~FakeFileHandler() override;
198 
199  int32 getSize() override;
200  bool load(int16 dataVar, int32 size, int32 offset) override;
201  bool save(int16 dataVar, int32 size, int32 offset) override;
202  bool loadToRaw(byte *ptr, int32 size, int32 offset) override;
203  bool saveFromRaw(const byte *ptr, int32 size, int32 offset) override;
204 
205  bool deleteFile() override;
206 
207 private:
208  Common::Array<byte> _data;
209 };
210 
211 } // End of namespace Gob
212 
213 #endif // GOB_SAVE_SAVEHANDLER_H
Definition: gob.h:163
Definition: str.h:59
Definition: savehandler.h:96
Definition: savehandler.h:172
Definition: savefile.h:54
Definition: savehandler.h:194
Definition: savefile.h:130
Definition: stream.h:745
Definition: savefile.h:200
virtual int getSlotRemainder(int32 offset) const =0
Definition: savehandler.h:141
Definition: anifile.h:40
Definition: savehandler.h:68
Definition: savehandler.h:116
SlotFile(GobEngine *vm, uint32 slotCount, const Common::String &base)
virtual int getSlot(int32 offset) const =0
Definition: savefile.h:162
Definition: savehandler.h:45
Definition: saveconverter.h:43