diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index ef19135bf..86d5d5ffd 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -734,14 +734,8 @@ bool SystemData::loadConfig() continue; } - if (sortName == "") { + if (sortName == "") sortName = fullname; - } - else { - LOG(LogDebug) << "SystemData::loadConfig(): System \"" << name - << "\" has a tag set, sorting as \"" << sortName - << "\" instead of \"" << fullname << "\""; - } // Convert path to generic directory seperators. path = Utils::FileSystem::getGenericPath(path); @@ -798,6 +792,8 @@ bool SystemData::loadConfig() Window::getInstance()->renderSplashScreen(Window::SplashScreenState::SCANNING, 1.0f); } + loadSortingConfig(); + LOG(LogInfo) << "Parsed configuration for " << systemCount << " system" << (systemCount == 1 ? ", loaded " : "s, loaded ") << sSystemVector.size() << " system" << (sSystemVector.size() == 1 ? "" : "s") @@ -816,6 +812,69 @@ bool SystemData::loadConfig() return false; } +void SystemData::loadSortingConfig() +{ + std::vector paths; + std::string filePath {ResourceManager::getInstance().getResourcePath( + ":/systems/sorting/es_systems_sorting.xml", false)}; + + if (Utils::FileSystem::exists(filePath)) + paths.emplace_back(filePath); + + filePath = Utils::FileSystem::getHomePath() + "/.emulationstation/custom_systems" + + "/es_systems_sorting.xml"; + + if (Utils::FileSystem::exists(filePath)) + paths.emplace_back(filePath); + + if (paths.empty()) { + LOG(LogDebug) << "No systems sorting file found"; + return; + } + + for (auto& path : paths) { + LOG(LogInfo) << "Parsing systems sorting file \"" << path << "\"..."; + + pugi::xml_document doc; +#if defined(_WIN64) + const pugi::xml_parse_result& res { + doc.load_file(Utils::String::stringToWideString(path).c_str())}; +#else + const pugi::xml_parse_result& res {doc.load_file(path.c_str())}; +#endif + if (!res) { + LOG(LogError) << "Couldn't parse es_systems_sorting.xml: " << res.description(); + continue; + } + + const pugi::xml_node& systemList {doc.child("systemList")}; + if (!systemList) { + LOG(LogError) << "es_systems_sorting.xml is missing the tag"; + continue; + } + + std::string systemName; + std::string sortName; + + for (pugi::xml_node system {systemList.child("system")}; system; + system = system.next_sibling("system")) { + sortName = system.child("systemsortname").text().get(); + + if (sortName == "") + continue; + + systemName = Utils::String::replace(system.child("name").text().get(), "\n", ""); + + auto systemEntry = std::find_if( + sSystemVector.begin(), sSystemVector.end(), + [systemName](SystemData* system) { return system->getName() == systemName; }); + + if (systemEntry != SystemData::sSystemVector.end()) + (*systemEntry)->mSortName = sortName; + } + } +} + std::string SystemData::getLaunchCommandFromLabel(const std::string& label) { auto commandIter = std::find_if( diff --git a/es-app/src/SystemData.h b/es-app/src/SystemData.h index 33d7cdfee..38979a7d6 100644 --- a/es-app/src/SystemData.h +++ b/es-app/src/SystemData.h @@ -110,6 +110,8 @@ public: // Loads the systems configuration file(s) at getConfigPath() and creates the systems. static bool loadConfig(); static std::vector getConfigPath(bool legacyWarning); + // Parses an optional es_systems_sorting.xml file. + static void loadSortingConfig(); // Generates the game system directories and information files based on es_systems.xml. static bool createSystemDirectories();