From fe001b35b54185458e2e3fe6fcf81fe1a6848b81 Mon Sep 17 00:00:00 2001 From: Thunderforge Date: Mon, 20 Jun 2022 00:47:38 -0500 Subject: [PATCH] COMMON: Adding default iconspath functionality It's for macOS only right now. --- backends/platform/sdl/macosx/macosx.cpp | 15 +++++++++++++++ backends/platform/sdl/macosx/macosx.h | 2 +- backends/platform/sdl/posix/posix.cpp | 25 +++++++++++++++++++++++++ backends/platform/sdl/posix/posix.h | 1 + backends/platform/sdl/sdl.cpp | 10 ++++++++++ backends/platform/sdl/sdl.h | 2 +- gui/downloadiconsdialog.cpp | 6 ++++-- gui/gui-manager.cpp | 2 +- gui/options.cpp | 8 ++++---- 9 files changed, 62 insertions(+), 9 deletions(-) diff --git a/backends/platform/sdl/macosx/macosx.cpp b/backends/platform/sdl/macosx/macosx.cpp index 0809ab0d686..1c3ef7349f8 100644 --- a/backends/platform/sdl/macosx/macosx.cpp +++ b/backends/platform/sdl/macosx/macosx.cpp @@ -261,6 +261,21 @@ Common::String OSystem_MacOSX::getDefaultLogFileName() { return Common::String(prefix) + "/Library/Logs/scummvm.log"; } +Common::String OSystem_MacOSX::getDefaultIconPath() { + const char *prefix = getenv("HOME"); + if (prefix == nullptr) { + return Common::String(); + } + + const Common::String appSupportFolder = Common::String(prefix) + "/Library/Application Support/ScummVM"; + + if (!Posix::assureDirectoryExists(appSupportFolder)) { + return Common::String(); + } + + return appSupportFolder; +} + Common::String OSystem_MacOSX::getScreenshotsPath() { // If the user has configured a screenshots path, use it const Common::String path = OSystem_SDL::getScreenshotsPath(); diff --git a/backends/platform/sdl/macosx/macosx.h b/backends/platform/sdl/macosx/macosx.h index 858e5865191..39b5be253da 100644 --- a/backends/platform/sdl/macosx/macosx.h +++ b/backends/platform/sdl/macosx/macosx.h @@ -48,7 +48,7 @@ public: GraphicsManagerType getDefaultGraphicsManager() const override; #endif - //Screenshots + Common::String getDefaultIconPath() override; Common::String getScreenshotsPath() override; protected: diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index fc68bf016b6..4577912ea74 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -235,6 +235,31 @@ Common::String OSystem_POSIX::getXdgUserDir(const char *name) { return directoryPath; } +Common::String OSystem_POSIX::getDefaultIconPath() { + Common::String iconsPath; + + // On POSIX systems we follow the XDG Base Directory Specification for + // where to store files. The version we based our code upon can be found + // over here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html + const char *prefix = getenv("XDG_CACHE_HOME"); + if (prefix == nullptr || !*prefix) { + prefix = getenv("HOME"); + if (prefix == nullptr) { + return Common::String(); + } + + iconsPath = ".cache/"; + } + + iconsPath += "scummvm/icons"; + + if (!Posix::assureDirectoryExists(iconsPath, prefix)) { + return Common::String(); + } + + return iconsPath; +} + Common::String OSystem_POSIX::getScreenshotsPath() { // If the user has configured a screenshots path, use it const Common::String path = OSystem_SDL::getScreenshotsPath(); diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h index 3e8028e020e..2bf745873b8 100644 --- a/backends/platform/sdl/posix/posix.h +++ b/backends/platform/sdl/posix/posix.h @@ -35,6 +35,7 @@ public: void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override; + Common::String getDefaultIconPath() override; Common::String getScreenshotsPath() override; protected: diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 3f1fd57d305..f87b89f6e88 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -302,6 +302,8 @@ void OSystem_SDL::initBackend() { _presence = new DiscordPresence(); #endif + ConfMan.registerDefault("iconspath", this->getDefaultIconPath()); + _inited = true; BaseBackend::initBackend(); @@ -760,6 +762,14 @@ Common::SaveFileManager *OSystem_SDL::getSavefileManager() { #endif } +//Not specified in base class +Common::String OSystem_SDL::getDefaultIconPath() { + Common::String path = ConfMan.get("iconspath"); + if (!path.empty() && !path.hasSuffix("/")) + path += "/"; + return path; +} + //Not specified in base class Common::String OSystem_SDL::getScreenshotsPath() { Common::String path = ConfMan.get("screenshotpath"); diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 87c73522c5a..b4f52c3df49 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -90,7 +90,7 @@ public: Common::TimerManager *getTimerManager() override; Common::SaveFileManager *getSavefileManager() override; - //Screenshots + virtual Common::String getDefaultIconPath(); virtual Common::String getScreenshotsPath(); #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS) diff --git a/gui/downloadiconsdialog.cpp b/gui/downloadiconsdialog.cpp index 5c07714ed00..063f1da0445 100644 --- a/gui/downloadiconsdialog.cpp +++ b/gui/downloadiconsdialog.cpp @@ -369,7 +369,8 @@ void DownloadIconsDialog::setError(Common::U32String &msg) { } void DownloadIconsDialog::calculateList() { - if (!ConfMan.hasKey("iconspath")) { + Common::String iconsPath = ConfMan.get("iconspath"); + if (iconsPath.empty()) { Common::U32String str(_("ERROR: No icons path set")); setError(str); return; @@ -377,7 +378,8 @@ void DownloadIconsDialog::calculateList() { // Scan all files in iconspath and remove present ones from the // donwloaded files list - Common::FSDirectory *iconDir = new Common::FSDirectory(ConfMan.get("iconspath")); + Common::FSDirectory *iconDir = new Common::FSDirectory(iconsPath); + Common::ArchiveMemberList iconFiles; iconDir->listMatchingMembers(iconFiles, "gui-icons*.dat"); diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index 0ed7abdfdb4..803051596d0 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -121,7 +121,7 @@ void GuiManager::initIconsSet() { _iconsSet.clear(); - if (ConfMan.hasKey("iconspath")) { + if (!ConfMan.get("iconspath").empty()) { Common::FSDirectory *iconDir = new Common::FSDirectory(ConfMan.get("iconspath")); Common::ArchiveMemberList iconFiles; diff --git a/gui/options.cpp b/gui/options.cpp index ea04dc29985..51a1b8a315d 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -2216,7 +2216,7 @@ void GlobalOptionsDialog::build() { setPath(_savePath, "savepath", _("Default")); setPath(_themePath, "themepath", _c("None", "path")); - setPath(_iconPath, "iconspath", _c("None", "path")); + setPath(_iconPath, "iconspath", _("Default")); setPath(_extraPath, "extrapath", _c("None", "path")); #ifdef DYNAMIC_MODULES @@ -2304,7 +2304,7 @@ void GlobalOptionsDialog::addPathsControls(GuiObject *boss, const Common::String new ButtonWidget(boss, prefix + "IconButton", _("Icon Path:"), Common::U32String(), kChooseIconDirCmd); else new ButtonWidget(boss, prefix + "IconButton", _c("Icon Path:", "lowres"), Common::U32String(), kChooseIconDirCmd); - _iconPath = new StaticTextWidget(boss, prefix + "IconPath", _c("None", "path")); + _iconPath = new StaticTextWidget(boss, prefix + "IconPath", _c("Default", "path")); _iconPathClearButton = addClearButton(boss, prefix + "IconPathClearButton", kIconPathClearCmd); @@ -2709,7 +2709,7 @@ void GlobalOptionsDialog::apply() { changePath(_savePath, "savepath", _("Default")); changePath(_themePath, "themepath", _c("None", "path")); - changePath(_iconPath, "iconspath", _c("None", "path")); + changePath(_iconPath, "iconspath", _("Default")); changePath(_extraPath, "extrapath", _c("None", "path")); #ifdef DYNAMIC_MODULES @@ -3001,7 +3001,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 _themePath->setLabel(_c("None", "path")); break; case kIconPathClearCmd: - _iconPath->setLabel(_c("None", "path")); + _iconPath->setLabel(_("Default")); break; case kExtraPathClearCmd: _extraPath->setLabel(_c("None", "path"));