From 590c6ede63d9fa61d2b05ce74596b043f5c79bc8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 23 May 2011 19:09:34 +0200 Subject: BACKENDS: Move SCUMMVM_SAVEPATH env var handling to POSIX savefile manager --- backends/saves/posix/posix-saves.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'backends/saves/posix/posix-saves.cpp') diff --git a/backends/saves/posix/posix-saves.cpp b/backends/saves/posix/posix-saves.cpp index d82f8a1845..37545c77c2 100644 --- a/backends/saves/posix/posix-saves.cpp +++ b/backends/saves/posix/posix-saves.cpp @@ -21,7 +21,8 @@ */ -// Enable mkdir +// Enable getenv, mkdir and time.h stuff +#define FORBIDDEN_SYMBOL_EXCEPTION_getenv #define FORBIDDEN_SYMBOL_EXCEPTION_mkdir #define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h @@ -59,6 +60,27 @@ POSIXSaveFileManager::POSIXSaveFileManager() { savePath += "/" DEFAULT_SAVE_PATH; ConfMan.registerDefault("savepath", savePath); } + + // The user can override the savepath with the SCUMMVM_SAVEPATH + // environment variable. This is weaker than a --savepath on the + // command line, but overrides the default savepath. + // + // To ensure that the command line option (if given) has precedence, + // we only set the value in the transient domain if it is not + // yet present there. + if (!ConfMan.hasKey("savepath", Common::ConfigManager::kTransientDomain)) { + const char *dir = getenv("SCUMMVM_SAVEPATH"); + if (dir && *dir && strlen(dir) < MAXPATHLEN) { + Common::FSNode saveDir(dir); + if (!saveDir.exists()) { + warning("Ignoring non-existent SCUMMVM_SAVEPATH '%s'", dir); + } else if (!saveDir.isWritable()) { + warning("Ignoring non-writable SCUMMVM_SAVEPATH '%s'", dir); + } else { + ConfMan.set("savepath", dir, Common::ConfigManager::kTransientDomain); + } + } + } #endif } /* -- cgit v1.2.3