diff options
author | Max Horn | 2004-11-27 00:26:11 +0000 |
---|---|---|
committer | Max Horn | 2004-11-27 00:26:11 +0000 |
commit | 876e738dce6e3725ce28d8caf1520e71edfe09f0 (patch) | |
tree | 582797db161e7209b70fb3c563bdb5d5b3a2e060 /common | |
parent | d56cd17183008830b4fd50d903f7a0250928b691 (diff) | |
download | scummvm-rg350-876e738dce6e3725ce28d8caf1520e71edfe09f0.tar.gz scummvm-rg350-876e738dce6e3725ce28d8caf1520e71edfe09f0.tar.bz2 scummvm-rg350-876e738dce6e3725ce28d8caf1520e71edfe09f0.zip |
Moved Engine::getSavePath() to class SaveFileManager; removed the 'directory' parameter from SaveFileManager::openSavefile and listSavefiles (they always use getSavePath() now, which is what we did anyway)
svn-id: r15901
Diffstat (limited to 'common')
-rw-r--r-- | common/savefile.cpp | 43 | ||||
-rw-r--r-- | common/savefile.h | 12 |
2 files changed, 48 insertions, 7 deletions
diff --git a/common/savefile.cpp b/common/savefile.cpp index a25dae3dc5..07313bfcf5 100644 --- a/common/savefile.cpp +++ b/common/savefile.cpp @@ -21,6 +21,7 @@ #include "stdafx.h" #include "common/util.h" +#include "common/config-manager.h" #include "common/savefile.h" #include <stdio.h> @@ -30,6 +31,42 @@ #include <zlib.h> #endif +const char *SaveFileManager::getSavePath() const { + +#if defined(__PALM_OS__) + return SCUMMVM_SAVEPATH; +#else + + const char *dir = NULL; + +#if !defined(MACOS_CARBON) && !defined(_WIN32_WCE) + dir = getenv("SCUMMVM_SAVEPATH"); +#endif + + // If SCUMMVM_SAVEPATH was not specified, try to use game specific savepath from config + if (!dir || dir[0] == 0) { + dir = ConfMan.get("savepath").c_str(); + + // Work around a bug (#999122) in the original 0.6.1 release of + // ScummVM, which would insert a bad savepath value into config files. + if (0 == strcmp(dir, "None")) { + ConfMan.removeKey("savepath", ConfMan.getActiveDomain()); + ConfMan.flushToDisk(); + dir = ConfMan.get("savepath").c_str(); + } + } + +#ifdef _WIN32_WCE + if (dir[0] == 0) + dir = _gameDataPath.c_str(); +#endif + + assert(dir); + + return dir; +#endif +} + class StdioSaveFile : public SaveFile { private: FILE *fh; @@ -103,9 +140,9 @@ static void join_paths(const char *filename, const char *directory, strncat(buf, filename, bufsize-1); } -SaveFile *DefaultSaveFileManager::open_savefile(const char *filename, const char *directory, bool saveOrLoad) { +SaveFile *DefaultSaveFileManager::openSavefile(const char *filename, bool saveOrLoad) { char buf[256]; - join_paths(filename, directory, buf, sizeof(buf)); + join_paths(filename, getSavePath(), buf, sizeof(buf)); SaveFile *sf = makeSaveFile(buf, saveOrLoad); if (!sf->isOpen()) { delete sf; @@ -114,7 +151,7 @@ SaveFile *DefaultSaveFileManager::open_savefile(const char *filename, const char return sf; } -void DefaultSaveFileManager::list_savefiles(const char * /* prefix */, const char *directory, bool *marks, int num) { +void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) { memset(marks, true, num * sizeof(bool)); } diff --git a/common/savefile.h b/common/savefile.h index 4e2c21eaa5..f8b862f3ae 100644 --- a/common/savefile.h +++ b/common/savefile.h @@ -36,6 +36,7 @@ public: }; class SaveFileManager { + public: virtual ~SaveFileManager() {} @@ -46,14 +47,17 @@ public: * @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; + virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad) = 0; + virtual void listSavefiles(const char * /* prefix */, bool *marks, int num) = 0; + + /** Get the path to the save game directory. */ + virtual const char *getSavePath() const; }; 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); + virtual SaveFile *openSavefile(const char *filename, bool saveOrLoad); + virtual void listSavefiles(const char * /* prefix */, bool *marks, int num); protected: virtual SaveFile *makeSaveFile(const char *filename, bool saveOrLoad); |