aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2005-04-10 15:13:40 +0000
committerMax Horn2005-04-10 15:13:40 +0000
commite79c168d35d9c3633e3dfb618bd05466b0efc307 (patch)
treefe4fa01fd852546eaa3229f62069109d98eb8a67 /common
parente03861fdd4ca4cb676788c4ae4ea19647107fd6b (diff)
downloadscummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.tar.gz
scummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.tar.bz2
scummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.zip
split SaveFileManager::openSavefile and class SaveFile into two, each, one for loading and one for saving
svn-id: r17517
Diffstat (limited to 'common')
-rw-r--r--common/savefile.cpp24
-rw-r--r--common/savefile.h54
2 files changed, 59 insertions, 19 deletions
diff --git a/common/savefile.cpp b/common/savefile.cpp
index 03b2eaa4e2..b6d4cf47b9 100644
--- a/common/savefile.cpp
+++ b/common/savefile.cpp
@@ -134,15 +134,16 @@ static void join_paths(const char *filename, const char *directory,
strncat(buf, filename, bufsize-1);
}
-SaveFile *DefaultSaveFileManager::openSavefile(const char *filename, bool saveOrLoad) {
+OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) {
char buf[256];
join_paths(filename, getSavePath(), buf, sizeof(buf));
- SaveFile *sf = makeSaveFile(buf, saveOrLoad);
- if (!sf->isOpen()) {
- delete sf;
- sf = 0;
- }
- return sf;
+ return makeSaveFile(buf, true);
+}
+
+InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
+ char buf[256];
+ join_paths(filename, getSavePath(), buf, sizeof(buf));
+ return makeSaveFile(buf, false);
}
void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) {
@@ -151,8 +152,13 @@ void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *mark
SaveFile *DefaultSaveFileManager::makeSaveFile(const char *filename, bool saveOrLoad) {
#ifdef USE_ZLIB
- return new GzipSaveFile(filename, saveOrLoad);
+ GzipSaveFile *sf = new GzipSaveFile(filename, saveOrLoad);
#else
- return new StdioSaveFile(filename, saveOrLoad);
+ StdioSaveFile *sf = new StdioSaveFile(filename, saveOrLoad);
#endif
+ if (!sf->isOpen()) {
+ delete sf;
+ sf = 0;
+ }
+ return sf;
}
diff --git a/common/savefile.h b/common/savefile.h
index ba2c2c9885..4b4771daa9 100644
--- a/common/savefile.h
+++ b/common/savefile.h
@@ -27,11 +27,38 @@
#include "common/stream.h"
-class SaveFile : public Common::ReadStream, public Common::WriteStream {
+/**
+ * A class which allows game engines to load game state data.
+ * That typically means "save games", but also includes things like the
+ * IQ points in Indy3.
+ *
+ * @todo Add error checking abilities.
+ * @todo Change base class to SeekableReadStream; or alternatively,
+ * add a simple 'skip()' method which would allow skipping
+ * a number of bytes in the savefile.
+ */
+class InSaveFile : public Common::ReadStream {
public:
- virtual ~SaveFile() {}
+ virtual ~InSaveFile() {}
+};
- virtual bool isOpen() const = 0;
+/**
+ * A class which allows game engines to save game state data.
+ * That typically means "save games", but also includes things like the
+ * IQ points in Indy3.
+ *
+ * @todo Add error checking abilities.
+ */
+class OutSaveFile : public Common::WriteStream {
+public:
+ virtual ~OutSaveFile() {}
+};
+
+/**
+ * Convenience intermediate class, to be removed.
+ */
+class SaveFile : public InSaveFile, public OutSaveFile {
+public:
};
class SaveFileManager {
@@ -40,13 +67,19 @@ public:
virtual ~SaveFileManager() {}
/**
- * Open the file with name filename in the given directory for saving or loading.
+ * Open the file with name filename in the given directory for saving.
* @param filename the filename
- * @param directory the directory
- * @param saveOrLoad true for saving, false for loading
- * @return pointer to a SaveFile object
+ * @return pointer to a SaveFile object, or NULL if an error occured.
*/
- virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad) = 0;
+ virtual OutSaveFile *openForSaving(const char *filename) = 0;
+
+ /**
+ * Open the file with name filename in the given directory for loading.
+ * @param filename the filename
+ * @return pointer to a SaveFile object, or NULL if an error occured.
+ */
+ virtual InSaveFile *openForLoading(const char *filename) = 0;
+
virtual void listSavefiles(const char * /* prefix */, bool *marks, int num) = 0;
/** Get the path to the save game directory. */
@@ -55,11 +88,12 @@ public:
class DefaultSaveFileManager : public SaveFileManager {
public:
- virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad);
+ virtual OutSaveFile *openForSaving(const char *filename);
+ virtual InSaveFile *openForLoading(const char *filename);
virtual void listSavefiles(const char * /* prefix */, bool *marks, int num);
protected:
- virtual SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
+ SaveFile *makeSaveFile(const char *filename, bool saveOrLoad);
};
#endif