From ffcb578fe766a812dd58f991829eee480cbed3e6 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 21 Aug 2020 21:49:45 +0200 Subject: [PATCH] (macOS) Updates to make ES find resources and themes within the application installation directory. --- es-core/src/ThemeData.cpp | 6 ++++-- es-core/src/resources/ResourceManager.cpp | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index a79d34067..0764ffe6b 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -603,14 +603,16 @@ std::map ThemeData::getThemeSets() // Check for themes first under the home directory, then under the data installation // directory (Unix only) and last under the ES executable directory. - #ifdef __unix__ + #if defined(__unix__) || defined(__APPLE__) static const size_t pathCount = 3; #else static const size_t pathCount = 2; #endif std::string paths[pathCount] = { Utils::FileSystem::getExePath() + "/themes", - #ifdef __unix__ + #if defined(__APPLE__) + Utils::FileSystem::getExePath() + "/../Resources/themes", + #elif defined(__unix__) Utils::FileSystem::getProgramDataPath() + "/themes", #endif Utils::FileSystem::getHomePath() + "/.emulationstation/themes" diff --git a/es-core/src/resources/ResourceManager.cpp b/es-core/src/resources/ResourceManager.cpp index 7cd3efdec..7d81b6f8f 100644 --- a/es-core/src/resources/ResourceManager.cpp +++ b/es-core/src/resources/ResourceManager.cpp @@ -44,8 +44,17 @@ std::string ResourceManager::getResourcePath(const std::string& path) const if (Utils::FileSystem::exists(testHome)) return testHome; + // For macOS, check in the ../Resources directory relative to the executable directory. + #if defined(__APPLE__) + std::string applePackagePath = + Utils::FileSystem::getExePath() + "/../Resources/resources/" + &path[2]; + + if (Utils::FileSystem::exists(applePackagePath)) { + return applePackagePath; + } + // Check under the data installation directory (Unix only). - #ifdef __unix__ + #elif defined(__unix__) std::string testDataPath; testDataPath = Utils::FileSystem::getProgramDataPath() + "/resources/" + &path[2]; @@ -56,9 +65,7 @@ std::string ResourceManager::getResourcePath(const std::string& path) const #endif // Check under the ES executable directory. - std::string testExePath; - - testExePath = Utils::FileSystem::getExePath() + "/resources/" + &path[2]; + std::string testExePath = Utils::FileSystem::getExePath() + "/resources/" + &path[2]; if (Utils::FileSystem::exists(testExePath)) { return testExePath; @@ -70,7 +77,9 @@ std::string ResourceManager::getResourcePath(const std::string& path) const LOG(LogError) << "Program resource missing: " << path; LOG(LogError) << "Tried to find the resource in the following locations:"; LOG(LogError) << testHome; - #ifdef __unix__ + #if defined(__APPLE__) + LOG(LogError) << applePackagePath; + #elif defined(__unix__) LOG(LogError) << testDataPath; #endif LOG(LogError) << testExePath;