Changed theme loading into a populateThemeSets function and created a separate getter function.

Also removed a deprecated theme check in the game directory.
This commit is contained in:
Leon Styhre 2022-06-11 18:34:53 +02:00
parent 0ef6a22248
commit 40bf018aaa
4 changed files with 21 additions and 26 deletions

View file

@ -1079,27 +1079,22 @@ std::string SystemData::getGamelistPath(bool forWrite) const
std::string SystemData::getThemePath() const
{
// Locations where we check for themes, in the following order:
// 1. [SYSTEM_PATH]/theme.xml
// 2. System theme from currently selected theme set [CURRENT_THEME_PATH]/[SYSTEM]/theme.xml
// 3. Default system theme from currently selected theme set [CURRENT_THEME_PATH]/theme.xml
// Check for the precence of [CURRENT_THEME_PATH]/[SYSTEM]/theme.xml and if this does not
// exist, then try the default for the theme set, i.e. [CURRENT_THEME_PATH]/theme.xml
std::string themePath {ThemeData::getThemeFromCurrentSet(mThemeFolder)};
// First, check game folder.
std::string localThemePath = mRootFolder->getPath() + "/theme.xml";
if (Utils::FileSystem::exists(localThemePath))
return localThemePath;
if (Utils::FileSystem::exists(themePath))
return themePath;
// Not in game folder, try system theme in theme sets.
localThemePath = ThemeData::getThemeFromCurrentSet(mThemeFolder);
themePath = Utils::FileSystem::getParent(Utils::FileSystem::getParent(themePath));
if (Utils::FileSystem::exists(localThemePath))
return localThemePath;
if (themePath != "") {
themePath.append("/theme.xml");
if (Utils::FileSystem::exists(themePath))
return themePath;
}
// Not system theme, try default system theme in theme set.
localThemePath =
Utils::FileSystem::getParent(Utils::FileSystem::getParent(localThemePath)) + "/theme.xml";
return localThemePath;
return "";
}
SystemData* SystemData::getRandomSystem(const SystemData* currentSystem)
@ -1260,7 +1255,7 @@ void SystemData::loadTheme()
{
mTheme = std::make_shared<ThemeData>();
std::string path = getThemePath();
std::string path {getThemePath()};
if (!Utils::FileSystem::exists(path)) {
// No theme available for this platform.

View file

@ -661,7 +661,7 @@ int main(int argc, char* argv[])
AudioManager::getInstance();
MameNames::getInstance();
ThemeData::getThemeSets();
ThemeData::populateThemeSets();
loadSystemsReturnCode loadSystemsStatus = loadSystemConfigFile();
if (loadSystemsStatus) {

View file

@ -531,11 +531,9 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view,
return &elemIt->second;
}
const std::map<std::string, ThemeData::ThemeSet, ThemeData::StringComparator>&
ThemeData::getThemeSets()
void ThemeData::populateThemeSets()
{
if (!mThemeSets.empty())
return mThemeSets;
assert(mThemeSets.empty());
LOG(LogInfo) << "Checking for available theme sets...";
@ -583,8 +581,6 @@ ThemeData::getThemeSets()
}
}
}
return mThemeSets;
}
const std::string ThemeData::getThemeFromCurrentSet(const std::string& system)

View file

@ -214,7 +214,11 @@ public:
const std::string& element,
const std::string& expectedType) const;
const static std::map<std::string, ThemeSet, StringComparator>& getThemeSets();
static void populateThemeSets();
const static std::map<std::string, ThemeSet, StringComparator>& getThemeSets()
{
return mThemeSets;
}
const static std::string getThemeFromCurrentSet(const std::string& system);
const static std::string getAspectRatioLabel(const std::string& aspectRatio);