ScummVM API documentation
framfs_save_manager.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 __FRAMFS_SAVE_MANAGER__
23#define __FRAMFS_SAVE_MANAGER__
24
25#include <common/savefile.h>
26#include <common/compression/deflate.h>
27
28#include <framfs.h> // N64 FramFS library
29
30bool fram_deleteSaveGame(const char *filename);
31
33private:
34 FRAMFILE *fd;
35
36 uint32 read(void *buf, uint32 cnt) override;
37 bool skip(uint32 offset) override;
38 bool seek(int64 offs, int whence) override;
39
40public:
41 InFRAMSave() : fd(NULL) { }
42
43 ~InFRAMSave() {
44 if (fd != NULL)
45 framfs_close(fd);
46 }
47
48 bool eos() const override {
49 return framfs_eof(fd);
50 }
51 void clearErr() override {
52 framfs_clearerr(fd);
53 }
54 int64 pos() const override {
55 return framfs_tell(fd);
56 }
57 int64 size() const override {
58 return fd->size;
59 }
60
61 bool readSaveGame(const char *filename) {
62 fd = framfs_open(filename, "r");
63 return (fd != NULL);
64 }
65};
66
68private:
69 FRAMFILE *fd;
70
71public:
72 uint32 write(const void *buf, uint32 cnt);
73 virtual int64 pos() const {
74 return framfs_tell(fd);
75 }
76
77 OutFRAMSave(const char *_filename) : fd(NULL) {
78 fd = framfs_open(_filename, "w");
79 }
80
81 ~OutFRAMSave() {
82 if (fd != NULL) {
83 finalize();
84 framfs_close(fd);
85 }
86 }
87
88 bool err() const {
89 if (fd)
90 return (framfs_error(fd) == 1);
91 else
92 return true;
93 }
94 void clearErr() {
95 framfs_clearerr(fd);
96 }
97 void finalize() {
98 framfs_flush(fd);
99 }
100};
101
103public:
104 void updateSavefilesList(Common::StringArray &lockedFiles) override {
105 // this method is used to lock saves while cloud syncing
106 // as there is no network on N64, this method wouldn't be used
107 // thus it's not implemtented
108 }
109
110 Common::InSaveFile *openRawFile(const Common::String &filename) override {
111 InFRAMSave *s = new InFRAMSave();
112 if (s->readSaveGame(filename.c_str())) {
113 return s;
114 } else {
115 delete s;
116 return 0;
117 }
118 }
119
120 Common::OutSaveFile *openForSaving(const Common::String &filename, bool compress = true) override {
121 OutFRAMSave *s = new OutFRAMSave(filename.c_str());
122 if (!s->err()) {
123 return new Common::OutSaveFile(compress ? Common::wrapCompressedWriteStream(s) : s);
124 } else {
125 delete s;
126 return 0;
127 }
128 }
129
131 InFRAMSave *s = new InFRAMSave();
132 if (s->readSaveGame(filename.c_str())) {
134 } else {
135 delete s;
136 return 0;
137 }
138 }
139
140 bool removeSavefile(const Common::String &filename) override {
141 return ::fram_deleteSaveGame(filename.c_str());
142 }
143
145
146 bool exists(const Common::String &filename) override {
147 return InFRAMSave().readSaveGame(filename.c_str());
148 }
149};
150
151
152#endif
Definition: savefile.h:54
Definition: savefile.h:142
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: framfs_save_manager.h:102
Common::InSaveFile * openRawFile(const Common::String &filename) override
Definition: framfs_save_manager.h:110
Common::OutSaveFile * openForSaving(const Common::String &filename, bool compress=true) override
Definition: framfs_save_manager.h:120
Common::InSaveFile * openForLoading(const Common::String &filename) override
Definition: framfs_save_manager.h:130
void updateSavefilesList(Common::StringArray &lockedFiles) override
Definition: framfs_save_manager.h:104
bool exists(const Common::String &filename) override
Definition: framfs_save_manager.h:146
Common::StringArray listSavefiles(const Common::String &pattern) override
bool removeSavefile(const Common::String &filename) override
Definition: framfs_save_manager.h:140
Definition: framfs_save_manager.h:32
int64 size() const override
Definition: framfs_save_manager.h:57
void clearErr() override
Definition: framfs_save_manager.h:51
int64 pos() const override
Definition: framfs_save_manager.h:54
bool eos() const override
Definition: framfs_save_manager.h:48
Definition: framfs_save_manager.h:67
virtual int64 pos() const
Definition: framfs_save_manager.h:73
bool err() const
Definition: framfs_save_manager.h:88
void clearErr()
Definition: framfs_save_manager.h:94
void finalize()
Definition: framfs_save_manager.h:97
uint32 write(const void *buf, uint32 cnt)
SeekableReadStream * wrapCompressedReadStream(SeekableReadStream *toBeWrapped, DisposeAfterUse::Flag disposeParent=DisposeAfterUse::YES, uint64 knownSize=0)
WriteStream * wrapCompressedWriteStream(WriteStream *toBeWrapped)