aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2004-06-25 22:11:48 +0000
committerMax Horn2004-06-25 22:11:48 +0000
commite5f90509a606819dec58b7642c9845373ae364d5 (patch)
treeb892289fd90878d306be42c236c18f6ea6bbf269
parentde7c36f063eb4ee33b01bfb7be4186c7cb9fd704 (diff)
downloadscummvm-rg350-e5f90509a606819dec58b7642c9845373ae364d5.tar.gz
scummvm-rg350-e5f90509a606819dec58b7642c9845373ae364d5.tar.bz2
scummvm-rg350-e5f90509a606819dec58b7642c9845373ae364d5.zip
Cleaned up SaveFileManager stuff a little bit
svn-id: r14056
-rw-r--r--backends/PalmOS/Src/palmsave.cpp18
-rw-r--r--backends/dc/vmsave.cpp22
-rw-r--r--common/savefile.cpp57
-rw-r--r--common/savefile.h28
-rw-r--r--common/system.cpp3
-rw-r--r--common/system.h7
6 files changed, 64 insertions, 71 deletions
diff --git a/backends/PalmOS/Src/palmsave.cpp b/backends/PalmOS/Src/palmsave.cpp
index 1df11705a6..5e49e71ec8 100644
--- a/backends/PalmOS/Src/palmsave.cpp
+++ b/backends/PalmOS/Src/palmsave.cpp
@@ -37,9 +37,9 @@ public:
~PalmSaveFile();
bool isOpen() const { return file != NULL; }
-protected:
- int fread(void *buf, int size, int cnt);
- int fwrite(const void *buf, int size, int cnt);
+
+ uint32 read(void *buf, uint32 cnt);
+ uint32 write(const void *buf, uint32 cnt);
private :
FILE *file;
@@ -67,12 +67,12 @@ PalmSaveFile::~PalmSaveFile() {
}
}
-int PalmSaveFile::fread(void *buf, int size, int cnt) {
- return ::fread(buf, size, cnt, file);
+uint32 PalmSaveFile::read(void *buf, uint32 cnt) {
+ return ::fread(buf, 1, cnt, file);
}
-int PalmSaveFile::fwrite(const void *buf, int size, int cnt) {
- UInt32 fullsize = size*cnt;
+uint32 PalmSaveFile::write(const void *buf, uint32 cnt) {
+ UInt32 fullsize = cnt;
if (fullsize <= MAX_BLOCK)
{
@@ -92,12 +92,12 @@ int PalmSaveFile::fwrite(const void *buf, int size, int cnt) {
return cnt;
}
- return ::fwrite(buf, size, cnt, file);
+ return ::fwrite(buf, 1, cnt, file);
}
// SaveFileManager class
-class PalmSaveFileManager : public SaveFileManager {
+class PalmSaveFileManager : public DefaultSaveFileManager {
public:
void list_savefiles(const char *prefix, const char *directory, bool *marks, int num);
diff --git a/backends/dc/vmsave.cpp b/backends/dc/vmsave.cpp
index b80742ee07..d695ae2638 100644
--- a/backends/dc/vmsave.cpp
+++ b/backends/dc/vmsave.cpp
@@ -222,9 +222,8 @@ private:
int pos, size;
char filename[16];
-protected:
- virtual int fread(void *buf, int size, int cnt);
- virtual int fwrite(const void *buf, int size, int cnt);
+ uint32 read(void *buf, uint32 cnt);
+ uint32 write(const void *buf, uint32 cnt);
public:
VMSave(const char *_filename, bool _saveOrLoad)
@@ -258,6 +257,7 @@ public:
};
class VMSaveManager : public SaveFileManager {
+public:
virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad);
virtual void list_savefiles(const char *prefix, const char *directory, bool *marks, int num);
};
@@ -299,15 +299,15 @@ VMSave::~VMSave()
delete buffer;
}
-int VMSave::fread(void *buf, int sz, int cnt)
+uint32 VMSave::read(void *buf, uint32 cnt)
{
if (issave)
return -1;
- int nbyt = sz*cnt;
+ int nbyt = cnt;
if (pos + nbyt > size) {
- cnt = (size - pos)/sz;
- nbyt = sz*cnt;
+ cnt = (size - pos);
+ nbyt = cnt;
}
if (nbyt)
memcpy(buf, buffer + pos, nbyt);
@@ -315,15 +315,15 @@ int VMSave::fread(void *buf, int sz, int cnt)
return cnt;
}
-int VMSave::fwrite(const void *buf, int sz, int cnt)
+uint32 VMSave::write(const void *buf, uint32 cnt)
{
if (!issave)
return -1;
- int nbyt = sz*cnt;
+ int nbyt = cnt;
if (pos + nbyt > size) {
- cnt = (size - pos)/sz;
- nbyt = sz*cnt;
+ cnt = (size - pos);
+ nbyt = cnt;
}
if (nbyt)
memcpy(buffer + pos, buf, nbyt);
diff --git a/common/savefile.cpp b/common/savefile.cpp
index 3aba3fdc36..a25dae3dc5 100644
--- a/common/savefile.cpp
+++ b/common/savefile.cpp
@@ -30,15 +30,6 @@
#include <zlib.h>
#endif
-uint32 SaveFile::read(void *ptr, uint32 size) {
- return fread(ptr, 1, size);
-}
-
-uint32 SaveFile::write(const void *ptr, uint32 size) {
- return fwrite(ptr, 1, size);
-}
-
-
class StdioSaveFile : public SaveFile {
private:
FILE *fh;
@@ -50,11 +41,10 @@ public:
bool isOpen() const { return fh != 0; }
-protected:
- int fread(void *buf, int size, int cnt)
- { return ::fread(buf, size, cnt, fh); }
- int fwrite(const void *buf, int size, int cnt)
- { return ::fwrite(buf, size, cnt, fh); }
+ uint32 read(void *buf, uint32 cnt)
+ { return ::fread(buf, 1, cnt, fh); }
+ uint32 write(const void *buf, uint32 cnt)
+ { return ::fwrite(buf, 1, cnt, fh); }
};
@@ -70,11 +60,10 @@ public:
bool isOpen() const { return fh != 0; }
-protected:
- int fread(void *buf, int size, int cnt) {
- return ::gzread(fh, buf, size * cnt);
+ uint32 read(void *buf, uint32 cnt) {
+ return ::gzread(fh, buf, cnt);
}
- int fwrite(const void *buf, int size, int cnt) {
+ uint32 write(const void *buf, uint32 cnt) {
// 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.
@@ -82,24 +71,13 @@ protected:
// 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
- return ::gzwrite(fh, const_cast<void *>(buf), size * cnt);
+ return ::gzwrite(fh, const_cast<void *>(buf), cnt);
}
};
#endif
-SaveFile *SaveFileManager::open_savefile(const char *filename, const char *directory, bool saveOrLoad) {
- char buf[256];
- join_paths(filename, directory, buf, sizeof(buf));
- SaveFile *sf = makeSaveFile(buf, saveOrLoad);
- if (!sf->isOpen()) {
- delete sf;
- sf = 0;
- }
- return sf;
-}
-
-void SaveFileManager::join_paths(const char *filename, const char *directory,
+static void join_paths(const char *filename, const char *directory,
char *buf, int bufsize) {
buf[bufsize-1] = '\0';
strncpy(buf, directory, bufsize-1);
@@ -125,7 +103,22 @@ void SaveFileManager::join_paths(const char *filename, const char *directory,
strncat(buf, filename, bufsize-1);
}
-SaveFile *SaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
+SaveFile *DefaultSaveFileManager::open_savefile(const char *filename, const char *directory, bool saveOrLoad) {
+ char buf[256];
+ join_paths(filename, directory, buf, sizeof(buf));
+ SaveFile *sf = makeSaveFile(buf, saveOrLoad);
+ if (!sf->isOpen()) {
+ delete sf;
+ sf = 0;
+ }
+ return sf;
+}
+
+void DefaultSaveFileManager::list_savefiles(const char * /* prefix */, const char *directory, bool *marks, int num) {
+ memset(marks, true, num * sizeof(bool));
+}
+
+SaveFile *DefaultSaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
#ifdef USE_ZLIB
return new GzipSaveFile(filename, saveOrLoad);
#else
diff --git a/common/savefile.h b/common/savefile.h
index 83e09ad9c1..4e2c21eaa5 100644
--- a/common/savefile.h
+++ b/common/savefile.h
@@ -32,30 +32,30 @@ class SaveFile : public Common::ReadStream, public Common::WriteStream {
public:
virtual ~SaveFile() {}
- /* Compatible with File API */
- uint32 read(void *ptr, uint32 size);
- uint32 write(const void *ptr, uint32 size);
-
virtual bool isOpen() const = 0;
-
-protected:
- /* Only for internal use, use File compatible API above instead */
- virtual int fread(void *buf, int size, int cnt) = 0;
- virtual int fwrite(const void *buf, int size, int cnt) = 0;
};
class SaveFileManager {
-
public:
virtual ~SaveFileManager() {}
+ /**
+ * Open the file with name filename in the given directory for saving or loading.
+ * @param filename the filename
+ * @param directory the directory
+ * @param saveOrLoad true for saving, false for loading
+ * @return pointer to a SaveFile object
+ */
+ virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad) = 0;
+ virtual void list_savefiles(const char * /* prefix */, const char *directory, bool *marks, int num) = 0;
+};
+
+class DefaultSaveFileManager : public SaveFileManager {
+public:
virtual SaveFile *open_savefile(const char *filename, const char *directory, bool saveOrLoad);
- virtual void list_savefiles(const char * /* prefix */, const char *directory, bool *marks, int num) {
- memset(marks, true, num * sizeof(bool));
- }
+ virtual void list_savefiles(const char * /* prefix */, const char *directory, bool *marks, int num);
protected:
- void join_paths(const char *filename, const char *directory, char *buf, int bufsize);
virtual SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
};
diff --git a/common/system.cpp b/common/system.cpp
index 75998e3795..bc65a5f21e 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -92,6 +92,9 @@ void OSystem::displayMessageOnOSD(const char *msg) {
dialog.runModal();
}
+SaveFileManager *OSystem::get_savefile_manager() {
+ return new DefaultSaveFileManager();
+}
#pragma mark -
diff --git a/common/system.h b/common/system.h
index ec057dde63..794271f8bb 100644
--- a/common/system.h
+++ b/common/system.h
@@ -24,10 +24,9 @@
#define COMMON_SYSTEM_H
#include "common/scummsys.h"
-#include "common/savefile.h"
#include "common/util.h"
#include "common/rect.h"
-
+#include "common/savefile.h"
/**
* Interface for ScummVM backends. If you want to port ScummVM to a system
@@ -623,9 +622,7 @@ public:
virtual void displayMessageOnOSD(const char *msg);
/** Savefile management. */
- virtual SaveFileManager *get_savefile_manager() {
- return new SaveFileManager();
- }
+ virtual SaveFileManager *get_savefile_manager();
//@}
};