2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 11:10:33 +00:00
|
|
|
//
|
2024-07-10 16:04:40 +00:00
|
|
|
// ES-DE Frontend
|
2020-06-21 12:25:28 +00:00
|
|
|
// MameNames.cpp
|
2020-06-06 11:10:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Provides expanded game names based on short MAME name arguments. Also contains
|
|
|
|
// functions to check whether a passed argument is a MAME BIOS or a MAME device.
|
2023-12-15 17:33:02 +00:00
|
|
|
// The data sources are stored as the files mamebioses.xml, mamedevices.xml and mamenames.xml.
|
2020-06-06 11:10:33 +00:00
|
|
|
//
|
|
|
|
|
2018-02-09 17:23:58 +00:00
|
|
|
#include "MameNames.h"
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "Log.h"
|
2018-02-09 17:23:58 +00:00
|
|
|
#include "resources/ResourceManager.h"
|
|
|
|
#include "utils/FileSystemUtil.h"
|
2020-09-21 17:17:34 +00:00
|
|
|
|
2020-06-24 15:38:41 +00:00
|
|
|
#include <pugixml.hpp>
|
2018-02-09 17:23:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-11-17 20:32:40 +00:00
|
|
|
MameNames& MameNames::getInstance()
|
2018-02-09 17:23:58 +00:00
|
|
|
{
|
2021-11-17 20:32:40 +00:00
|
|
|
static MameNames instance;
|
|
|
|
return instance;
|
2020-06-06 11:10:33 +00:00
|
|
|
}
|
2018-02-09 17:23:58 +00:00
|
|
|
|
|
|
|
MameNames::MameNames()
|
|
|
|
{
|
2022-01-19 17:01:54 +00:00
|
|
|
std::string xmlpath {ResourceManager::getInstance().getResourcePath(":/MAME/mamenames.xml")};
|
2018-02-09 17:23:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(xmlpath))
|
|
|
|
return;
|
2018-02-09 17:23:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document doc;
|
2022-07-01 14:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#if defined(_WIN64)
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME names file \"" << Utils::String::replace(xmlpath, "/", "\\")
|
|
|
|
<< "\"...";
|
|
|
|
pugi::xml_parse_result result {
|
|
|
|
doc.load_file(Utils::String::stringToWideString(xmlpath).c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#else
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME names file \"" << xmlpath << "\"...";
|
|
|
|
pugi::xml_parse_result result {doc.load_file(xmlpath.c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#endif
|
2018-02-09 17:23:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result) {
|
2021-07-07 18:31:46 +00:00
|
|
|
LOG(LogError) << "Error parsing MAME names file \"" << xmlpath
|
|
|
|
<< "\": " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-09 17:23:58 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
for (pugi::xml_node gameNode = doc.child("game"); gameNode;
|
|
|
|
gameNode = gameNode.next_sibling("game")) {
|
2021-11-17 20:32:40 +00:00
|
|
|
mNamePairs[gameNode.child("mamename").text().get()] =
|
|
|
|
gameNode.child("realname").text().get();
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Read BIOS file.
|
2022-01-04 20:21:26 +00:00
|
|
|
xmlpath = ResourceManager::getInstance().getResourcePath(":/MAME/mamebioses.xml");
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(xmlpath))
|
|
|
|
return;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#if defined(_WIN64)
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME BIOSes file \"" << Utils::String::replace(xmlpath, "/", "\\")
|
|
|
|
<< "\"...";
|
2020-07-10 16:32:23 +00:00
|
|
|
result = doc.load_file(Utils::String::stringToWideString(xmlpath).c_str());
|
2021-07-07 18:31:46 +00:00
|
|
|
#else
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME BIOSes file \"" << xmlpath << "\"...";
|
2020-06-21 12:25:28 +00:00
|
|
|
result = doc.load_file(xmlpath.c_str());
|
2021-07-07 18:31:46 +00:00
|
|
|
#endif
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result) {
|
2021-07-07 18:31:46 +00:00
|
|
|
LOG(LogError) << "Error parsing MAME BIOSes file \"" << xmlpath
|
|
|
|
<< "\": " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
for (pugi::xml_node biosNode = doc.child("bios"); biosNode;
|
|
|
|
biosNode = biosNode.next_sibling("bios")) {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string bios = biosNode.text().get();
|
2021-11-17 20:32:40 +00:00
|
|
|
mMameBioses.emplace_back(bios);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
// Read device file.
|
2022-01-04 20:21:26 +00:00
|
|
|
xmlpath = ResourceManager::getInstance().getResourcePath(":/MAME/mamedevices.xml");
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(xmlpath))
|
|
|
|
return;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#if defined(_WIN64)
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME devices file \"" << Utils::String::replace(xmlpath, "/", "\\")
|
|
|
|
<< "\"...";
|
2020-07-10 16:32:23 +00:00
|
|
|
result = doc.load_file(Utils::String::stringToWideString(xmlpath).c_str());
|
2021-07-07 18:31:46 +00:00
|
|
|
#else
|
2022-07-01 14:39:18 +00:00
|
|
|
LOG(LogInfo) << "Parsing MAME devices file \"" << xmlpath << "\"...";
|
2020-06-21 12:25:28 +00:00
|
|
|
result = doc.load_file(xmlpath.c_str());
|
2021-07-07 18:31:46 +00:00
|
|
|
#endif
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result) {
|
2021-07-07 18:31:46 +00:00
|
|
|
LOG(LogError) << "Error parsing MAME devices file \"" << xmlpath
|
|
|
|
<< "\": " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
for (pugi::xml_node deviceNode = doc.child("device"); deviceNode;
|
|
|
|
deviceNode = deviceNode.next_sibling("device")) {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string device = deviceNode.text().get();
|
2021-11-17 20:32:40 +00:00
|
|
|
mMameDevices.emplace_back(device);
|
2020-12-16 23:20:25 +00:00
|
|
|
}
|
2018-05-10 01:29:46 +00:00
|
|
|
}
|