aboutsummaryrefslogtreecommitdiff
path: root/backends/saves/default/default-saves.cpp
diff options
context:
space:
mode:
authorMax Horn2007-02-18 02:25:39 +0000
committerMax Horn2007-02-18 02:25:39 +0000
commit7f07e6e48a94049e16ffaac6c39256c4a97755a4 (patch)
tree68e73d976bf6dd85b733051f5e0d874f0099d4c1 /backends/saves/default/default-saves.cpp
parent5fc65f223007d4d5d4e3ee2d9047c84c2b950757 (diff)
downloadscummvm-rg350-7f07e6e48a94049e16ffaac6c39256c4a97755a4.tar.gz
scummvm-rg350-7f07e6e48a94049e16ffaac6c39256c4a97755a4.tar.bz2
scummvm-rg350-7f07e6e48a94049e16ffaac6c39256c4a97755a4.zip
Replaced the old code for compressed savegames (which was using the gzopen/gzread/etc. API, and thuse tied to FILE/fopen/fread/etc.) with a new wrapper approach, which allows reading/writing gzip data via arbitrary SaveFile implementations, and thus can be used with custom savefile implementations
svn-id: r25669
Diffstat (limited to 'backends/saves/default/default-saves.cpp')
-rw-r--r--backends/saves/default/default-saves.cpp81
1 files changed, 3 insertions, 78 deletions
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index 8537d4c2b6..0e5b00d316 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -24,14 +24,11 @@
#include "common/savefile.h"
#include "common/util.h"
#include "backends/saves/default/default-saves.h"
+#include "backends/saves/compressed/compressed-saves.h"
#include <stdio.h>
#include <string.h>
-#ifdef USE_ZLIB
-#include <zlib.h>
-#endif
-
#if defined(UNIX) || defined(__SYMBIAN32__)
#include <errno.h>
#include <sys/stat.h>
@@ -85,70 +82,6 @@ public:
};
-#ifdef USE_ZLIB
-class GzipSaveFile : public Common::InSaveFile, public Common::OutSaveFile {
-private:
- gzFile fh;
- bool _ioError;
-public:
- GzipSaveFile(const char *filename, bool saveOrLoad) {
- _ioError = false;
- fh = gzopen(filename, (saveOrLoad? "wb" : "rb"));
- }
- ~GzipSaveFile() {
- if (fh)
- gzclose(fh);
- }
-
- bool eos() const { return gzeof(fh) != 0; }
- bool ioFailed() const { return _ioError; }
- void clearIOFailed() { _ioError = false; }
-
- bool isOpen() const { return fh != 0; }
-
- uint32 read(void *dataPtr, uint32 dataSize) {
- assert(fh);
- int ret = gzread(fh, dataPtr, dataSize);
- if (ret <= -1)
- _ioError = true;
- return ret;
- }
- uint32 write(const void *dataPtr, uint32 dataSize) {
- assert(fh);
- // Due to a "bug" in the zlib headers (or maybe I should say,
- // a bug in the C++ spec? Whatever <g>) we have to be a bit
- // hackish here and remove the const qualifier.
- // Note that gzwrite's buf param is declared as "const voidp"
- // which you might think is the same as "const void *" but it
- // is not - rather it is equal to "void const *" which is the
- // same as "void *". Hrmpf
- int ret = gzwrite(fh, const_cast<void *>(dataPtr), dataSize);
- if (ret <= 0)
- _ioError = true;
- return ret;
- }
-
- uint32 pos() const {
- assert(fh);
- return gztell(fh);
- }
- uint32 size() const {
- assert(fh);
- uint32 oldPos = gztell(fh);
- gzseek(fh, 0, SEEK_END);
- uint32 length = gztell(fh);
- gzseek(fh, oldPos, SEEK_SET);
- return length;
- }
-
- void seek(int32 offs, int whence = SEEK_SET) {
- assert(fh);
- gzseek(fh, offs, whence);
- }
-};
-#endif
-
-
static void join_paths(const char *filename, const char *directory,
char *buf, int bufsize) {
buf[bufsize-1] = '\0';
@@ -219,34 +152,26 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename)
join_paths(filename, savePath, buf, sizeof(buf));
-#ifdef USE_ZLIB
- GzipSaveFile *sf = new GzipSaveFile(buf, true);
-#else
StdioSaveFile *sf = new StdioSaveFile(buf, true);
-#endif
if (!sf->isOpen()) {
delete sf;
sf = 0;
}
- return sf;
+ return wrapOutSaveFile(sf);
}
Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
char buf[256];
join_paths(filename, getSavePath(), buf, sizeof(buf));
-#ifdef USE_ZLIB
- GzipSaveFile *sf = new GzipSaveFile(buf, false);
-#else
StdioSaveFile *sf = new StdioSaveFile(buf, false);
-#endif
if (!sf->isOpen()) {
delete sf;
sf = 0;
}
- return sf;
+ return wrapInSaveFile(sf);
}
void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) {