From aa083256ec05ee43d9f1977ca2178cacdfb25ae3 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 7 Dec 2019 14:08:33 +0000 Subject: [PATCH] SDL: Simplify implementations of getDefaultConfigFileName() --- backends/platform/samsungtv/samsungtv.cpp | 9 ++++----- backends/platform/samsungtv/samsungtv.h | 3 +-- backends/platform/sdl/macosx/macosx.cpp | 23 ++++++++++++++++++----- backends/platform/sdl/macosx/macosx.h | 2 +- backends/platform/sdl/posix/posix.cpp | 21 +++++++-------------- backends/platform/sdl/posix/posix.h | 11 ----------- backends/platform/sdl/ps3/ps3.cpp | 6 +----- backends/platform/sdl/ps3/ps3.h | 8 -------- backends/platform/sdl/psp2/psp2.cpp | 6 +----- backends/platform/sdl/psp2/psp2.h | 8 -------- backends/platform/sdl/switch/switch.cpp | 8 -------- backends/platform/sdl/switch/switch.h | 9 --------- 12 files changed, 33 insertions(+), 81 deletions(-) diff --git a/backends/platform/samsungtv/samsungtv.cpp b/backends/platform/samsungtv/samsungtv.cpp index bee71b7ff29..5a103793fae 100644 --- a/backends/platform/samsungtv/samsungtv.cpp +++ b/backends/platform/samsungtv/samsungtv.cpp @@ -31,11 +31,6 @@ #include "backends/fs/posix/posix-fs.h" #include "common/textconsole.h" -OSystem_SDL_SamsungTV::OSystem_SDL_SamsungTV() - : - OSystem_POSIX("/mtd_rwarea/.scummvmrc") { -} - void OSystem_SDL_SamsungTV::initBackend() { // Create the savefile manager if (_savefileManager == 0) { @@ -63,6 +58,10 @@ void OSystem_SDL_SamsungTV::fatalError() { for (;;) {} } +Common::String OSystem_SDL_SamsungTV::getDefaultConfigFileName() { + return "/mtd_rwarea/.scummvmrc"; +} + Common::String OSystem_SDL_SamsungTV::getDefaultLogFileName() { if (!Posix::assureDirectoryExists("/mtd_ram", nullptr)) { return Common::String(); diff --git a/backends/platform/samsungtv/samsungtv.h b/backends/platform/samsungtv/samsungtv.h index aad946aa0ac..0b98297d793 100644 --- a/backends/platform/samsungtv/samsungtv.h +++ b/backends/platform/samsungtv/samsungtv.h @@ -29,13 +29,12 @@ class OSystem_SDL_SamsungTV : public OSystem_POSIX { public: - OSystem_SDL_SamsungTV(); - virtual void initBackend(); virtual void quit(); virtual void fatalError(); protected: + virtual Common::String getDefaultConfigFileName(); virtual Common::String getDefaultLogFileName(); }; diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index 1c47401c13e..1545d9ab613 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -45,11 +45,6 @@ #include "ApplicationServices/ApplicationServices.h" // for LSOpenFSRef #include "CoreFoundation/CoreFoundation.h" // for CF* stuff -OSystem_MacOSX::OSystem_MacOSX() - : - OSystem_POSIX("Library/Preferences/ScummVM Preferences") { -} - OSystem_MacOSX::~OSystem_MacOSX() { releaseMenu(); } @@ -205,6 +200,24 @@ Common::String OSystem_MacOSX::getSystemLanguage() const { #endif // USE_DETECTLANG } +Common::String OSystem_MacOSX::getDefaultConfigFileName() { + const Common::String baseConfigName = "Library/Preferences/ScummVM Preferences"; + + Common::String configFile; + + Common::String prefix = getenv("HOME"); + + if (!prefix.empty() && (prefix.size() + 1 + baseConfigName.size()) < MAXPATHLEN) { + configFile = prefix; + configFile += '/'; + configFile += baseConfigName; + } else { + configFile = baseConfigName; + } + + return configFile; +} + Common::String OSystem_MacOSX::getDefaultLogFileName() { const char *prefix = getenv("HOME"); if (prefix == nullptr) { diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index b860b71ad86..e4b5b2a6316 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -27,7 +27,6 @@ class OSystem_MacOSX : public OSystem_POSIX { public: - OSystem_MacOSX(); ~OSystem_MacOSX(); virtual bool hasFeature(Feature f); @@ -50,6 +49,7 @@ public: virtual Common::String getScreenshotsPath(); protected: + virtual Common::String getDefaultConfigFileName(); virtual Common::String getDefaultLogFileName(); // Override createAudioCDManager() to get our Mac-specific diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index b9838498a48..b6afd36ba68 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -60,11 +60,6 @@ #endif extern char **environ; -OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName) - : - _baseConfigName(baseConfigName) { -} - void OSystem_POSIX::init() { // Initialze File System Factory _fsFactory = new POSIXFilesystemFactory(); @@ -108,16 +103,15 @@ bool OSystem_POSIX::hasFeature(Feature f) { } Common::String OSystem_POSIX::getDefaultConfigFileName() { + const Common::String baseConfigName = "scummvm.ini"; + Common::String configFile; Common::String prefix; -#ifdef MACOSX - prefix = getenv("HOME"); -#elif !defined(SAMSUNGTV) - const char *envVar; + // Our old configuration file path for POSIX systems was ~/.scummvmrc. // If that file exists, we still use it. - envVar = getenv("HOME"); + const char *envVar = getenv("HOME"); if (envVar && *envVar) { configFile = envVar; configFile += '/'; @@ -152,14 +146,13 @@ Common::String OSystem_POSIX::getDefaultConfigFileName() { if (!prefix.empty() && Posix::assureDirectoryExists("scummvm", prefix.c_str())) { prefix += "/scummvm"; } -#endif - if (!prefix.empty() && (prefix.size() + 1 + _baseConfigName.size()) < MAXPATHLEN) { + if (!prefix.empty() && (prefix.size() + 1 + baseConfigName.size()) < MAXPATHLEN) { configFile = prefix; configFile += '/'; - configFile += _baseConfigName; + configFile += baseConfigName; } else { - configFile = _baseConfigName; + configFile = baseConfigName; } return configFile; diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 5df6738d45c..41fdc35c99d 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -27,10 +27,6 @@ class OSystem_POSIX : public OSystem_SDL { public: - // Let the subclasses be able to change _baseConfigName in the constructor - OSystem_POSIX(Common::String baseConfigName = "scummvm.ini"); - virtual ~OSystem_POSIX() {} - virtual bool hasFeature(Feature f); virtual bool displayLogFile(); @@ -45,13 +41,6 @@ public: Common::String getScreenshotsPath() override; protected: - /** - * Base string for creating the default path and filename for the - * configuration file. This allows the Mac OS X subclass to override - * the config file path and name. - */ - Common::String _baseConfigName; - virtual Common::String getDefaultConfigFileName(); virtual Common::String getDefaultLogFileName(); diff --git a/backends/platform/sdl/ps3/ps3.cpp b/backends/platform/sdl/ps3/ps3.cpp index 78b02d7e2e3..9f77c035a26 100644 --- a/backends/platform/sdl/ps3/ps3.cpp +++ b/backends/platform/sdl/ps3/ps3.cpp @@ -45,10 +45,6 @@ int access(const char *pathname, int mode) { return 0; } -OSystem_PS3::OSystem_PS3(Common::String baseConfigName) - : _baseConfigName(baseConfigName) { -} - void OSystem_PS3::init() { // Initialze File System Factory _fsFactory = new PS3FilesystemFactory(); @@ -75,7 +71,7 @@ void OSystem_PS3::initBackend() { } Common::String OSystem_PS3::getDefaultConfigFileName() { - return PREFIX "/" + _baseConfigName; + return PREFIX "/scummvm.ini"; } Common::String OSystem_PS3::getDefaultLogFileName() { diff --git a/backends/platform/sdl/ps3/ps3.h b/backends/platform/sdl/ps3/ps3.h index a0c0d80b0e4..766cf5f2f2d 100644 --- a/backends/platform/sdl/ps3/ps3.h +++ b/backends/platform/sdl/ps3/ps3.h @@ -27,18 +27,10 @@ class OSystem_PS3 : public OSystem_SDL { public: - // Let the subclasses be able to change _baseConfigName in the constructor - OSystem_PS3(Common::String baseConfigName = "scummvm.ini"); - virtual ~OSystem_PS3() {} - virtual void init(); virtual void initBackend(); protected: - // Base string for creating the default path and filename - // for the configuration file - Common::String _baseConfigName; - virtual Common::String getDefaultConfigFileName(); virtual Common::String getDefaultLogFileName(); }; diff --git a/backends/platform/sdl/psp2/psp2.cpp b/backends/platform/sdl/psp2/psp2.cpp index bb26694dfdb..f87d8f809fc 100644 --- a/backends/platform/sdl/psp2/psp2.cpp +++ b/backends/platform/sdl/psp2/psp2.cpp @@ -49,10 +49,6 @@ int access(const char *pathname, int mode) { return 0; } -OSystem_PSP2::OSystem_PSP2(Common::String baseConfigName) - : _baseConfigName(baseConfigName) { -} - void OSystem_PSP2::init() { #if __PSP2_DEBUG__ @@ -172,7 +168,7 @@ void OSystem_PSP2::logMessage(LogMessageType::Type type, const char *message) { } Common::String OSystem_PSP2::getDefaultConfigFileName() { - return "ux0:data/scummvm/" + _baseConfigName; + return "ux0:data/scummvm/scummvm.ini"; } Common::String OSystem_PSP2::getDefaultLogFileName() { diff --git a/backends/platform/sdl/psp2/psp2.h b/backends/platform/sdl/psp2/psp2.h index a90272ba627..0b3be259501 100644 --- a/backends/platform/sdl/psp2/psp2.h +++ b/backends/platform/sdl/psp2/psp2.h @@ -30,10 +30,6 @@ class OSystem_PSP2 : public OSystem_SDL { public: - // Let the subclasses be able to change _baseConfigName in the constructor - OSystem_PSP2(Common::String baseConfigName = "scummvm.ini"); - virtual ~OSystem_PSP2() {} - virtual void init() override; virtual void initBackend() override; virtual bool hasFeature(Feature f) override; @@ -42,10 +38,6 @@ public: virtual void logMessage(LogMessageType::Type type, const char *message) override; protected: - // Base string for creating the default path and filename - // for the configuration file - Common::String _baseConfigName; - virtual Common::String getDefaultConfigFileName() override; virtual Common::String getDefaultLogFileName() override; }; diff --git a/backends/platform/sdl/switch/switch.cpp b/backends/platform/sdl/switch/switch.cpp index 1a3c5736080..120fb955fb5 100644 --- a/backends/platform/sdl/switch/switch.cpp +++ b/backends/platform/sdl/switch/switch.cpp @@ -30,10 +30,6 @@ #include "backends/fs/posix/posix-fs-factory.h" #include "backends/fs/posix/posix-fs.h" -OSystem_Switch::OSystem_Switch(Common::String baseConfigName) - : _baseConfigName(baseConfigName) { -} - void OSystem_Switch::init() { // Initialze File System Factory @@ -126,10 +122,6 @@ void OSystem_Switch::logMessage(LogMessageType::Type type, const char *message) printf("%s\n", message); } -Common::String OSystem_Switch::getDefaultConfigFileName() { - return _baseConfigName; -} - Common::String OSystem_Switch::getDefaultLogFileName() { return "scummvm.log"; } diff --git a/backends/platform/sdl/switch/switch.h b/backends/platform/sdl/switch/switch.h index 61b4f3c0585..2bdea6fe098 100644 --- a/backends/platform/sdl/switch/switch.h +++ b/backends/platform/sdl/switch/switch.h @@ -27,10 +27,6 @@ class OSystem_Switch : public OSystem_SDL { public: - // Let the subclasses be able to change _baseConfigName in the constructor - OSystem_Switch(Common::String baseConfigName = "scummvm.ini"); - virtual ~OSystem_Switch() {} - virtual void init() override; virtual void initBackend() override; virtual bool hasFeature(Feature f) override; @@ -39,11 +35,6 @@ public: virtual void logMessage(LogMessageType::Type type, const char *message) override; protected: - // Base string for creating the default path and filename - // for the configuration file - Common::String _baseConfigName; - - virtual Common::String getDefaultConfigFileName() override; virtual Common::String getDefaultLogFileName() override; };