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

View file

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

View file

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

View file

@ -214,7 +214,11 @@ public:
const std::string& element, const std::string& element,
const std::string& expectedType) const; 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 getThemeFromCurrentSet(const std::string& system);
const static std::string getAspectRatioLabel(const std::string& aspectRatio); const static std::string getAspectRatioLabel(const std::string& aspectRatio);