Added a UserThemeDirectory setting for relocating the user theme directory

This commit is contained in:
Leon Styhre 2023-04-06 11:40:32 +02:00
parent 6139c96d4c
commit 2209c384aa
4 changed files with 77 additions and 15 deletions

View file

@ -163,7 +163,31 @@ GuiThemeDownloader::GuiThemeDownloader(std::function<void()> updateCallback)
std::promise<bool>().swap(mPromise);
mFuture = mPromise.get_future();
mThemeDirectory = Utils::FileSystem::getHomePath() + "/.emulationstation/themes/";
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() +
"/.emulationstation/themes"};
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))};
#if defined(_WIN64)
mThemeDirectory = Utils::String::replace(mThemeDirectory, "\\", "/");
#endif
if (userThemeDirSetting == "") {
mThemeDirectory = defaultUserThemeDir;
}
else if (Utils::FileSystem::isDirectory(userThemeDirSetting) ||
Utils::FileSystem::isSymlink(userThemeDirSetting)) {
mThemeDirectory = userThemeDirSetting;
}
else {
LOG(LogWarning) << "GuiThemeDownloader: Requested user theme directory \""
<< userThemeDirSetting
<< "\" does not exist or is not a directory, reverting to \""
<< defaultUserThemeDir << "\"";
mThemeDirectory = defaultUserThemeDir;
}
if (mThemeDirectory.back() != '/')
mThemeDirectory.append("/");
}
GuiThemeDownloader::~GuiThemeDownloader()

View file

@ -673,19 +673,32 @@ int main(int argc, char* argv[])
}
}
// Create the themes directory in the application home folder. This is not required but
// is rather a convenience in case the user wants to add additional themes.
const std::string themesDir {Utils::FileSystem::getHomePath() + "/.emulationstation/themes"};
if (!Utils::FileSystem::exists(themesDir)) {
// Create the themes directory in the application home directory (or elsewhere if the
// UserThemeDirectory setting has been defined).
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() +
"/.emulationstation/themes"};
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))};
#if defined(_WIN64)
LOG(LogInfo) << "Creating themes directory \""
<< Utils::String::replace(themesDir, "/", "\\") << "\"...";
#else
LOG(LogInfo) << "Creating themes directory \"" << themesDir << "\"...";
userThemeDirSetting = Utils::String::replace(userThemeDirSetting, "\\", "/");
#endif
Utils::FileSystem::createDirectory(themesDir);
if (!Utils::FileSystem::exists(themesDir)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?\n";
std::string userThemeDirectory;
if (userThemeDirSetting == "")
userThemeDirectory = defaultUserThemeDir;
else
userThemeDirectory = userThemeDirSetting;
if (!Utils::FileSystem::exists(userThemeDirectory)) {
#if defined(_WIN64)
LOG(LogInfo) << "Creating user theme directory \""
<< Utils::String::replace(userThemeDirectory, "/", "\\") << "\"...";
#else
LOG(LogInfo) << "Creating themes directory \"" << userThemeDirectory << "\"...";
#endif
Utils::FileSystem::createDirectory(userThemeDirectory);
if (!Utils::FileSystem::exists(userThemeDirectory)) {
LOG(LogWarning) << "Couldn't create directory, permission problems?";
}
}

View file

@ -316,6 +316,7 @@ void Settings::setDefaults()
mStringMap["OpenGLVersion"] = {"", ""};
mStringMap["ROMDirectory"] = {"", ""};
mStringMap["UIMode_passkey"] = {"uuddlrlrba", "uuddlrlrba"};
mStringMap["UserThemeDirectory"] = {"", ""};
mIntMap["LottieMaxFileCache"] = {150, 150};
mIntMap["LottieMaxTotalCache"] = {1024, 1024};
mIntMap["ScraperConnectionTimeout"] = {30, 30};

View file

@ -771,8 +771,32 @@ void ThemeData::populateThemeSets()
sThemeSets.clear();
LOG(LogInfo) << "Checking for available theme sets...";
// Check for themes first under the home directory, then under the data installation
// directory (Unix only) and last under the ES-DE binary directory.
// Check for themes first under the user theme directory (which is in the ES-DE home directory
// by default), then under the data installation directory (Unix only) and last under the ES-DE
// binary directory.
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() +
"/.emulationstation/themes"};
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath(
Settings::getInstance()->getString("UserThemeDirectory"))};
#if defined(_WIN64)
userThemeDirSetting = Utils::String::replace(userThemeDirSetting, "\\", "/");
#endif
std::string userThemeDirectory;
if (userThemeDirSetting == "") {
userThemeDirectory = defaultUserThemeDir;
}
else if (Utils::FileSystem::isDirectory(userThemeDirSetting) ||
Utils::FileSystem::isSymlink(userThemeDirSetting)) {
userThemeDirectory = userThemeDirSetting;
LOG(LogInfo) << "Setting user theme directory to \"" << userThemeDirectory << "\"";
}
else {
LOG(LogWarning) << "Requested user theme directory \"" << userThemeDirSetting
<< "\" does not exist or is not a directory, reverting to \""
<< defaultUserThemeDir << "\"";
userThemeDirectory = defaultUserThemeDir;
}
#if defined(__unix__) || defined(__APPLE__)
#if defined(APPIMAGE_BUILD)
@ -790,7 +814,7 @@ void ThemeData::populateThemeSets()
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
Utils::FileSystem::getProgramDataPath() + "/themes",
#endif
Utils::FileSystem::getHomePath() + "/.emulationstation/themes"
userThemeDirectory
};
for (size_t i {0}; i < pathCount; ++i) {