2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// Gamelist.cpp
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Parses and updates the gamelist.xml files.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Gamelist.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
#include "FileData.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "Settings.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
|
|
|
#include "utils/StringUtil.h"
|
2020-08-23 15:04:30 +00:00
|
|
|
|
2020-06-24 15:38:41 +00:00
|
|
|
#include <pugixml.hpp>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType type)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// First, verify that path is within the system's root folder.
|
|
|
|
FileData* root = system->getRootFolder();
|
|
|
|
bool contains = false;
|
|
|
|
std::string relative = Utils::FileSystem::removeCommonPath(path, root->getPath(), contains);
|
|
|
|
|
|
|
|
if (!contains) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Path \"" << path << "\" is outside system path \""
|
|
|
|
<< system->getStartPath() << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::FileSystem::stringList pathList = Utils::FileSystem::getPathList(relative);
|
|
|
|
auto path_it = pathList.begin();
|
|
|
|
FileData* treeNode = root;
|
|
|
|
bool found = false;
|
|
|
|
while (path_it != pathList.end()) {
|
|
|
|
const std::unordered_map<std::string, FileData*>& children =
|
2021-07-07 18:03:42 +00:00
|
|
|
treeNode->getChildrenByFilename();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
std::string key = *path_it;
|
|
|
|
found = children.find(key) != children.cend();
|
|
|
|
if (found) {
|
|
|
|
treeNode = children.at(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the end
|
|
|
|
if (path_it == --pathList.end()) {
|
|
|
|
if (found)
|
|
|
|
return treeNode;
|
|
|
|
|
|
|
|
if (type == FOLDER) {
|
2021-01-01 17:36:53 +00:00
|
|
|
LOG(LogWarning) << "A folder defined in the gamelist file does not exist:";
|
2020-06-21 12:25:28 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileData* file = new FileData(type, path, system->getSystemEnvData(), system);
|
|
|
|
|
|
|
|
// Skipping arcade assets from gamelist.
|
|
|
|
if (!file->isArcadeAsset())
|
|
|
|
treeNode->addChild(file);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
// Don't create folders unless they're including any games.
|
|
|
|
// If the type is FOLDER it's going to be empty, so don't bother.
|
|
|
|
if (type == FOLDER) {
|
2021-01-01 17:36:53 +00:00
|
|
|
LOG(LogWarning) << "A folder defined in the gamelist file does not exist:";
|
2020-06-21 12:25:28 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create missing folder.
|
2021-07-07 18:03:42 +00:00
|
|
|
FileData* folder = new FileData(
|
|
|
|
FOLDER, Utils::FileSystem::getStem(treeNode->getPath()) + "/" + *path_it,
|
|
|
|
system->getSystemEnvData(), system);
|
2020-06-21 12:25:28 +00:00
|
|
|
treeNode->addChild(folder);
|
|
|
|
treeNode = folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void parseGamelist(SystemData* system)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
bool trustGamelist = Settings::getInstance()->getBool("ParseGamelistOnly");
|
|
|
|
std::string xmlpath = system->getGamelistPath(false);
|
|
|
|
|
2021-02-08 19:59:10 +00:00
|
|
|
if (!Utils::FileSystem::exists(xmlpath)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "Gamelist::parseGamelist(): System \"" << system->getName()
|
|
|
|
<< "\" does not have a gamelist.xml file";
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
2021-02-08 19:59:10 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogInfo) << "Parsing gamelist file \"" << xmlpath << "\"...";
|
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 result =
|
2021-07-07 18:03:42 +00:00
|
|
|
doc.load_file(Utils::String::stringToWideString(xmlpath).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_parse_result result = doc.load_file(xmlpath.c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!result) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Error parsing gamelist file \"" << xmlpath
|
|
|
|
<< "\": " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node root = doc.child("gameList");
|
|
|
|
if (!root) {
|
2021-03-15 20:01:59 +00:00
|
|
|
LOG(LogError) << "Couldn't find <gameList> node in gamelist \"" << xmlpath << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
pugi::xml_node alternativeEmulator = doc.child("alternativeEmulator");
|
|
|
|
if (alternativeEmulator) {
|
|
|
|
std::string label = alternativeEmulator.child("label").text().get();
|
|
|
|
if (label != "") {
|
|
|
|
bool validLabel = false;
|
|
|
|
for (auto command : system->getSystemEnvData()->mLaunchCommands) {
|
|
|
|
if (command.second == label)
|
|
|
|
validLabel = true;
|
|
|
|
}
|
|
|
|
if (validLabel) {
|
|
|
|
system->setAlternativeEmulator(label);
|
|
|
|
LOG(LogDebug) << "Gamelist::parseGamelist(): System \"" << system->getName()
|
|
|
|
<< "\" has a valid alternativeEmulator entry: \"" << label << "\"";
|
|
|
|
}
|
|
|
|
else {
|
2021-09-04 09:21:55 +00:00
|
|
|
system->setAlternativeEmulator("<INVALID>" + label);
|
2021-08-22 13:26:38 +00:00
|
|
|
LOG(LogWarning) << "System \"" << system->getName()
|
|
|
|
<< "\" has an invalid alternativeEmulator entry that does "
|
|
|
|
"not match any command tag in es_systems.xml: \""
|
|
|
|
<< label << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string relativeTo = system->getStartPath();
|
2020-07-26 11:58:49 +00:00
|
|
|
bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles");
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-08-17 16:41:45 +00:00
|
|
|
std::vector<std::string> tagList = {"game", "folder"};
|
|
|
|
FileType typeList[2] = {GAME, FOLDER};
|
2020-06-21 12:25:28 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
2020-12-16 22:59:00 +00:00
|
|
|
std::string tag = tagList[i];
|
2020-06-21 12:25:28 +00:00
|
|
|
FileType type = typeList[i];
|
2021-07-07 18:03:42 +00:00
|
|
|
for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode;
|
|
|
|
fileNode = fileNode.next_sibling(tag.c_str())) {
|
|
|
|
const std::string path = Utils::FileSystem::resolveRelativePath(
|
|
|
|
fileNode.child("path").text().get(), relativeTo, false);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!trustGamelist && !Utils::FileSystem::exists(path)) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogWarning) << (type == GAME ? "File \"" : "Folder \"") << path
|
|
|
|
<< "\" does not exist, ignoring entry";
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-26 13:21:41 +00:00
|
|
|
// Skip hidden files, check both the file itself and the directory in which
|
|
|
|
// it is located.
|
2021-07-07 18:03:42 +00:00
|
|
|
if (!showHiddenFiles &&
|
|
|
|
(Utils::FileSystem::isHidden(path) ||
|
|
|
|
Utils::FileSystem::isHidden(Utils::FileSystem::getParent(path)))) {
|
|
|
|
LOG(LogDebug) << "Gamelist::parseGamelist(): Skipping hidden file \"" << path
|
|
|
|
<< "\"";
|
2020-07-26 11:58:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
FileData* file = findOrCreateFile(system, path, type);
|
|
|
|
if (!file) {
|
2021-03-15 20:01:59 +00:00
|
|
|
LOG(LogError) << "Couldn't find or create \"" << path << "\", skipping entry";
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!file->isArcadeAsset()) {
|
|
|
|
std::string defaultName = file->metadata.get("name");
|
|
|
|
file->metadata = MetaDataList::createFromXML(GAME_METADATA, fileNode, relativeTo);
|
|
|
|
|
|
|
|
// Make sure a name gets set if one doesn't exist.
|
|
|
|
if (file->metadata.get("name").empty())
|
|
|
|
file->metadata.set("name", defaultName);
|
|
|
|
|
|
|
|
file->metadata.resetChangedFlag();
|
|
|
|
}
|
2021-03-15 20:01:59 +00:00
|
|
|
else {
|
|
|
|
// Skip arcade asset entries as these will not be used in any way inside
|
|
|
|
// the application.
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "Gamelist::parseGamelist(): Skipping arcade asset \""
|
|
|
|
<< file->getName() << "\"";
|
2021-03-15 20:01:59 +00:00
|
|
|
delete file;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-18 17:14:34 +00:00
|
|
|
// If the game is flagged as hidden and the option has not been set to show hidden
|
|
|
|
// games, then delete the entry. This leaves no trace of the entry at all in ES
|
|
|
|
// but that is fine as the option to show hidden files is defined as requiring an
|
|
|
|
// application restart.
|
2020-11-08 17:33:28 +00:00
|
|
|
if (!Settings::getInstance()->getBool("ShowHiddenGames")) {
|
|
|
|
if (file->getHidden()) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogDebug) << "Gamelist::parseGamelist(): Skipping hidden "
|
|
|
|
<< (type == GAME ? "file" : "folder") << " entry \""
|
|
|
|
<< file->getName() << "\""
|
|
|
|
<< " (\"" << file->getPath() << "\")";
|
2020-11-08 17:33:28 +00:00
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
// Also delete any folders which are empty, i.e. all their entries are hidden.
|
|
|
|
else if (file->getType() == FOLDER && file->getChildren().size() == 0) {
|
|
|
|
delete file;
|
|
|
|
}
|
2020-10-18 17:14:34 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
void addFileDataNode(pugi::xml_node& parent,
|
|
|
|
const FileData* file,
|
|
|
|
const std::string& tag,
|
|
|
|
SystemData* system)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Create game and add to parent node.
|
2020-12-16 22:59:00 +00:00
|
|
|
pugi::xml_node newNode = parent.append_child(tag.c_str());
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Write metadata.
|
|
|
|
file->metadata.appendToXML(newNode, true, system->getStartPath());
|
|
|
|
|
|
|
|
// First element is "name", there's only one element and the name is the default.
|
|
|
|
if (newNode.children().begin() == newNode.child("name") &&
|
2021-07-07 18:03:42 +00:00
|
|
|
++newNode.children().begin() == newNode.children().end() &&
|
|
|
|
newNode.child("name").text().get() == file->getDisplayName()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// If the only info is the default name, don't bother
|
|
|
|
// with this node, delete it and ultimately do nothing.
|
|
|
|
parent.remove_child(newNode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// There's something useful in there so we'll keep the node, add the path.
|
|
|
|
|
|
|
|
// Try and make the path relative if we can so things still
|
|
|
|
// work if we change the ROM folder location in the future.
|
2021-07-07 18:03:42 +00:00
|
|
|
newNode.prepend_child("path").text().set(
|
|
|
|
Utils::FileSystem::createRelativePath(file->getPath(), system->getStartPath(), false)
|
|
|
|
.c_str());
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
void updateGamelist(SystemData* system, bool updateAlternativeEmulator)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// We do this by reading the XML again, adding changes and then writing them back,
|
|
|
|
// because there might be information missing in our systemdata which we would otherwise
|
|
|
|
// miss in the new XML file. We have the complete information for every game though, so
|
|
|
|
// we can simply remove a game we already have in the system from the XML, and then add
|
|
|
|
// it back from its GameData information...
|
|
|
|
if (Settings::getInstance()->getBool("IgnoreGamelist"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_node root;
|
|
|
|
std::string xmlReadPath = system->getGamelistPath(false);
|
2021-08-25 18:58:03 +00:00
|
|
|
bool hasAlternativeEmulatorTag = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(xmlReadPath)) {
|
|
|
|
// Parse an existing file first.
|
2021-07-07 18:03:42 +00:00
|
|
|
|
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
pugi::xml_parse_result result =
|
2021-07-07 18:03:42 +00:00
|
|
|
doc.load_file(Utils::String::stringToWideString(xmlReadPath).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_parse_result result = doc.load_file(xmlReadPath.c_str());
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (!result) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Error parsing gamelist file \"" << xmlReadPath
|
|
|
|
<< "\": " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
root = doc.child("gameList");
|
|
|
|
if (!root) {
|
2021-07-07 18:03:42 +00:00
|
|
|
LOG(LogError) << "Couldn't find <gameList> node in gamelist \"" << xmlReadPath << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-08-22 13:26:38 +00:00
|
|
|
if (updateAlternativeEmulator) {
|
|
|
|
pugi::xml_node alternativeEmulator = doc.child("alternativeEmulator");
|
|
|
|
|
2021-08-25 18:58:03 +00:00
|
|
|
if (alternativeEmulator)
|
|
|
|
hasAlternativeEmulatorTag = true;
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
if (system->getAlternativeEmulator() != "") {
|
|
|
|
if (!alternativeEmulator) {
|
|
|
|
doc.prepend_child("alternativeEmulator");
|
|
|
|
alternativeEmulator = doc.child("alternativeEmulator");
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node label = alternativeEmulator.child("label");
|
|
|
|
|
|
|
|
if (label && system->getAlternativeEmulator() !=
|
|
|
|
alternativeEmulator.child("label").text().get()) {
|
|
|
|
alternativeEmulator.remove_child(label);
|
|
|
|
alternativeEmulator.prepend_child("label").text().set(
|
|
|
|
system->getAlternativeEmulator().c_str());
|
|
|
|
}
|
|
|
|
else if (!label) {
|
|
|
|
alternativeEmulator.prepend_child("label").text().set(
|
|
|
|
system->getAlternativeEmulator().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (alternativeEmulator) {
|
|
|
|
doc.remove_child("alternativeEmulator");
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-08-22 13:26:38 +00:00
|
|
|
if (updateAlternativeEmulator && system->getAlternativeEmulator() != "") {
|
|
|
|
pugi::xml_node alternativeEmulator = doc.prepend_child("alternativeEmulator");
|
|
|
|
alternativeEmulator.prepend_child("label").text().set(
|
|
|
|
system->getAlternativeEmulator().c_str());
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
// Set up an empty gamelist to append to.
|
|
|
|
root = doc.append_child("gameList");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we have all the information from the XML file, so iterate
|
|
|
|
// through all our games and add the information from there.
|
|
|
|
FileData* rootFolder = system->getRootFolder();
|
|
|
|
if (rootFolder != nullptr) {
|
|
|
|
int numUpdated = 0;
|
|
|
|
|
|
|
|
// Get only files, no folders.
|
|
|
|
std::vector<FileData*> files = rootFolder->getFilesRecursive(GAME | FOLDER);
|
|
|
|
// Iterate through all files, checking if they're already in the XML file.
|
2021-07-07 18:03:42 +00:00
|
|
|
for (std::vector<FileData*>::const_iterator fit = files.cbegin(); // Line break.
|
|
|
|
fit != files.cend(); fit++) {
|
2020-12-16 22:59:00 +00:00
|
|
|
const std::string tag = ((*fit)->getType() == GAME) ? "game" : "folder";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-07-13 18:13:48 +00:00
|
|
|
// Do not touch if it wasn't changed and is not flagged for deletion.
|
|
|
|
if (!(*fit)->metadata.wasChanged() && !(*fit)->getDeletionFlag())
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check if the file already exists in the XML file.
|
|
|
|
// If it does, remove the entry before adding it back.
|
2020-12-16 22:59:00 +00:00
|
|
|
for (pugi::xml_node fileNode = root.child(tag.c_str()); fileNode;
|
2021-07-07 18:03:42 +00:00
|
|
|
fileNode = fileNode.next_sibling(tag.c_str())) {
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_node pathNode = fileNode.child("path");
|
|
|
|
if (!pathNode) {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "<" << tag << "> node contains no <path> child";
|
2020-06-21 12:25:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string nodePath =
|
|
|
|
Utils::FileSystem::getCanonicalPath(Utils::FileSystem::resolveRelativePath(
|
|
|
|
pathNode.text().get(), system->getStartPath(), true));
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string gamePath = Utils::FileSystem::getCanonicalPath((*fit)->getPath());
|
2020-07-13 18:13:48 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (nodePath == gamePath) {
|
|
|
|
// Found it
|
|
|
|
root.remove_child(fileNode);
|
2020-07-13 18:13:48 +00:00
|
|
|
if ((*fit)->getDeletionFlag())
|
2021-01-25 17:07:11 +00:00
|
|
|
numUpdated++;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 18:13:48 +00:00
|
|
|
// Add the game to the file, unless it's flagged for deletion.
|
|
|
|
if (!(*fit)->getDeletionFlag()) {
|
|
|
|
addFileDataNode(root, *fit, tag, system);
|
2020-10-18 10:42:37 +00:00
|
|
|
(*fit)->metadata.resetChangedFlag();
|
2021-01-25 17:07:11 +00:00
|
|
|
numUpdated++;
|
2020-07-13 18:13:48 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now write the file.
|
2021-08-22 13:26:38 +00:00
|
|
|
if (numUpdated > 0 || updateAlternativeEmulator) {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Make sure the folders leading up to this path exist (or the write will fail).
|
|
|
|
std::string xmlWritePath(system->getGamelistPath(true));
|
|
|
|
Utils::FileSystem::createDirectory(Utils::FileSystem::getParent(xmlWritePath));
|
|
|
|
|
2021-08-22 13:26:38 +00:00
|
|
|
if (updateAlternativeEmulator) {
|
2021-08-25 18:58:03 +00:00
|
|
|
if (hasAlternativeEmulatorTag && system->getAlternativeEmulator() == "") {
|
2021-08-22 13:26:38 +00:00
|
|
|
LOG(LogDebug) << "Gamelist::updateGamelist(): Removed the "
|
|
|
|
"alternativeEmulator tag for system \""
|
|
|
|
<< system->getName() << "\" as the default emulator \""
|
|
|
|
<< system->getSystemEnvData()->mLaunchCommands.front().second
|
|
|
|
<< "\" was selected";
|
|
|
|
}
|
2021-08-25 18:58:03 +00:00
|
|
|
else if (system->getAlternativeEmulator() != "") {
|
2021-08-22 13:26:38 +00:00
|
|
|
LOG(LogDebug) << "Gamelist::updateGamelist(): "
|
|
|
|
"Added/updated the alternativeEmulator tag for system \""
|
|
|
|
<< system->getName() << "\" to \""
|
|
|
|
<< system->getAlternativeEmulator() << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (numUpdated > 0) {
|
|
|
|
LOG(LogDebug) << "Gamelist::updateGamelist(): Added/updated " << numUpdated
|
|
|
|
<< (numUpdated == 1 ? " entity in \"" : " entities in \"")
|
|
|
|
<< xmlWritePath << "\"";
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
if (!doc.save_file(Utils::String::stringToWideString(xmlWritePath).c_str())) {
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!doc.save_file(xmlWritePath.c_str())) {
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
|
|
|
LOG(LogError) << "Error saving gamelist.xml to \"" << xmlWritePath
|
|
|
|
<< "\" (for system " << system->getName() << ")";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-10-19 15:28:20 +00:00
|
|
|
LOG(LogError) << "Found no root folder for system \"" << system->getName() << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|