mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Changed ThemeData::populateThemes() to use std::filesystem::path
This commit is contained in:
parent
932cb60027
commit
0a2b9f8595
|
@ -667,73 +667,61 @@ void ThemeData::populateThemes()
|
||||||
// Check for themes first under the user theme directory (which is in the ES-DE home 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
|
// by default), then under the data installation directory (Unix only) and last under the ES-DE
|
||||||
// binary directory.
|
// binary directory.
|
||||||
const std::string defaultUserThemeDir {Utils::FileSystem::getHomePath() +
|
const std::filesystem::path defaultUserThemeDir {
|
||||||
"/.emulationstation/themes"};
|
Utils::FileSystem::getESDataDirectory().append("themes")};
|
||||||
std::string userThemeDirSetting {Utils::FileSystem::expandHomePath(
|
const std::filesystem::path userThemeDirSetting {Utils::FileSystem::expandHomePath(
|
||||||
Settings::getInstance()->getString("UserThemeDirectory"))};
|
Settings::getInstance()->getString("UserThemeDirectory"))};
|
||||||
#if defined(_WIN64)
|
std::filesystem::path userThemeDirectory;
|
||||||
userThemeDirSetting = Utils::String::replace(userThemeDirSetting, "\\", "/");
|
|
||||||
#endif
|
|
||||||
std::string userThemeDirectory;
|
|
||||||
|
|
||||||
if (userThemeDirSetting == "") {
|
if (userThemeDirSetting.empty()) {
|
||||||
userThemeDirectory = defaultUserThemeDir;
|
userThemeDirectory = defaultUserThemeDir;
|
||||||
}
|
}
|
||||||
else if (Utils::FileSystem::isDirectory(userThemeDirSetting) ||
|
else if (Utils::FileSystem::isDirectorySTD(userThemeDirSetting) ||
|
||||||
Utils::FileSystem::isSymlink(userThemeDirSetting)) {
|
Utils::FileSystem::isSymlinkSTD(userThemeDirSetting)) {
|
||||||
userThemeDirectory = userThemeDirSetting;
|
userThemeDirectory = userThemeDirSetting;
|
||||||
#if defined(_WIN64)
|
LOG(LogInfo) << "Setting user theme directory to \"" << userThemeDirectory.string() << "\"";
|
||||||
LOG(LogInfo) << "Setting user theme directory to \""
|
|
||||||
<< Utils::String::replace(userThemeDirectory, "/", "\\") << "\"";
|
|
||||||
#else
|
|
||||||
LOG(LogInfo) << "Setting user theme directory to \"" << userThemeDirectory << "\"";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG(LogWarning) << "Requested user theme directory \"" << userThemeDirSetting
|
LOG(LogWarning) << "Requested user theme directory \"" << userThemeDirSetting.string()
|
||||||
<< "\" does not exist or is not a directory, reverting to \""
|
<< "\" does not exist or is not a directory, reverting to \""
|
||||||
<< defaultUserThemeDir << "\"";
|
<< defaultUserThemeDir.string() << "\"";
|
||||||
userThemeDirectory = defaultUserThemeDir;
|
userThemeDirectory = defaultUserThemeDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
const std::vector<std::string> themePaths {
|
const std::vector<std::filesystem::path> themePaths {
|
||||||
Utils::FileSystem::getProgramDataPath().string() + "/themes", userThemeDirectory};
|
Utils::FileSystem::getProgramDataPath().append("themes"), userThemeDirectory};
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
const std::vector<std::string> themePaths {
|
const std::vector<std::filesystem::path> themePaths {
|
||||||
Utils::FileSystem::getExePath() + "/themes",
|
Utils::FileSystem::getExePathSTD().append("themes"),
|
||||||
Utils::FileSystem::getExePath() + "/../Resources/themes", userThemeDirectory};
|
Utils::FileSystem::getExePathSTD().parent_path().append("Resources").append("themes"),
|
||||||
#elif defined(_WIN64) || defined(APPIMAGE_BUILD)
|
|
||||||
const std::vector<std::string> themePaths {Utils::FileSystem::getExePath() + "/themes",
|
|
||||||
userThemeDirectory};
|
userThemeDirectory};
|
||||||
|
#elif defined(_WIN64) || defined(APPIMAGE_BUILD)
|
||||||
|
const std::vector<std::filesystem::path> themePaths {
|
||||||
|
Utils::FileSystem::getExePathSTD().append("themes"), userThemeDirectory};
|
||||||
#else
|
#else
|
||||||
const std::vector<std::string> themePaths {
|
const std::vector<std::filesystem::path> themePaths {
|
||||||
Utils::FileSystem::getExePath() + "/themes",
|
Utils::FileSystem::getExePathSTD().append("themes"),
|
||||||
Utils::FileSystem::getProgramDataPath().string() + "/themes", userThemeDirectory};
|
Utils::FileSystem::getProgramDataPath().append("themes"), userThemeDirectory};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (auto path : themePaths) {
|
for (auto path : themePaths) {
|
||||||
if (!Utils::FileSystem::isDirectory(path))
|
if (!Utils::FileSystem::isDirectorySTD(path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(path)};
|
Utils::FileSystem::FileList dirContent {Utils::FileSystem::getDirContentSTD(path)};
|
||||||
|
|
||||||
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
for (Utils::FileSystem::FileList::const_iterator it = dirContent.cbegin();
|
||||||
it != dirContent.cend(); ++it) {
|
it != dirContent.cend(); ++it) {
|
||||||
if (Utils::FileSystem::isDirectory(*it)) {
|
if (Utils::FileSystem::isDirectorySTD(*it)) {
|
||||||
const std::string themeDirName {Utils::FileSystem::getFileName(*it)};
|
const std::string themeDirName {Utils::FileSystem::getFileNameSTD(*it).string()};
|
||||||
if (themeDirName == "themes-list" ||
|
if (themeDirName == "themes-list" ||
|
||||||
(themeDirName.length() >= 8 &&
|
(themeDirName.length() >= 8 &&
|
||||||
Utils::String::toLower(themeDirName.substr(themeDirName.length() - 8, 8)) ==
|
Utils::String::toLower(themeDirName.substr(themeDirName.length() - 8, 8)) ==
|
||||||
"disabled"))
|
"disabled"))
|
||||||
continue;
|
continue;
|
||||||
#if defined(_WIN64)
|
LOG(LogDebug) << "Loading theme capabilities for \"" << (*it).string() << "\"...";
|
||||||
LOG(LogDebug) << "Loading theme capabilities for \""
|
ThemeCapability capabilities {parseThemeCapabilities((*it).string())};
|
||||||
<< Utils::String::replace(*it, "/", "\\") << "\"...";
|
|
||||||
#else
|
|
||||||
LOG(LogDebug) << "Loading theme capabilities for \"" << *it << "\"...";
|
|
||||||
#endif
|
|
||||||
ThemeCapability capabilities {parseThemeCapabilities(*it)};
|
|
||||||
|
|
||||||
if (!capabilities.validTheme)
|
if (!capabilities.validTheme)
|
||||||
continue;
|
continue;
|
||||||
|
@ -742,12 +730,8 @@ void ThemeData::populateThemes()
|
||||||
if (capabilities.themeName != "")
|
if (capabilities.themeName != "")
|
||||||
themeName.append(" (\"").append(capabilities.themeName).append("\")");
|
themeName.append(" (\"").append(capabilities.themeName).append("\")");
|
||||||
|
|
||||||
#if defined(_WIN64)
|
LOG(LogInfo) << "Added theme \"" << (*it).string() << "\"" << themeName;
|
||||||
LOG(LogInfo) << "Added theme \"" << Utils::String::replace(*it, "/", "\\") << "\""
|
|
||||||
<< themeName;
|
|
||||||
#else
|
|
||||||
LOG(LogInfo) << "Added theme \"" << *it << "\"" << themeName;
|
|
||||||
#endif
|
|
||||||
int aspectRatios {0};
|
int aspectRatios {0};
|
||||||
if (capabilities.aspectRatios.size() > 0)
|
if (capabilities.aspectRatios.size() > 0)
|
||||||
aspectRatios = static_cast<int>(capabilities.aspectRatios.size()) - 1;
|
aspectRatios = static_cast<int>(capabilities.aspectRatios.size()) - 1;
|
||||||
|
@ -759,7 +743,7 @@ void ThemeData::populateThemes()
|
||||||
<< " and " << capabilities.transitions.size() << " transition"
|
<< " and " << capabilities.transitions.size() << " transition"
|
||||||
<< (capabilities.transitions.size() != 1 ? "s" : "");
|
<< (capabilities.transitions.size() != 1 ? "s" : "");
|
||||||
|
|
||||||
Theme theme {*it, capabilities};
|
Theme theme {(*it).string(), capabilities};
|
||||||
sThemes[theme.getName()] = theme;
|
sThemes[theme.getName()] = theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue