Use "new" framework for compressed saves...

svn-id: r29765
This commit is contained in:
Marcus Comstedt 2007-12-08 15:11:20 +00:00
parent 7f019cfdee
commit 9f43e2cf8a
2 changed files with 6 additions and 34 deletions

View File

@ -11,7 +11,7 @@ VPATH = $(srcdir)
CC = sh-elf-gcc -ml -m4-single-only
CXX = sh-elf-g++ -ml -m4-single-only
CXXFLAGS= -O3 -Wno-multichar -funroll-loops -fschedule-insns2 -fomit-frame-pointer -fdelete-null-pointer-checks -fno-exceptions
DEFINES = -D__DC__ -DNONSTANDARD_PORT -DUSE_MAD
DEFINES = -D__DC__ -DNONSTANDARD_PORT -DUSE_MAD -DUSE_ZLIB
LDFLAGS = -Wl,-Ttext,0x8c010000 -nostartfiles $(ronindir)/lib/crt0.o
INCLUDES= -I./ -I$(srcdir) -I$(srcdir)/common -I$(ronindir)/include/ -I$(srcdir)/engines
LIBS = -L$(ronindir)/lib -lmad -lronin -lz -lm

View File

@ -30,11 +30,10 @@
#include <common/savefile.h>
#include <gui/newgui.h>
#include <gui/message.h>
#include <zlib.h>
#include <backends/saves/compressed/compressed-saves.h>
// Savegame can not be bigger than this, even before compression
// Savegame can not be bigger than this
#define MAX_SAVE_SIZE (128*1024)
@ -137,7 +136,6 @@ static bool tryLoad(char *&buffer, int &size, const char *filename, int vm)
struct timestamp tstamp;
struct tm tm;
time_t t;
unsigned char iconbuffer[512+32];
if (!vmsfs_check_unit(vm, 0, &info))
return false;
@ -298,20 +296,6 @@ public:
bool readSaveGame(const char *filename)
{ return ::readSaveGame(buffer, _size, filename); }
void tryUncompress()
{
if (_size > 0 && buffer[0] != 'S') {
// Data does not start with "SCVM". Maybe compressed?
char *expbuf = new char[MAX_SAVE_SIZE];
unsigned long destlen = MAX_SAVE_SIZE;
if (!uncompress((Bytef*)expbuf, &destlen, (Bytef*)buffer, _size)) {
delete[] buffer;
buffer = expbuf;
_size = destlen;
} else delete[] expbuf;
}
}
};
class OutVMSave : public Common::OutSaveFile {
@ -342,14 +326,13 @@ class VMSaveManager : public Common::SaveFileManager {
public:
virtual Common::OutSaveFile *openForSaving(const char *filename) {
return new OutVMSave(filename);
return wrapOutSaveFile(new OutVMSave(filename));
}
virtual Common::InSaveFile *openForLoading(const char *filename) {
InVMSave *s = new InVMSave();
if (s->readSaveGame(filename)) {
s->tryUncompress();
return s;
return wrapInSaveFile(s);
} else {
delete s;
return NULL;
@ -371,22 +354,11 @@ void OutVMSave::finalize()
if (committed >= pos)
return;
char *data = buffer, *compbuf = NULL;
char *data = buffer;
int len = pos;
if (pos) {
// Try compression
compbuf = new char[pos];
unsigned long destlen = pos;
if (!compress((Bytef*)compbuf, &destlen, (Bytef*)buffer, pos)) {
data = compbuf;
len = destlen;
}
}
vmsaveResult r = writeSaveGame(gGameName, data, len, filename, icon);
committed = pos;
if (compbuf != NULL)
delete[] compbuf;
if (r != VMSAVE_OK)
iofailed = true;
displaySaveResult(r);