From b560429a2070e2c6e2708a9254bfd5098d8123f8 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 21 Jun 2020 21:08:54 +0200 Subject: [PATCH] Moved the CMake install prefix function to FileSystemUtil and implemented the same logic also for theme loading. --- NEWS.md | 2 ++ es-core/src/ThemeData.cpp | 4 +++- es-core/src/resources/ResourceManager.cpp | 23 ++++------------------- es-core/src/utils/FileSystemUtil.cpp | 22 ++++++++++++++++++++++ es-core/src/utils/FileSystemUtil.h | 1 + 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index bbe6edcab..53e668674 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,8 @@ v1.0.0 * GUI-configurable option to sort favorite games on the top of the game lists (favorites marked with stars) * Added new component GuiComplexTextEditPopup to handle changes to configuration file entries and similar * Speed improvements and optimizations, the application now starts faster and feels more responsive +* Moved all resources to a subdirectory structure and enabled the CMake install prefix variable to generate the resources search path +* Changed theme directory to the install prefix (e.g. /usr/local/share/emulationstation/themes) with themes in the home directory taking precedence * Refactoring, cleanup and documentation of the source code, removal of deprecated files etc. * All required fonts bundled with the application, no dependencies on the OS to provide them any longer * License files included for all the libraries and resources that are bundled with the application diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index ac323522b..2278ee329 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -592,10 +592,12 @@ std::map ThemeData::getThemeSets() { std::map sets; + // Check for themes under the data installation directory (install prefix), as well + // as under the user home directory. static const size_t pathCount = 2; std::string paths[pathCount] = { - "/etc/emulationstation/themes", + Utils::FileSystem::getInstallPrefixPath() + "/emulationstation/themes", Utils::FileSystem::getHomePath() + "/.emulationstation/themes" }; diff --git a/es-core/src/resources/ResourceManager.cpp b/es-core/src/resources/ResourceManager.cpp index 1d9d4706c..1d35fcbf2 100644 --- a/es-core/src/resources/ResourceManager.cpp +++ b/es-core/src/resources/ResourceManager.cpp @@ -10,18 +10,6 @@ #include "utils/FileSystemUtil.h" #include -#ifdef ES_INSTALL_PREFIX -std::string installPrefix = ES_INSTALL_PREFIX; -#else -std::string installPrefix = "/usr/local"; -#endif - -#ifdef ES_DATAROOTDIR -std::string dataRootDir = ES_DATAROOTDIR; -#else -std::string dataRootDir = "share"; -#endif - auto array_deleter = [](unsigned char* p) { delete[] p; }; auto nop_deleter = [](unsigned char* /*p*/) { }; @@ -50,13 +38,10 @@ std::string ResourceManager::getResourcePath(const std::string& path) const if (Utils::FileSystem::exists(test)) return test; - // Check under the data installation directory. - // The base directory is the value set for CMAKE_INSTALL_DIRECTORY during build. - // The datarootdir directory is the value set for CMAKE_INSTALL_DATAROOTDIR during build. - // If not defined, the default prefix path '/usr/local' and the default datarootdir - // directory 'share' will be used, i.e. '/usr/local/share'. - test = installPrefix + "/" + dataRootDir + "/emulationstation/resources/" + &path[2]; - if (Utils::FileSystem::exists(test)) + // Check under the data installation directory (install prefix). + test = Utils::FileSystem::getInstallPrefixPath() + + "/emulationstation/resources/" + &path[2]; + if (Utils::FileSystem::exists(test)) return test; } diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 06028e6ef..821d5fb4a 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -21,6 +21,23 @@ #include #endif // _WIN32 +// Try to ascertain the install prefix as defined when CMake was run. +// The installPrefix directory is the value set for CMAKE_INSTALL_DIRECTORY during build. +// The datarootdir directory is the value set for CMAKE_INSTALL_DATAROOTDIR during build. +// If not defined, the default prefix path '/usr/local' and the default datarootdir +// directory 'share' will be used, i.e. combining to '/usr/local/share'. +#ifdef ES_INSTALL_PREFIX +std::string installPrefix = ES_INSTALL_PREFIX; +#else +std::string installPrefix = "/usr/local"; +#endif + +#ifdef ES_DATAROOTDIR +std::string dataRootDir = ES_DATAROOTDIR; +#else +std::string dataRootDir = "share"; +#endif + namespace Utils { namespace FileSystem @@ -221,6 +238,11 @@ namespace Utils } // getExePath + std::string getInstallPrefixPath() + { + return installPrefix + "/" + dataRootDir; + } + std::string getPreferredPath(const std::string& _path) { std::string path = _path; diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index db45a1c53..13e2bf959 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -18,6 +18,7 @@ namespace Utils std::string getCWDPath (); void setExePath (const std::string& _path); std::string getExePath (); + std::string getInstallPrefixPath (); std::string getPreferredPath (const std::string& _path); std::string getGenericPath (const std::string& _path); std::string getEscapedPath (const std::string& _path);