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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 /*
24  * This file is based on WME Lite.
25  * http://dead-code.org/redir.php?target=wmelite
26  * Copyright (c) 2011 Jan Nedoma
27  */
28 
29 #ifndef WINTERMUTE_BASE_PERSISTENCE_MANAGER_H
30 #define WINTERMUTE_BASE_PERSISTENCE_MANAGER_H
31 
32 
33 #include "engines/wintermute/dctypes.h"
34 #include "engines/wintermute/math/rect32.h"
35 #include "engines/savestate.h"
36 #include "common/stream.h"
37 #include "common/str.h"
38 #include "common/system.h"
39 #include "common/rect.h"
40 
41 namespace Wintermute {
42 
43 class Vector2;
44 class BaseGame;
45 class BasePersistenceManager {
46 public:
47 	char *_savedDescription;
48 	Common::String _savePrefix;
49 	Common::String _savedName;
50 	bool saveFile(const Common::String &filename);
51 	uint32 getDWORD();
52 	void putDWORD(uint32 val);
53 	char *getString();
54 	Common::String getStringObj();
55 	void putString(const char *val);
56 	float getFloat();
57 	void putFloat(float val);
58 	double getDouble();
59 	void putDouble(double val);
60 	void cleanup();
61 	void getSaveStateDesc(int slot, SaveStateDescriptor &desc);
62 	void deleteSaveSlot(int slot);
63 	uint32 getMaxUsedSlot();
64 	bool getSaveExists(int slot);
65 	bool initLoad(const Common::String &filename);
66 	bool initSave(const Common::String &desc);
67 	bool getBytes(byte *buffer, uint32 size);
68 	bool putBytes(byte *buffer, uint32 size);
69 	uint32 _offset;
70 
getIsSaving()71 	bool getIsSaving() { return _saving; }
72 
73 	uint32 _richBufferSize;
74 	byte *_richBuffer;
75 
76 	bool transferPtr(const char *name, void *val);
77 	bool transferSint32(const char *name, int32 *val);
78 	bool transferUint32(const char *name, uint32 *val);
79 	bool transferFloat(const char *name, float *val);
80 	bool transferDouble(const char *name, double *val);
81 	bool transferBool(const char *name, bool *val);
82 	bool transferByte(const char *name, byte *val);
83 	bool transferRect32(const char *name, Rect32 *val);
84 	bool transferPoint32(const char *name, Point32 *val);
85 	bool transferConstChar(const char *name, const char **val);
86 	bool transferCharPtr(const char *name, char **val);
87 	bool transferString(const char *name, Common::String *val);
88 	bool transferVector2(const char *name, Vector2 *val);
89 	BasePersistenceManager(const Common::String &savePrefix = "", bool deleteSingleton = false);
90 	virtual ~BasePersistenceManager();
91 	bool checkVersion(byte  verMajor, byte verMinor, byte verBuild);
92 
93 	uint32 _thumbnailDataSize;
94 	byte *_thumbnailData;
95 	uint32 _scummVMThumbSize;
96 	byte *_scummVMThumbnailData;
97 	Common::String getFilenameForSlot(int slot) const;
98 private:
99 	bool _deleteSingleton;
100 	bool readHeader(const Common::String &filename);
101 	TimeDate getTimeDate();
102 	bool putTimeDate(const TimeDate &t);
103 	Common::WriteStream *_saveStream;
104 	Common::SeekableReadStream *_loadStream;
105 	TimeDate _savedTimestamp;
106 	uint32 _savedPlayTime;
107 	byte _savedVerMajor;
108 	byte _savedVerMinor;
109 	byte _savedVerBuild;
110 	byte _savedExtMajor;
111 	byte _savedExtMinor;
112 	bool _saving;
113 	// Separate from Base, as this class can do SOME operations without a _gameRef.
114 	BaseGame *_gameRef;
115 };
116 
117 } // End of namespace Wintermute
118 
119 #endif
120