mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Completely refactored MameNames.
This commit is contained in:
parent
83bf80196e
commit
445b914379
|
@ -47,7 +47,7 @@ FileData::FileData(FileType type,
|
||||||
system->hasPlatformId(PlatformIds::SNK_NEO_GEO)) &&
|
system->hasPlatformId(PlatformIds::SNK_NEO_GEO)) &&
|
||||||
metadata.getType() != FOLDER_METADATA) {
|
metadata.getType() != FOLDER_METADATA) {
|
||||||
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
||||||
metadata.set("name", MameNames::getInstance()->getCleanName(getCleanName()));
|
metadata.set("name", MameNames::getInstance().getCleanName(getCleanName()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (metadata.getType() == FOLDER_METADATA && Utils::FileSystem::isHidden(mPath)) {
|
if (metadata.getType() == FOLDER_METADATA && Utils::FileSystem::isHidden(mPath)) {
|
||||||
|
@ -414,7 +414,7 @@ const bool FileData::isArcadeAsset() const
|
||||||
const std::string stem = Utils::FileSystem::getStem(mPath);
|
const std::string stem = Utils::FileSystem::getStem(mPath);
|
||||||
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
||||||
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
||||||
(MameNames::getInstance()->isBios(stem) || MameNames::getInstance()->isDevice(stem)));
|
(MameNames::getInstance().isBios(stem) || MameNames::getInstance().isDevice(stem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool FileData::isArcadeGame() const
|
const bool FileData::isArcadeGame() const
|
||||||
|
@ -422,7 +422,7 @@ const bool FileData::isArcadeGame() const
|
||||||
const std::string stem = Utils::FileSystem::getStem(mPath);
|
const std::string stem = Utils::FileSystem::getStem(mPath);
|
||||||
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
||||||
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
mSystem->hasPlatformId(PlatformIds::SNK_NEO_GEO))) &&
|
||||||
(!MameNames::getInstance()->isBios(stem) && !MameNames::getInstance()->isDevice(stem)));
|
(!MameNames::getInstance().isBios(stem) && !MameNames::getInstance().isDevice(stem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileData::addChild(FileData* file)
|
void FileData::addChild(FileData* file)
|
||||||
|
|
|
@ -38,9 +38,9 @@ GuiGameScraper::GuiGameScraper(Window* window,
|
||||||
else {
|
else {
|
||||||
if (params.game->isArcadeGame() &&
|
if (params.game->isArcadeGame() &&
|
||||||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||||
scrapeName =
|
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath()) + " (" +
|
||||||
Utils::FileSystem::getFileName(mSearchParams.game->getPath()) + " (" +
|
MameNames::getInstance().getCleanName(mSearchParams.game->getCleanName()) +
|
||||||
MameNames::getInstance()->getCleanName(mSearchParams.game->getCleanName()) + ")";
|
")";
|
||||||
else
|
else
|
||||||
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath());
|
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,8 +397,8 @@ void GuiGamelistOptions::openMetaDataEd()
|
||||||
if (it->key == "name") {
|
if (it->key == "name") {
|
||||||
if (file->isArcadeGame()) {
|
if (file->isArcadeGame()) {
|
||||||
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
||||||
file->metadata.set(
|
file->metadata.set(it->key,
|
||||||
it->key, MameNames::getInstance()->getCleanName(file->getCleanName()));
|
MameNames::getInstance().getCleanName(file->getCleanName()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file->metadata.set(it->key, file->getDisplayName());
|
file->metadata.set(it->key, file->getDisplayName());
|
||||||
|
|
|
@ -230,7 +230,7 @@ void GuiScraperMulti::doNextSearch()
|
||||||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||||
scrapeName =
|
scrapeName =
|
||||||
Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath()) + " (" +
|
Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath()) + " (" +
|
||||||
MameNames::getInstance()->getCleanName(mSearchQueue.front().game->getCleanName()) +
|
MameNames::getInstance().getCleanName(mSearchQueue.front().game->getCleanName()) +
|
||||||
")";
|
")";
|
||||||
else
|
else
|
||||||
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
|
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
|
||||||
|
|
|
@ -826,7 +826,7 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
|
||||||
// required as TheGamesDB does not support searches using the short MAME names.
|
// required as TheGamesDB does not support searches using the short MAME names.
|
||||||
if (params.game->isArcadeGame() &&
|
if (params.game->isArcadeGame() &&
|
||||||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||||
searchString = MameNames::getInstance()->getCleanName(params.game->getCleanName());
|
searchString = MameNames::getInstance().getCleanName(params.game->getCleanName());
|
||||||
else
|
else
|
||||||
searchString = params.game->getCleanName();
|
searchString = params.game->getCleanName();
|
||||||
}
|
}
|
||||||
|
@ -859,7 +859,7 @@ bool GuiScraperSearch::saveMetadata(const ScraperSearchResult& result,
|
||||||
// Get the default name, which is either the MAME name or the name of the physical file
|
// Get the default name, which is either the MAME name or the name of the physical file
|
||||||
// or directory.
|
// or directory.
|
||||||
if (scrapedGame->isArcadeGame())
|
if (scrapedGame->isArcadeGame())
|
||||||
defaultName = MameNames::getInstance()->getCleanName(scrapedGame->getCleanName());
|
defaultName = MameNames::getInstance().getCleanName(scrapedGame->getCleanName());
|
||||||
else
|
else
|
||||||
defaultName = Utils::FileSystem::getStem(scrapedGame->getFileName());
|
defaultName = Utils::FileSystem::getStem(scrapedGame->getFileName());
|
||||||
|
|
||||||
|
|
|
@ -596,7 +596,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioManager::getInstance();
|
AudioManager::getInstance();
|
||||||
MameNames::init();
|
MameNames::getInstance();
|
||||||
loadSystemsReturnCode loadSystemsStatus = loadSystemConfigFile();
|
loadSystemsReturnCode loadSystemsStatus = loadSystemConfigFile();
|
||||||
|
|
||||||
if (loadSystemsStatus) {
|
if (loadSystemsStatus) {
|
||||||
|
@ -701,7 +701,6 @@ int main(int argc, char* argv[])
|
||||||
delete window.peekGui();
|
delete window.peekGui();
|
||||||
window.deinit();
|
window.deinit();
|
||||||
|
|
||||||
MameNames::deinit();
|
|
||||||
CollectionSystemsManager::deinit();
|
CollectionSystemsManager::deinit();
|
||||||
SystemData::deleteSystems();
|
SystemData::deleteSystems();
|
||||||
NavigationSounds::getInstance().deinit();
|
NavigationSounds::getInstance().deinit();
|
||||||
|
|
|
@ -157,7 +157,7 @@ void thegamesdb_generate_json_scraper_requests(
|
||||||
// arcade game and if so expand to the full game name. This is required as
|
// arcade game and if so expand to the full game name. This is required as
|
||||||
// TheGamesDB has issues with searching using the short MAME names.
|
// TheGamesDB has issues with searching using the short MAME names.
|
||||||
if (params.game->isArcadeGame())
|
if (params.game->isArcadeGame())
|
||||||
cleanName = MameNames::getInstance()->getCleanName(params.game->getCleanName());
|
cleanName = MameNames::getInstance().getCleanName(params.game->getCleanName());
|
||||||
else
|
else
|
||||||
cleanName = params.game->getCleanName();
|
cleanName = params.game->getCleanName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,33 +14,14 @@
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "resources/ResourceManager.h"
|
#include "resources/ResourceManager.h"
|
||||||
#include "utils/FileSystemUtil.h"
|
#include "utils/FileSystemUtil.h"
|
||||||
#include "utils/StringUtil.h"
|
|
||||||
|
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
MameNames* MameNames::sInstance = nullptr;
|
MameNames& MameNames::getInstance()
|
||||||
|
|
||||||
void MameNames::init()
|
|
||||||
{
|
{
|
||||||
if (!sInstance)
|
static MameNames instance;
|
||||||
sInstance = new MameNames();
|
return instance;
|
||||||
}
|
|
||||||
|
|
||||||
void MameNames::deinit()
|
|
||||||
{
|
|
||||||
if (sInstance) {
|
|
||||||
delete sInstance;
|
|
||||||
sInstance = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MameNames* MameNames::getInstance()
|
|
||||||
{
|
|
||||||
if (!sInstance)
|
|
||||||
sInstance = new MameNames();
|
|
||||||
|
|
||||||
return sInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MameNames::MameNames()
|
MameNames::MameNames()
|
||||||
|
@ -68,9 +49,8 @@ MameNames::MameNames()
|
||||||
|
|
||||||
for (pugi::xml_node gameNode = doc.child("game"); gameNode;
|
for (pugi::xml_node gameNode = doc.child("game"); gameNode;
|
||||||
gameNode = gameNode.next_sibling("game")) {
|
gameNode = gameNode.next_sibling("game")) {
|
||||||
NamePair namePair = {gameNode.child("mamename").text().get(),
|
mNamePairs[gameNode.child("mamename").text().get()] =
|
||||||
gameNode.child("realname").text().get()};
|
gameNode.child("realname").text().get();
|
||||||
mNamePairs.push_back(namePair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read BIOS file.
|
// Read BIOS file.
|
||||||
|
@ -96,7 +76,7 @@ MameNames::MameNames()
|
||||||
for (pugi::xml_node biosNode = doc.child("bios"); biosNode;
|
for (pugi::xml_node biosNode = doc.child("bios"); biosNode;
|
||||||
biosNode = biosNode.next_sibling("bios")) {
|
biosNode = biosNode.next_sibling("bios")) {
|
||||||
std::string bios = biosNode.text().get();
|
std::string bios = biosNode.text().get();
|
||||||
mMameBioses.push_back(bios);
|
mMameBioses.emplace_back(bios);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read device file.
|
// Read device file.
|
||||||
|
@ -122,53 +102,6 @@ MameNames::MameNames()
|
||||||
for (pugi::xml_node deviceNode = doc.child("device"); deviceNode;
|
for (pugi::xml_node deviceNode = doc.child("device"); deviceNode;
|
||||||
deviceNode = deviceNode.next_sibling("device")) {
|
deviceNode = deviceNode.next_sibling("device")) {
|
||||||
std::string device = deviceNode.text().get();
|
std::string device = deviceNode.text().get();
|
||||||
mMameDevices.push_back(device);
|
mMameDevices.emplace_back(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MameNames::getRealName(const std::string& _mameName)
|
|
||||||
{
|
|
||||||
size_t start = 0;
|
|
||||||
size_t end = mNamePairs.size();
|
|
||||||
|
|
||||||
while (start < end) {
|
|
||||||
const size_t index = (start + end) / 2;
|
|
||||||
const int compare = strcmp(mNamePairs[index].mameName.c_str(), _mameName.c_str());
|
|
||||||
|
|
||||||
if (compare < 0)
|
|
||||||
start = index + 1;
|
|
||||||
else if (compare > 0)
|
|
||||||
end = index;
|
|
||||||
else
|
|
||||||
return mNamePairs[index].realName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _mameName;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MameNames::getCleanName(const std::string& _mameName)
|
|
||||||
{
|
|
||||||
std::string cleanName = Utils::String::removeParenthesis(getRealName(_mameName));
|
|
||||||
return cleanName;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool MameNames::find(std::vector<std::string> devices, const std::string& name)
|
|
||||||
{
|
|
||||||
size_t start = 0;
|
|
||||||
size_t end = devices.size();
|
|
||||||
|
|
||||||
while (start < end) {
|
|
||||||
if (!strcmp(devices[start].c_str(), name.c_str()))
|
|
||||||
return true;
|
|
||||||
const size_t index = (start + end) / 2;
|
|
||||||
const int compare = strcmp(devices[index].c_str(), name.c_str());
|
|
||||||
|
|
||||||
if (compare < 0)
|
|
||||||
start = index + 1;
|
|
||||||
else if (compare > 0)
|
|
||||||
end = index;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,45 +12,50 @@
|
||||||
#ifndef ES_CORE_MAMENAMES_H
|
#ifndef ES_CORE_MAMENAMES_H
|
||||||
#define ES_CORE_MAMENAMES_H
|
#define ES_CORE_MAMENAMES_H
|
||||||
|
|
||||||
|
#include "utils/StringUtil.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Expand MAME names to full game names.
|
// Expand MAME names to full game names and lookup device and BIOS entries.
|
||||||
class MameNames
|
class MameNames
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void init();
|
static MameNames& getInstance();
|
||||||
static void deinit();
|
|
||||||
static MameNames* getInstance();
|
std::string getRealName(const std::string& mameName)
|
||||||
std::string getRealName(const std::string& _mameName);
|
|
||||||
std::string getCleanName(const std::string& _mameName);
|
|
||||||
const bool isBios(const std::string& _biosName)
|
|
||||||
{
|
{
|
||||||
return MameNames::find(mMameBioses, _biosName);
|
std::string name = mNamePairs[mameName];
|
||||||
|
if (name == "")
|
||||||
|
return mameName;
|
||||||
|
else
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
const bool isDevice(const std::string& _deviceName)
|
|
||||||
|
std::string getCleanName(const std::string& mameName)
|
||||||
{
|
{
|
||||||
return MameNames::find(mMameDevices, _deviceName);
|
return Utils::String::removeParenthesis(getRealName(mameName));
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool isBios(const std::string& biosName)
|
||||||
|
{
|
||||||
|
return std::find(mMameBioses.cbegin(), mMameBioses.cend(), biosName) != mMameBioses.cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool isDevice(const std::string& deviceName)
|
||||||
|
{
|
||||||
|
return std::find(mMameDevices.cbegin(), mMameDevices.cend(), deviceName) !=
|
||||||
|
mMameDevices.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct NamePair {
|
|
||||||
std::string mameName;
|
|
||||||
std::string realName;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<NamePair> namePairVector;
|
|
||||||
|
|
||||||
MameNames();
|
MameNames();
|
||||||
~MameNames() {}
|
|
||||||
|
|
||||||
static MameNames* sInstance;
|
std::unordered_map<std::string, std::string> mNamePairs;
|
||||||
|
|
||||||
namePairVector mNamePairs;
|
|
||||||
std::vector<std::string> mMameBioses;
|
std::vector<std::string> mMameBioses;
|
||||||
std::vector<std::string> mMameDevices;
|
std::vector<std::string> mMameDevices;
|
||||||
|
|
||||||
const bool find(const std::vector<std::string> devices, const std::string& name);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_MAMENAMES_H
|
#endif // ES_CORE_MAMENAMES_H
|
||||||
|
|
|
@ -262,7 +262,6 @@ void emergencyShutdown()
|
||||||
{
|
{
|
||||||
LOG(LogError) << "Critical - Performing emergency shutdown...";
|
LOG(LogError) << "Critical - Performing emergency shutdown...";
|
||||||
|
|
||||||
MameNames::deinit();
|
|
||||||
// Most of the SDL deinitialization is done in Renderer.
|
// Most of the SDL deinitialization is done in Renderer.
|
||||||
Renderer::deinit();
|
Renderer::deinit();
|
||||||
Log::flush();
|
Log::flush();
|
||||||
|
|
Loading…
Reference in a new issue