2020-09-21 16:13:27 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-21 16:13:27 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// SystemData.cpp
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Provides data structures for the game systems and populates and indexes them based
|
2021-06-16 16:54:04 +00:00
|
|
|
// on the configuration in es_systems.xml as well as the presence of game ROM files.
|
2020-06-21 12:25:28 +00:00
|
|
|
// Also provides functions to read and write to the gamelist files and to handle theme
|
|
|
|
// loading.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "SystemData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2020-12-23 17:06:30 +00:00
|
|
|
#include "CollectionSystemsManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "FileFilterIndex.h"
|
|
|
|
#include "FileSorts.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Gamelist.h"
|
|
|
|
#include "Log.h"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Settings.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "ThemeData.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "resources/ResourceManager.h"
|
|
|
|
#include "utils/FileSystemUtil.h"
|
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
#include "views/UIModeController.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "views/gamelist/IGameListView.h"
|
2020-07-03 18:23:51 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <fstream>
|
2020-09-21 16:13:27 +00:00
|
|
|
#include <pugixml.hpp>
|
2020-10-21 19:56:31 +00:00
|
|
|
#include <random>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
std::vector<SystemData*> SystemData::sSystemVector;
|
2021-06-19 12:09:14 +00:00
|
|
|
std::unique_ptr<FindRules> SystemData::sFindRules;
|
|
|
|
|
|
|
|
FindRules::FindRules()
|
|
|
|
{
|
|
|
|
LOG(LogInfo) << "Loading emulator find rules...";
|
|
|
|
loadFindRules();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FindRules::loadFindRules()
|
|
|
|
{
|
|
|
|
std::string customSystemsDirectory =
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::getHomePath() + "/.emulationstation/custom_systems";
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
std::string path = customSystemsDirectory + "/es_find_rules.xml";
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(path)) {
|
|
|
|
LOG(LogInfo) << "Found custom find rules configuration file";
|
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
path = ResourceManager::getInstance()->getResourcePath(
|
|
|
|
":/systems/windows/es_find_rules.xml", false);
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
path = ResourceManager::getInstance()->getResourcePath(":/systems/macos/es_find_rules.xml",
|
|
|
|
false);
|
|
|
|
#else
|
|
|
|
path = ResourceManager::getInstance()->getResourcePath(":/systems/unix/es_find_rules.xml",
|
|
|
|
false);
|
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (path == "") {
|
|
|
|
LOG(LogWarning) << "No find rules configuration file found";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogInfo) << "Parsing find rules configuration file \"" << path << "\"...";
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-19 12:09:14 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(Utils::String::stringToWideString(path).c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-06-19 12:09:14 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
LOG(LogError) << "Couldn't parse es_find_rules.xml: " << res.description();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually read the file.
|
|
|
|
pugi::xml_node ruleList = doc.child("ruleList");
|
|
|
|
|
|
|
|
if (!ruleList) {
|
|
|
|
LOG(LogError) << "es_find_rules.xml is missing the <ruleList> tag";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmulatorRules emulatorRules;
|
|
|
|
CoreRules coreRules;
|
|
|
|
|
|
|
|
for (pugi::xml_node emulator = ruleList.child("emulator"); emulator;
|
2021-07-07 18:03:42 +00:00
|
|
|
emulator = emulator.next_sibling("emulator")) {
|
2021-06-19 12:09:14 +00:00
|
|
|
std::string emulatorName = emulator.attribute("name").as_string();
|
|
|
|
if (emulatorName.empty()) {
|
|
|
|
LOG(LogWarning) << "Found emulator tag without name attribute, skipping entry";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mEmulators.find(emulatorName) != mEmulators.end()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Found repeating emulator tag \"" << emulatorName
|
|
|
|
<< "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (pugi::xml_node rule = emulator.child("rule"); rule; rule = rule.next_sibling("rule")) {
|
|
|
|
std::string ruleType = rule.attribute("type").as_string();
|
|
|
|
if (ruleType.empty()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Found rule tag without type attribute for emulator \""
|
|
|
|
<< emulatorName << "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-26 10:00:09 +00:00
|
|
|
if (ruleType != "winregistrypath" && ruleType != "systempath" &&
|
2021-07-07 18:03:42 +00:00
|
|
|
ruleType != "staticpath") {
|
|
|
|
#else
|
2021-06-19 12:09:14 +00:00
|
|
|
if (ruleType != "systempath" && ruleType != "staticpath") {
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
|
|
|
LOG(LogWarning) << "Found invalid rule type \"" << ruleType << "\" for emulator \""
|
|
|
|
<< emulatorName << "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (pugi::xml_node entry = rule.child("entry"); entry;
|
2021-07-07 18:03:42 +00:00
|
|
|
entry = entry.next_sibling("entry")) {
|
2021-06-19 12:09:14 +00:00
|
|
|
std::string entryValue = entry.text().get();
|
|
|
|
if (ruleType == "systempath")
|
|
|
|
emulatorRules.systemPaths.push_back(entryValue);
|
|
|
|
else if (ruleType == "staticpath")
|
|
|
|
emulatorRules.staticPaths.push_back(entryValue);
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-26 10:00:09 +00:00
|
|
|
else if (ruleType == "winregistrypath")
|
|
|
|
emulatorRules.winRegistryPaths.push_back(entryValue);
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mEmulators[emulatorName] = emulatorRules;
|
|
|
|
emulatorRules.systemPaths.clear();
|
|
|
|
emulatorRules.staticPaths.clear();
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-26 10:00:09 +00:00
|
|
|
emulatorRules.winRegistryPaths.clear();
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-06-19 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (pugi::xml_node core = ruleList.child("core"); core; core = core.next_sibling("core")) {
|
2021-06-19 12:09:14 +00:00
|
|
|
std::string coreName = core.attribute("name").as_string();
|
|
|
|
if (coreName.empty()) {
|
|
|
|
LOG(LogWarning) << "Found core tag without name attribute, skipping entry";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mCores.find(coreName) != mCores.end()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Found repeating core tag \"" << coreName << "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (pugi::xml_node rule = core.child("rule"); rule; rule = rule.next_sibling("rule")) {
|
|
|
|
std::string ruleType = rule.attribute("type").as_string();
|
|
|
|
if (ruleType.empty()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Found rule tag without type attribute for core \"" << coreName
|
|
|
|
<< "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ruleType != "corepath") {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Found invalid rule type \"" << ruleType << "\" for core \""
|
|
|
|
<< coreName << "\", skipping entry";
|
2021-06-19 12:09:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (pugi::xml_node entry = rule.child("entry"); entry;
|
2021-07-07 18:03:42 +00:00
|
|
|
entry = entry.next_sibling("entry")) {
|
2021-06-19 12:09:14 +00:00
|
|
|
std::string entryValue = entry.text().get();
|
|
|
|
if (ruleType == "corepath")
|
|
|
|
coreRules.corePaths.push_back(entryValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCores[coreName] = coreRules;
|
|
|
|
coreRules.corePaths.clear();
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
SystemData::SystemData(const std::string& name,
|
|
|
|
const std::string& fullName,
|
|
|
|
SystemEnvironmentData* envData,
|
|
|
|
const std::string& themeFolder,
|
|
|
|
bool CollectionSystem,
|
|
|
|
bool CustomCollectionSystem)
|
|
|
|
: mName(name)
|
|
|
|
, mFullName(fullName)
|
|
|
|
, mEnvData(envData)
|
|
|
|
, mThemeFolder(themeFolder)
|
|
|
|
, mIsCollectionSystem(CollectionSystem)
|
|
|
|
, mIsCustomCollectionSystem(CustomCollectionSystem)
|
|
|
|
, mIsGroupedCustomCollectionSystem(false)
|
|
|
|
, mIsGameSystem(true)
|
|
|
|
, mScrapeFlag(false)
|
|
|
|
, mPlaceholder(nullptr)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mFilterIndex = new FileFilterIndex();
|
|
|
|
|
|
|
|
// If it's an actual system, initialize it, if not, just create the data structure.
|
|
|
|
if (!CollectionSystem) {
|
|
|
|
mRootFolder = new FileData(FOLDER, mEnvData->mStartPath, mEnvData, this);
|
|
|
|
mRootFolder->metadata.set("name", mFullName);
|
|
|
|
|
2020-06-21 20:11:29 +00:00
|
|
|
if (!Settings::getInstance()->getBool("ParseGamelistOnly")) {
|
|
|
|
// If there was an error populating the folder or if there were no games found,
|
|
|
|
// then don't continue with any additional process steps for this system.
|
|
|
|
if (!populateFolder(mRootFolder))
|
|
|
|
return;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!Settings::getInstance()->getBool("IgnoreGamelist"))
|
|
|
|
parseGamelist(this);
|
|
|
|
|
|
|
|
setupSystemSortType(mRootFolder);
|
|
|
|
|
2020-09-17 20:18:13 +00:00
|
|
|
mRootFolder->sort(mRootFolder->getSortTypeFromString(mRootFolder->getSortTypeString()),
|
2021-07-07 18:03:42 +00:00
|
|
|
Settings::getInstance()->getBool("FavoritesFirst"));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
indexAllGameFilters(mRootFolder);
|
|
|
|
}
|
|
|
|
else {
|
2020-12-23 17:06:30 +00:00
|
|
|
// Virtual systems are updated afterwards by CollectionSystemsManager.
|
2020-06-21 12:25:28 +00:00
|
|
|
// We're just creating the data structure here.
|
|
|
|
mRootFolder = new FileData(FOLDER, "" + name, mEnvData, this);
|
|
|
|
setupSystemSortType(mRootFolder);
|
|
|
|
}
|
2021-03-19 17:47:49 +00:00
|
|
|
|
|
|
|
// This placeholder can be used later in the gamelist view.
|
|
|
|
mPlaceholder = new FileData(PLACEHOLDER, "<No Entries Found>", getSystemEnvData(), this);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
setIsGameSystemStatus();
|
|
|
|
loadTheme();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemData::~SystemData()
|
|
|
|
{
|
2020-10-18 17:18:02 +00:00
|
|
|
if (Settings::getInstance()->getString("SaveGamelistsMode") == "on exit") {
|
|
|
|
if (mRootFolder->getGameCount().first + mRootFolder->getGameCount().second != 0)
|
|
|
|
writeMetaData();
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-02-28 15:56:50 +00:00
|
|
|
if (!mEnvData->mStartPath.empty())
|
|
|
|
delete mEnvData;
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mRootFolder;
|
2021-03-19 17:47:49 +00:00
|
|
|
delete mPlaceholder;
|
2020-06-21 12:25:28 +00:00
|
|
|
delete mFilterIndex;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
void SystemData::setIsGameSystemStatus()
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We exclude non-game systems from specific operations (i.e. the "RetroPie" system, at least).
|
|
|
|
// If/when there are more in the future, maybe this can be a more complex method, with a proper
|
2021-06-16 16:54:04 +00:00
|
|
|
// list but for now a simple string comparison is enough.
|
2020-06-21 12:25:28 +00:00
|
|
|
mIsGameSystem = (mName != "retropie");
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:11:29 +00:00
|
|
|
bool SystemData::populateFolder(FileData* folder)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string& folderPath = folder->getPath();
|
|
|
|
|
|
|
|
std::string filePath;
|
|
|
|
std::string extension;
|
|
|
|
bool isGame;
|
2020-07-26 11:58:49 +00:00
|
|
|
bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles");
|
2020-06-21 12:25:28 +00:00
|
|
|
Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(folderPath);
|
2020-06-21 20:11:29 +00:00
|
|
|
|
2020-06-22 17:46:09 +00:00
|
|
|
// If system directory exists but contains no games, return as error.
|
2020-06-21 20:11:29 +00:00
|
|
|
if (dirContent.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin();
|
2021-07-07 18:03:42 +00:00
|
|
|
it != dirContent.cend(); it++) {
|
2020-06-21 12:25:28 +00:00
|
|
|
filePath = *it;
|
|
|
|
|
2021-07-01 15:58:09 +00:00
|
|
|
// Skip any recursive symlinks as those would hang the application at various places.
|
|
|
|
if (Utils::FileSystem::isSymlink(filePath)) {
|
|
|
|
if (Utils::FileSystem::resolveSymlink(filePath) ==
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::getFileName(filePath)) {
|
2021-07-01 15:58:09 +00:00
|
|
|
LOG(LogWarning) << "Skipped \"" << filePath << "\" as it's a recursive symlink";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Skip hidden files and folders.
|
2020-10-19 15:28:20 +00:00
|
|
|
if (!showHiddenFiles && Utils::FileSystem::isHidden(filePath)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "SystemData::populateFolder(): Skipping hidden "
|
|
|
|
<< (Utils::FileSystem::isDirectory(filePath) ? "directory \"" : "file \"")
|
|
|
|
<< filePath << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
2020-10-19 15:28:20 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// This is a little complicated because we allow a list
|
|
|
|
// of extensions to be defined (delimited with a space).
|
|
|
|
// We first get the extension of the file itself:
|
|
|
|
extension = Utils::FileSystem::getExtension(filePath);
|
|
|
|
|
|
|
|
// FYI, folders *can* also match the extension and be added as games.
|
|
|
|
// This is mostly just to support higan.
|
|
|
|
// See issue #75: https://github.com/Aloshi/EmulationStation/issues/75
|
|
|
|
|
|
|
|
isGame = false;
|
|
|
|
if (std::find(mEnvData->mSearchExtensions.cbegin(), mEnvData->mSearchExtensions.cend(),
|
2021-07-07 18:03:42 +00:00
|
|
|
extension) != mEnvData->mSearchExtensions.cend()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* newGame = new FileData(GAME, filePath, mEnvData, this);
|
|
|
|
|
|
|
|
// Prevent new arcade assets from being added.
|
|
|
|
if (!newGame->isArcadeAsset()) {
|
|
|
|
folder->addChild(newGame);
|
|
|
|
isGame = true;
|
|
|
|
}
|
2021-02-28 15:37:22 +00:00
|
|
|
else {
|
|
|
|
delete newGame;
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add directories that also do not match an extension as folders.
|
|
|
|
if (!isGame && Utils::FileSystem::isDirectory(filePath)) {
|
2021-02-07 17:09:32 +00:00
|
|
|
// Make sure that it's not a recursive symlink pointing to a location higher in the
|
|
|
|
// hierarchy as the application would run forever trying to resolve the link.
|
|
|
|
if (Utils::FileSystem::isSymlink(filePath)) {
|
|
|
|
const std::string canonicalPath = Utils::FileSystem::getCanonicalPath(filePath);
|
|
|
|
const std::string canonicalStartPath =
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::getCanonicalPath(mEnvData->mStartPath);
|
|
|
|
const std::string combinedPath =
|
|
|
|
mEnvData->mStartPath +
|
|
|
|
canonicalPath.substr(canonicalStartPath.size(),
|
|
|
|
canonicalStartPath.size() - canonicalPath.size());
|
2021-02-07 17:09:32 +00:00
|
|
|
if (filePath.find(combinedPath) == 0) {
|
|
|
|
LOG(LogWarning) << "Skipped \"" << filePath << "\" as it's a recursive symlink";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* newFolder = new FileData(FOLDER, filePath, mEnvData, this);
|
|
|
|
populateFolder(newFolder);
|
|
|
|
|
|
|
|
// Ignore folders that do not contain games.
|
|
|
|
if (newFolder->getChildrenByFilename().size() == 0)
|
|
|
|
delete newFolder;
|
|
|
|
else
|
|
|
|
folder->addChild(newFolder);
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 20:11:29 +00:00
|
|
|
return true;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 16:03:24 +00:00
|
|
|
void SystemData::indexAllGameFilters(const FileData* folder)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::vector<FileData*>& children = folder->getChildren();
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
for (std::vector<FileData*>::const_iterator it = children.cbegin(); // Line break.
|
|
|
|
it != children.cend(); it++) {
|
2020-06-21 12:25:28 +00:00
|
|
|
switch ((*it)->getType()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
case GAME:
|
2020-06-21 12:25:28 +00:00
|
|
|
mFilterIndex->addToIndex(*it);
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
|
|
|
case FOLDER:
|
2020-06-21 12:25:28 +00:00
|
|
|
indexAllGameFilters(*it);
|
2021-07-07 18:03:42 +00:00
|
|
|
break;
|
2020-06-25 17:52:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-04 16:03:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:59:00 +00:00
|
|
|
std::vector<std::string> readList(const std::string& str, const std::string& delims = " \t\r\n,")
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> ret;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
size_t prevOff = str.find_first_not_of(delims, 0);
|
|
|
|
size_t off = str.find_first_of(delims, prevOff);
|
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
|
|
|
ret.push_back(str.substr(prevOff, off - prevOff));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
prevOff = str.find_first_not_of(delims, off);
|
|
|
|
off = str.find_first_of(delims, prevOff);
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return ret;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemData::loadConfig()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
deleteSystems();
|
|
|
|
|
2021-06-19 12:09:14 +00:00
|
|
|
if (sFindRules.get() == nullptr)
|
|
|
|
sFindRules = std::make_unique<FindRules>();
|
|
|
|
|
|
|
|
LOG(LogInfo) << "Populating game systems...";
|
|
|
|
|
2021-06-16 16:54:04 +00:00
|
|
|
std::string path = getConfigPath(true);
|
2020-10-19 15:28:20 +00:00
|
|
|
const std::string rompath = FileData::getROMDirectory();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "Parsing systems configuration file \"" << path << "\"...";
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document doc;
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(Utils::String::stringToWideString(path).c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!res) {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "Couldn't parse es_systems.xml: " << res.description();
|
2021-03-10 17:21:49 +00:00
|
|
|
return true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actually read the file.
|
|
|
|
pugi::xml_node systemList = doc.child("systemList");
|
|
|
|
|
|
|
|
if (!systemList) {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "es_systems.xml is missing the <systemList> tag";
|
2021-03-10 17:21:49 +00:00
|
|
|
return true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (pugi::xml_node system = systemList.child("system"); system;
|
2021-07-07 18:03:42 +00:00
|
|
|
system = system.next_sibling("system")) {
|
2020-07-07 19:25:15 +00:00
|
|
|
std::string name;
|
|
|
|
std::string fullname;
|
|
|
|
std::string path;
|
|
|
|
std::string themeFolder;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
name = system.child("name").text().get();
|
|
|
|
fullname = system.child("fullname").text().get();
|
|
|
|
path = system.child("path").text().get();
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
auto nameFindFunc = [&] {
|
|
|
|
for (auto system : sSystemVector) {
|
|
|
|
if (system->mName == name) {
|
|
|
|
LOG(LogWarning) << "A system with the name \"" << name
|
|
|
|
<< "\" has already been loaded, skipping duplicate entry";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// If the name is matching a system that has already been loaded, then skip the entry.
|
|
|
|
if (nameFindFunc())
|
|
|
|
continue;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If there is a %ROMPATH% variable set for the system, expand it. By doing this
|
2021-06-16 16:54:04 +00:00
|
|
|
// it's possible to use either absolute ROM paths in es_systems.xml or to utilize
|
2021-06-16 17:05:24 +00:00
|
|
|
// the ROM path configured as ROMDirectory in es_settings.xml. If it's set to ""
|
2020-06-21 12:25:28 +00:00
|
|
|
// in this configuration file, the default hardcoded path $HOME/ROMs/ will be used.
|
|
|
|
path = Utils::String::replace(path, "%ROMPATH%", rompath);
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-02-07 10:46:02 +00:00
|
|
|
path = Utils::String::replace(path, "\\", "/");
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-02-07 10:49:41 +00:00
|
|
|
path = Utils::String::replace(path, "//", "/");
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-02-07 10:30:54 +00:00
|
|
|
// Check that the ROM directory for the system is valid or otherwise abort the processing.
|
|
|
|
if (!Utils::FileSystem::exists(path)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "SystemData::loadConfig(): Skipping system \"" << name
|
|
|
|
<< "\" as the defined ROM directory \"" << path << "\" does not exist";
|
2021-02-07 10:30:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!Utils::FileSystem::isDirectory(path)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "SystemData::loadConfig(): Skipping system \"" << name
|
|
|
|
<< "\" as the defined ROM directory \"" << path
|
|
|
|
<< "\" is not actually a directory";
|
2021-02-07 10:30:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Utils::FileSystem::isSymlink(path)) {
|
2021-02-07 17:09:32 +00:00
|
|
|
// Make sure that the symlink is not pointing to somewhere higher in the hierarchy
|
2021-02-07 10:30:54 +00:00
|
|
|
// as that would lead to an infite loop, meaning the application would never start.
|
|
|
|
std::string resolvedRompath = Utils::FileSystem::getCanonicalPath(rompath);
|
|
|
|
if (resolvedRompath.find(Utils::FileSystem::getCanonicalPath(path)) == 0) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Skipping system \"" << name
|
|
|
|
<< "\" as the defined ROM directory \"" << path
|
|
|
|
<< "\" is an infinitely recursive symlink";
|
2021-02-07 10:30:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Convert extensions list from a string into a vector of strings.
|
|
|
|
std::vector<std::string> extensions = readList(system.child("extension").text().get());
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
// Load all launch command tags for the system and if there are multiple tags, then
|
|
|
|
// the label attribute needs to be set on all entries as it's a requirement for the
|
|
|
|
// alternative emulator logic.
|
|
|
|
std::vector<std::pair<std::string, std::string>> commands;
|
|
|
|
for (pugi::xml_node entry = system.child("command"); entry;
|
|
|
|
entry = entry.next_sibling("command")) {
|
|
|
|
if (!entry.attribute("label")) {
|
|
|
|
if (commands.size() == 1) {
|
|
|
|
// The first command tag had a label but the second one doesn't.
|
|
|
|
LOG(LogError)
|
|
|
|
<< "Missing mandatory label attribute for alternative emulator "
|
|
|
|
"entry, only the default command tag will be processed for system \""
|
|
|
|
<< name << "\"";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (commands.size() > 1) {
|
|
|
|
// At least two command tags had a label but this one doesn't.
|
|
|
|
LOG(LogError)
|
|
|
|
<< "Missing mandatory label attribute for alternative emulator "
|
|
|
|
"entry, no additional command tags will be processed for system \""
|
|
|
|
<< name << "\"";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!commands.empty() && commands.back().second == "") {
|
|
|
|
// There are more than one command tags and the first tag did not have a label.
|
|
|
|
LOG(LogError)
|
|
|
|
<< "Missing mandatory label attribute for alternative emulator "
|
|
|
|
"entry, only the default command tag will be processed for system \""
|
|
|
|
<< name << "\"";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
commands.push_back(
|
|
|
|
std::make_pair(entry.text().get(), entry.attribute("label").as_string()));
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Platform ID list
|
2020-12-26 19:20:45 +00:00
|
|
|
const std::string platformList =
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::String::toLower(system.child("platform").text().get());
|
2021-07-10 11:07:44 +00:00
|
|
|
|
|
|
|
if (platformList == "") {
|
|
|
|
LOG(LogWarning) << "No platform defined for system \"" << name
|
|
|
|
<< "\", scraper searches will be inaccurate";
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<std::string> platformStrs = readList(platformList);
|
|
|
|
std::vector<PlatformIds::PlatformId> platformIds;
|
|
|
|
for (auto it = platformStrs.cbegin(); it != platformStrs.cend(); it++) {
|
2020-12-17 19:43:52 +00:00
|
|
|
std::string str = *it;
|
2020-06-21 12:25:28 +00:00
|
|
|
PlatformIds::PlatformId platformId = PlatformIds::getPlatformId(str);
|
|
|
|
|
|
|
|
if (platformId == PlatformIds::PLATFORM_IGNORE) {
|
|
|
|
// When platform is PLATFORM_IGNORE, do not allow other platforms.
|
|
|
|
platformIds.clear();
|
|
|
|
platformIds.push_back(platformId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-02-07 11:24:22 +00:00
|
|
|
// If there's a platform entry defined but it does not match the list of supported
|
|
|
|
// platforms, then generate a warning.
|
2020-12-16 22:59:00 +00:00
|
|
|
if (str != "" && platformId == PlatformIds::PLATFORM_UNKNOWN)
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "Unknown platform \"" << str << "\" defined for system \""
|
2021-07-10 11:07:44 +00:00
|
|
|
<< name << "\", scraper searches will be inaccurate";
|
2020-06-21 12:25:28 +00:00
|
|
|
else if (platformId != PlatformIds::PLATFORM_UNKNOWN)
|
|
|
|
platformIds.push_back(platformId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Theme folder.
|
|
|
|
themeFolder = system.child("theme").text().as_string(name.c_str());
|
|
|
|
|
|
|
|
// Validate.
|
2020-12-26 19:20:45 +00:00
|
|
|
|
|
|
|
if (name.empty()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError)
|
|
|
|
<< "A system in the es_systems.xml file has no name defined, skipping entry";
|
2020-12-26 19:20:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-08-22 13:26:38 +00:00
|
|
|
else if (fullname.empty() || path.empty() || extensions.empty() || commands.empty()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "System \"" << name
|
|
|
|
<< "\" is missing the fullname, path, "
|
|
|
|
"extension, or command tag, skipping entry";
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert path to generic directory seperators.
|
|
|
|
path = Utils::FileSystem::getGenericPath(path);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-27 11:06:46 +00:00
|
|
|
if (!Settings::getInstance()->getBool("ShowHiddenFiles") &&
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::isHidden(path)) {
|
2021-02-07 10:30:54 +00:00
|
|
|
LOG(LogWarning) << "Skipping hidden ROM folder \"" << path << "\"";
|
2020-07-27 11:06:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-07-27 11:06:46 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Create the system runtime environment data.
|
|
|
|
SystemEnvironmentData* envData = new SystemEnvironmentData;
|
|
|
|
envData->mStartPath = path;
|
|
|
|
envData->mSearchExtensions = extensions;
|
2021-08-22 13:26:38 +00:00
|
|
|
envData->mLaunchCommands = commands;
|
2020-06-21 12:25:28 +00:00
|
|
|
envData->mPlatformIds = platformIds;
|
|
|
|
|
|
|
|
SystemData* newSys = new SystemData(name, fullname, envData, themeFolder);
|
2020-07-26 20:19:29 +00:00
|
|
|
bool onlyHidden = false;
|
|
|
|
|
|
|
|
// If the option to show hidden games has been disabled, then check whether all
|
|
|
|
// games for the system are hidden. That will flag the system as empty.
|
|
|
|
if (!Settings::getInstance()->getBool("ShowHiddenGames")) {
|
2021-07-07 18:03:42 +00:00
|
|
|
std::vector<FileData*> recursiveGames = newSys->getRootFolder()->getChildrenRecursive();
|
2020-07-26 20:19:29 +00:00
|
|
|
onlyHidden = true;
|
|
|
|
for (auto it = recursiveGames.cbegin(); it != recursiveGames.cend(); it++) {
|
|
|
|
if ((*it)->getType() != FOLDER) {
|
|
|
|
onlyHidden = (*it)->getHidden();
|
|
|
|
if (!onlyHidden)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newSys->getRootFolder()->getChildrenByFilename().size() == 0 || onlyHidden) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "SystemData::loadConfig(): Skipping system \"" << name
|
|
|
|
<< "\" as no files matched any of the defined file extensions";
|
2020-06-21 12:25:28 +00:00
|
|
|
delete newSys;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sSystemVector.push_back(newSys);
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 10:49:14 +00:00
|
|
|
|
|
|
|
// Sort systems by their full names.
|
|
|
|
std::sort(std::begin(sSystemVector), std::end(sSystemVector),
|
2021-07-07 18:03:42 +00:00
|
|
|
[](SystemData* a, SystemData* b) { return a->getFullName() < b->getFullName(); });
|
2020-09-27 10:49:14 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Don't load any collections if there are no systems available.
|
|
|
|
if (sSystemVector.size() > 0)
|
2020-12-23 17:06:30 +00:00
|
|
|
CollectionSystemsManager::get()->loadCollectionSystems();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
return false;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemData::deleteSystems()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (unsigned int i = 0; i < sSystemVector.size(); i++)
|
|
|
|
delete sSystemVector.at(i);
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
sSystemVector.clear();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 16:54:04 +00:00
|
|
|
std::string SystemData::getConfigPath(bool legacyWarning)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2021-06-16 16:54:04 +00:00
|
|
|
if (legacyWarning) {
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string legacyConfigFile =
|
|
|
|
Utils::FileSystem::getHomePath() + "/.emulationstation/es_systems.cfg";
|
2021-06-16 16:54:04 +00:00
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(legacyConfigFile)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogInfo) << "Found legacy systems configuration file \"" << legacyConfigFile
|
|
|
|
<< "\", to retain your customizations move it to "
|
|
|
|
"\"custom_systems/es_systems.xml\" or otherwise delete the file";
|
2021-06-16 16:54:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string customSystemsDirectory =
|
2021-07-07 18:03:42 +00:00
|
|
|
Utils::FileSystem::getHomePath() + "/.emulationstation/custom_systems";
|
2021-06-16 16:54:04 +00:00
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(customSystemsDirectory)) {
|
2021-06-24 21:29:03 +00:00
|
|
|
LOG(LogInfo) << "Creating custom systems directory \"" << customSystemsDirectory << "\"...";
|
2021-06-16 16:54:04 +00:00
|
|
|
Utils::FileSystem::createDirectory(customSystemsDirectory);
|
|
|
|
if (!Utils::FileSystem::exists(customSystemsDirectory)) {
|
|
|
|
LOG(LogError) << "Couldn't create directory, permission problems?";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string path = customSystemsDirectory + "/es_systems.xml";
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(path)) {
|
|
|
|
LOG(LogInfo) << "Found custom systems configuration file";
|
2020-06-21 12:25:28 +00:00
|
|
|
return path;
|
2021-06-16 16:54:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
path =
|
|
|
|
ResourceManager::getInstance()->getResourcePath(":/systems/windows/es_systems.xml", true);
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
path = ResourceManager::getInstance()->getResourcePath(":/systems/macos/es_systems.xml", true);
|
|
|
|
#else
|
|
|
|
path = ResourceManager::getInstance()->getResourcePath(":/systems/unix/es_systems.xml", true);
|
|
|
|
#endif
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-06-16 16:54:04 +00:00
|
|
|
return path;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
bool SystemData::createSystemDirectories()
|
|
|
|
{
|
|
|
|
std::string path = getConfigPath(false);
|
|
|
|
const std::string rompath = FileData::getROMDirectory();
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
if (!Utils::FileSystem::exists(path)) {
|
2021-03-10 17:21:49 +00:00
|
|
|
LOG(LogInfo) << "Systems configuration file does not exist, aborting";
|
|
|
|
return true;
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
2021-03-10 17:21:49 +00:00
|
|
|
|
|
|
|
LOG(LogInfo) << "Generating ROM directory structure...";
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(rompath) && Utils::FileSystem::isRegularFile(rompath)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Requested ROM directory \"" << rompath
|
|
|
|
<< "\" is actually a file, aborting";
|
2021-03-10 17:21:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(rompath)) {
|
|
|
|
LOG(LogInfo) << "Creating base ROM directory \"" << rompath << "\"...";
|
|
|
|
if (!Utils::FileSystem::createDirectory(rompath)) {
|
|
|
|
LOG(LogError) << "Couldn't create directory, permission problems or disk full?";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogInfo) << "Base ROM directory \"" << rompath << "\" already exists";
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogInfo) << "Parsing systems configuration file \"" << path << "\"...";
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-03-10 17:21:49 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(Utils::String::stringToWideString(path).c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-03-10 17:21:49 +00:00
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-03-10 17:21:49 +00:00
|
|
|
|
|
|
|
if (!res) {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "Couldn't parse es_systems.xml";
|
2021-03-10 17:21:49 +00:00
|
|
|
LOG(LogError) << res.description();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually read the file.
|
|
|
|
pugi::xml_node systemList = doc.child("systemList");
|
|
|
|
|
|
|
|
if (!systemList) {
|
2021-06-16 16:54:04 +00:00
|
|
|
LOG(LogError) << "es_systems.xml is missing the <systemList> tag";
|
2021-03-10 17:21:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:53:00 +00:00
|
|
|
std::vector<std::string> systemsVector;
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
for (pugi::xml_node system = systemList.child("system"); system;
|
2021-07-07 18:03:42 +00:00
|
|
|
system = system.next_sibling("system")) {
|
2021-03-10 17:21:49 +00:00
|
|
|
std::string systemDir;
|
|
|
|
std::string name;
|
|
|
|
std::string fullname;
|
|
|
|
std::string path;
|
|
|
|
std::string extensions;
|
2021-08-22 13:26:38 +00:00
|
|
|
std::vector<std::string> commands;
|
2021-03-10 17:21:49 +00:00
|
|
|
std::string platform;
|
|
|
|
std::string themeFolder;
|
|
|
|
const std::string systemInfoFileName = "/systeminfo.txt";
|
|
|
|
bool replaceInfoFile = false;
|
|
|
|
std::ofstream systemInfoFile;
|
|
|
|
|
|
|
|
name = system.child("name").text().get();
|
|
|
|
fullname = system.child("fullname").text().get();
|
|
|
|
path = system.child("path").text().get();
|
|
|
|
extensions = system.child("extension").text().get();
|
2021-08-22 13:26:38 +00:00
|
|
|
for (pugi::xml_node entry = system.child("command"); entry;
|
|
|
|
entry = entry.next_sibling("command")) {
|
|
|
|
commands.push_back(entry.text().get());
|
|
|
|
}
|
2021-03-10 17:21:49 +00:00
|
|
|
platform = Utils::String::toLower(system.child("platform").text().get());
|
|
|
|
themeFolder = system.child("theme").text().as_string(name.c_str());
|
|
|
|
|
|
|
|
// Check that the %ROMPATH% variable is actually used for the path element.
|
|
|
|
// If not, skip the system.
|
|
|
|
if (path.find("%ROMPATH%") != 0) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << "The path element for system \"" << name
|
|
|
|
<< "\" does not "
|
|
|
|
"utilize the %ROMPATH% variable, skipping entry";
|
2021-03-10 17:21:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
systemDir = path.substr(9, path.size() - 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trim any leading directory separator characters.
|
|
|
|
systemDir.erase(systemDir.begin(),
|
2021-07-07 18:03:42 +00:00
|
|
|
std::find_if(systemDir.begin(), systemDir.end(),
|
|
|
|
[](char c) { return c != '/' && c != '\\'; }));
|
2021-03-10 17:21:49 +00:00
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(rompath + systemDir)) {
|
|
|
|
if (!Utils::FileSystem::createDirectory(rompath + systemDir)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Couldn't create system directory \"" << systemDir
|
|
|
|
<< "\", permission problems or disk full?";
|
2021-03-10 17:21:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogInfo) << "Created system directory \"" << systemDir << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogInfo) << "System directory \"" << systemDir << "\" already exists";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(rompath + systemDir + systemInfoFileName))
|
|
|
|
replaceInfoFile = true;
|
|
|
|
else
|
|
|
|
replaceInfoFile = false;
|
|
|
|
|
|
|
|
if (replaceInfoFile) {
|
|
|
|
if (Utils::FileSystem::removeFile(rompath + systemDir + systemInfoFileName))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
systemInfoFile.open(
|
|
|
|
Utils::String::stringToWideString(rompath + systemDir + systemInfoFileName).c_str());
|
|
|
|
#else
|
2021-03-10 17:21:49 +00:00
|
|
|
systemInfoFile.open(rompath + systemDir + systemInfoFileName);
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-03-10 17:21:49 +00:00
|
|
|
|
|
|
|
if (systemInfoFile.fail()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Couldn't create system information file \""
|
|
|
|
<< rompath + systemDir + systemInfoFileName
|
|
|
|
<< "\", permission problems or disk full?";
|
2021-03-10 17:21:49 +00:00
|
|
|
systemInfoFile.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
systemInfoFile << "System name:" << std::endl;
|
|
|
|
systemInfoFile << name << std::endl << std::endl;
|
|
|
|
systemInfoFile << "Full system name:" << std::endl;
|
|
|
|
systemInfoFile << fullname << std::endl << std::endl;
|
|
|
|
systemInfoFile << "Supported file extensions:" << std::endl;
|
|
|
|
systemInfoFile << extensions << std::endl << std::endl;
|
|
|
|
systemInfoFile << "Launch command:" << std::endl;
|
2021-08-22 13:26:38 +00:00
|
|
|
systemInfoFile << commands.front() << std::endl << std::endl;
|
|
|
|
// Alternative emulator configuration entries.
|
|
|
|
if (commands.size() > 1) {
|
|
|
|
systemInfoFile << (commands.size() == 2 ? "Alternative launch command:" :
|
|
|
|
"Alternative launch commands:")
|
|
|
|
<< std::endl;
|
|
|
|
for (auto it = commands.cbegin() + 1; it != commands.cend(); it++)
|
|
|
|
systemInfoFile << (*it) << std::endl;
|
|
|
|
systemInfoFile << std::endl;
|
|
|
|
}
|
2021-03-10 17:21:49 +00:00
|
|
|
systemInfoFile << "Platform (for scraping):" << std::endl;
|
|
|
|
systemInfoFile << platform << std::endl << std::endl;
|
|
|
|
systemInfoFile << "Theme folder:" << std::endl;
|
|
|
|
systemInfoFile << themeFolder << std::endl;
|
|
|
|
systemInfoFile.close();
|
|
|
|
|
2021-04-01 10:53:00 +00:00
|
|
|
systemsVector.push_back(systemDir + ": " + fullname);
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
if (replaceInfoFile) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogInfo) << "Replaced existing system information file \""
|
|
|
|
<< rompath + systemDir + systemInfoFileName << "\"";
|
2021-03-10 17:21:49 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogInfo) << "Created system information file \""
|
|
|
|
<< rompath + systemDir + systemInfoFileName << "\"";
|
2021-03-10 17:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 10:53:00 +00:00
|
|
|
// Also generate a systems.txt file directly in the ROM directory root that contains the
|
|
|
|
// mappings between the system directory names and the full system names. This makes it
|
|
|
|
// easier for the users to identify the correct directories for their games.
|
|
|
|
if (!systemsVector.empty()) {
|
|
|
|
const std::string systemsFileName = "/systems.txt";
|
|
|
|
bool systemsFileSuccess = true;
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(rompath + systemsFileName)) {
|
|
|
|
if (Utils::FileSystem::removeFile(rompath + systemsFileName))
|
|
|
|
systemsFileSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (systemsFileSuccess) {
|
|
|
|
std::ofstream systemsFile;
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-04-01 10:53:00 +00:00
|
|
|
systemsFile.open(Utils::String::stringToWideString(rompath + systemsFileName).c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-04-01 10:53:00 +00:00
|
|
|
systemsFile.open(rompath + systemsFileName);
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-04-01 10:53:00 +00:00
|
|
|
if (systemsFile.fail()) {
|
|
|
|
systemsFileSuccess = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (std::string systemEntry : systemsVector) {
|
|
|
|
systemsFile << systemEntry << std::endl;
|
|
|
|
}
|
|
|
|
systemsFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!systemsFileSuccess) {
|
|
|
|
LOG(LogWarning) << "System directories successfully created but couldn't create "
|
2021-07-07 18:03:42 +00:00
|
|
|
"the systems.txt file in the ROM directory root";
|
2021-04-01 10:53:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
LOG(LogInfo) << "System directories successfully created";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-01 19:28:45 +00:00
|
|
|
bool SystemData::isVisible()
|
|
|
|
{
|
2021-03-10 17:21:49 +00:00
|
|
|
// This function doesn't make much sense at the moment; if a system does not have any
|
2020-09-21 16:13:27 +00:00
|
|
|
// games available, it will not be processed during startup and will as such not exist.
|
|
|
|
// In the future this function may be used for an option to hide specific systems, but
|
|
|
|
// for the time being all systems will always be visible.
|
|
|
|
return true;
|
2017-12-01 19:28:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:20:07 +00:00
|
|
|
SystemData* SystemData::getNext() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<SystemData*>::const_iterator it = getIterator();
|
2017-09-08 13:20:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// As we are starting in a valid gamelistview, this will
|
|
|
|
// always succeed, even if we have to come full circle.
|
|
|
|
do {
|
|
|
|
it++;
|
|
|
|
if (it == sSystemVector.cend())
|
|
|
|
it = sSystemVector.cbegin();
|
|
|
|
} while (!(*it)->isVisible());
|
2017-09-08 13:20:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return *it;
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemData* SystemData::getPrev() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<SystemData*>::const_reverse_iterator it = getRevIterator();
|
2017-11-11 14:56:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// As we are starting in a valid gamelistview, this will
|
|
|
|
// always succeed, even if we have to come full circle.
|
|
|
|
do {
|
|
|
|
it++;
|
|
|
|
if (it == sSystemVector.crend())
|
|
|
|
it = sSystemVector.crbegin();
|
|
|
|
} while (!(*it)->isVisible());
|
2017-09-08 13:20:07 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return *it;
|
2017-09-08 13:20:07 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::string SystemData::getGamelistPath(bool forWrite) const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string filePath;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
filePath = mRootFolder->getPath() + "/gamelist.xml";
|
|
|
|
if (Utils::FileSystem::exists(filePath))
|
|
|
|
return filePath;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
filePath = Utils::FileSystem::getHomePath() + "/.emulationstation/gamelists/" + mName +
|
|
|
|
"/gamelist.xml";
|
2020-06-22 17:46:09 +00:00
|
|
|
|
|
|
|
// Make sure the directory exists if we're going to write to it,
|
|
|
|
// or crashes will happen.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (forWrite)
|
|
|
|
Utils::FileSystem::createDirectory(Utils::FileSystem::getParent(filePath));
|
|
|
|
if (forWrite || Utils::FileSystem::exists(filePath))
|
|
|
|
return filePath;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-22 17:46:09 +00:00
|
|
|
return "";
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SystemData::getThemePath() const
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// First, check game folder.
|
|
|
|
std::string localThemePath = mRootFolder->getPath() + "/theme.xml";
|
|
|
|
if (Utils::FileSystem::exists(localThemePath))
|
|
|
|
return localThemePath;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Not in game folder, try system theme in theme sets.
|
|
|
|
localThemePath = ThemeData::getThemeFromCurrentSet(mThemeFolder);
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Utils::FileSystem::exists(localThemePath))
|
|
|
|
return localThemePath;
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Not system theme, try default system theme in theme set.
|
2021-07-07 18:03:42 +00:00
|
|
|
localThemePath =
|
|
|
|
Utils::FileSystem::getParent(Utils::FileSystem::getParent(localThemePath)) + "/theme.xml";
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return localThemePath;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 13:19:54 +00:00
|
|
|
SystemData* SystemData::getRandomSystem(const SystemData* currentSystem)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
unsigned int total = 0;
|
|
|
|
for (auto it = sSystemVector.cbegin(); it != sSystemVector.cend(); it++) {
|
|
|
|
if ((*it)->isGameSystem())
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
2020-07-28 13:19:54 +00:00
|
|
|
if (total < 2)
|
|
|
|
return nullptr;
|
|
|
|
|
2020-10-17 12:32:08 +00:00
|
|
|
SystemData* randomSystem = nullptr;
|
2020-07-28 13:19:54 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
// Get a random number in range.
|
2020-10-21 19:56:31 +00:00
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
2021-08-17 16:41:45 +00:00
|
|
|
std::mt19937 engine{randDev()};
|
2020-10-21 19:56:31 +00:00
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, total - 1);
|
|
|
|
int target = uniform_dist(engine);
|
2020-07-28 13:19:54 +00:00
|
|
|
|
|
|
|
for (auto it = sSystemVector.cbegin(); it != sSystemVector.cend(); it++) {
|
|
|
|
if ((*it)->isGameSystem()) {
|
|
|
|
if (target > 0) {
|
|
|
|
target--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
randomSystem = (*it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
} while (randomSystem == currentSystem);
|
2020-07-28 13:19:54 +00:00
|
|
|
|
|
|
|
return randomSystem;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileData* SystemData::getRandomGame(const FileData* currentGame)
|
2017-06-12 16:38:59 +00:00
|
|
|
{
|
2020-10-31 10:33:43 +00:00
|
|
|
std::vector<FileData*> gameList;
|
|
|
|
bool onlyFolders = false;
|
|
|
|
bool hasFolders = false;
|
|
|
|
|
|
|
|
// If we're in the custom collection group list, then get the list of collections,
|
|
|
|
// otherwise get a list of all the folder and file entries in the view.
|
2021-07-07 18:03:42 +00:00
|
|
|
if (currentGame && currentGame->getType() == FOLDER &&
|
|
|
|
currentGame->getSystem()->isGroupedCustomCollection()) {
|
2021-01-02 14:11:56 +00:00
|
|
|
gameList = mRootFolder->getParent()->getChildrenListToDisplay();
|
2020-10-31 10:33:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
gameList = ViewController::get()
|
|
|
|
->getGameListView(mRootFolder->getSystem())
|
|
|
|
.get()
|
|
|
|
->getCursor()
|
|
|
|
->getParent()
|
|
|
|
->getChildrenListToDisplay();
|
2020-10-31 10:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gameList.size() > 0 && gameList.front()->getParent()->getOnlyFoldersFlag())
|
|
|
|
onlyFolders = true;
|
|
|
|
|
|
|
|
if (gameList.size() > 0 && gameList.front()->getParent()->getHasFoldersFlag())
|
|
|
|
hasFolders = true;
|
|
|
|
|
|
|
|
// If this is a mixed view of folders and files, then remove all the folder entries
|
|
|
|
// as we want to exclude them from the random selection.
|
|
|
|
if (!onlyFolders && hasFolders) {
|
|
|
|
unsigned int i = 0;
|
|
|
|
do {
|
|
|
|
if (gameList[i]->getType() == FOLDER)
|
|
|
|
gameList.erase(gameList.begin() + i);
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
} while (i < gameList.size());
|
|
|
|
}
|
2020-07-28 13:19:54 +00:00
|
|
|
|
2020-10-21 19:56:31 +00:00
|
|
|
if (!currentGame && gameList.size() == 1)
|
2020-10-20 20:02:33 +00:00
|
|
|
return gameList.front();
|
|
|
|
|
2020-10-31 10:33:43 +00:00
|
|
|
// If there is only one folder and one file in the list, then return the file.
|
|
|
|
if (!onlyFolders && hasFolders && gameList.size() == 1)
|
|
|
|
return gameList.front();
|
|
|
|
|
2020-08-06 21:41:44 +00:00
|
|
|
if (currentGame && currentGame->getType() == PLACEHOLDER)
|
|
|
|
return nullptr;
|
|
|
|
|
2020-10-31 10:33:43 +00:00
|
|
|
unsigned int total = static_cast<int>(gameList.size());
|
2020-06-21 12:25:28 +00:00
|
|
|
int target = 0;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-07-28 13:19:54 +00:00
|
|
|
if (total < 2)
|
2020-06-23 18:07:00 +00:00
|
|
|
return nullptr;
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-07-28 13:19:54 +00:00
|
|
|
do {
|
|
|
|
// Get a random number in range.
|
2020-10-21 19:56:31 +00:00
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
2021-08-17 16:41:45 +00:00
|
|
|
std::mt19937 engine{randDev()};
|
2020-10-21 19:56:31 +00:00
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, total - 1);
|
|
|
|
target = uniform_dist(engine);
|
2021-07-07 18:03:42 +00:00
|
|
|
} while (currentGame && gameList.at(target) == currentGame);
|
2020-07-28 13:19:54 +00:00
|
|
|
|
|
|
|
return gameList.at(target);
|
2017-06-12 16:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
void SystemData::sortSystem(bool reloadGamelist, bool jumpToFirstRow)
|
2020-09-26 11:03:14 +00:00
|
|
|
{
|
|
|
|
if (getName() == "recent")
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool favoritesSorting;
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
if (this->isCustomCollection() ||
|
2021-07-07 18:03:42 +00:00
|
|
|
(this->isCollection() && this->getFullName() == "collections")) {
|
2020-09-26 11:03:14 +00:00
|
|
|
favoritesSorting = Settings::getInstance()->getBool("FavFirstCustom");
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-09-26 11:03:14 +00:00
|
|
|
favoritesSorting = Settings::getInstance()->getBool("FavoritesFirst");
|
2021-07-07 18:03:42 +00:00
|
|
|
}
|
2020-09-26 11:03:14 +00:00
|
|
|
|
|
|
|
FileData* rootFolder = getRootFolder();
|
2020-10-21 19:56:31 +00:00
|
|
|
// Assign the sort type to all grouped custom collections.
|
|
|
|
if (mIsCollectionSystem && mFullName == "collections") {
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto it = rootFolder->getChildren().begin(); // Line break.
|
|
|
|
it != rootFolder->getChildren().end(); it++) {
|
2020-10-21 19:56:31 +00:00
|
|
|
setupSystemSortType((*it)->getSystem()->getRootFolder());
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 11:03:14 +00:00
|
|
|
setupSystemSortType(rootFolder);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
rootFolder->sort(rootFolder->getSortTypeFromString(rootFolder->getSortTypeString()),
|
|
|
|
favoritesSorting);
|
2020-09-26 11:03:14 +00:00
|
|
|
|
|
|
|
if (reloadGamelist)
|
|
|
|
ViewController::get()->reloadGameListView(this, false);
|
2020-11-05 17:18:11 +00:00
|
|
|
|
|
|
|
if (jumpToFirstRow) {
|
|
|
|
IGameListView* gameList = ViewController::get()->getGameListView(this).get();
|
|
|
|
gameList->setCursor(gameList->getFirstEntry());
|
|
|
|
}
|
2020-09-26 11:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 16:13:27 +00:00
|
|
|
std::pair<unsigned int, unsigned int> SystemData::getDisplayedGameCount() const
|
2017-03-18 17:54:39 +00:00
|
|
|
{
|
2020-09-21 16:13:27 +00:00
|
|
|
// Return all games for the system which are marked as 'countasgame'. As this flag is set
|
|
|
|
// by default, normally most games will be included in the number returned from here.
|
|
|
|
// The actual game counting takes place in FileData during sorting.
|
|
|
|
return mRootFolder->getGameCount();
|
2017-03-18 17:54:39 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void SystemData::loadTheme()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mTheme = std::make_shared<ThemeData>();
|
|
|
|
|
|
|
|
std::string path = getThemePath();
|
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(path)) // No theme available for this platform.
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Build map with system variables for theme to use.
|
|
|
|
std::map<std::string, std::string> sysData;
|
|
|
|
sysData.insert(std::pair<std::string, std::string>("system.name", getName()));
|
|
|
|
sysData.insert(std::pair<std::string, std::string>("system.theme", getThemeFolder()));
|
|
|
|
sysData.insert(std::pair<std::string, std::string>("system.fullName", getFullName()));
|
|
|
|
|
|
|
|
mTheme->loadFile(sysData, path);
|
|
|
|
}
|
|
|
|
catch (ThemeException& e) {
|
|
|
|
LOG(LogError) << e.what();
|
|
|
|
mTheme = std::make_shared<ThemeData>(); // Reset to empty.
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
void SystemData::writeMetaData()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Settings::getInstance()->getBool("IgnoreGamelist") || mIsCollectionSystem)
|
|
|
|
return;
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Save changed game data back to xml.
|
|
|
|
updateGamelist(this);
|
2019-08-24 14:22:02 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
void SystemData::onMetaDataSavePoint()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Settings::getInstance()->getString("SaveGamelistsMode") != "always")
|
|
|
|
return;
|
2019-08-24 14:22:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
writeMetaData();
|
2019-08-24 14:22:02 +00:00
|
|
|
}
|
2020-05-24 08:29:29 +00:00
|
|
|
|
|
|
|
void SystemData::setupSystemSortType(FileData* mRootFolder)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// If DefaultSortOrder is set to something, check that it is actually a valid value.
|
|
|
|
if (Settings::getInstance()->getString("DefaultSortOrder") != "") {
|
|
|
|
for (unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) {
|
|
|
|
if (FileSorts::SortTypes.at(i).description ==
|
2021-07-07 18:03:42 +00:00
|
|
|
Settings::getInstance()->getString("DefaultSortOrder")) {
|
|
|
|
mRootFolder->setSortTypeString(
|
|
|
|
Settings::getInstance()->getString("DefaultSortOrder"));
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 16:25:41 +00:00
|
|
|
// If no valid sort type was defined in the configuration file, set to default sorting.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mRootFolder->getSortTypeString() == "")
|
2021-07-07 18:03:42 +00:00
|
|
|
mRootFolder->setSortTypeString(
|
|
|
|
Settings::getInstance()->getDefaultString("DefaultSortOrder"));
|
2020-05-24 08:29:29 +00:00
|
|
|
}
|