mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05: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)) &&
|
||||
metadata.getType() != FOLDER_METADATA) {
|
||||
// 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 {
|
||||
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);
|
||||
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
||||
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
|
||||
|
@ -422,7 +422,7 @@ const bool FileData::isArcadeGame() const
|
|||
const std::string stem = Utils::FileSystem::getStem(mPath);
|
||||
return ((mSystem && (mSystem->hasPlatformId(PlatformIds::ARCADE) ||
|
||||
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)
|
||||
|
|
|
@ -38,9 +38,9 @@ GuiGameScraper::GuiGameScraper(Window* window,
|
|||
else {
|
||||
if (params.game->isArcadeGame() &&
|
||||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||
scrapeName =
|
||||
Utils::FileSystem::getFileName(mSearchParams.game->getPath()) + " (" +
|
||||
MameNames::getInstance()->getCleanName(mSearchParams.game->getCleanName()) + ")";
|
||||
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath()) + " (" +
|
||||
MameNames::getInstance().getCleanName(mSearchParams.game->getCleanName()) +
|
||||
")";
|
||||
else
|
||||
scrapeName = Utils::FileSystem::getFileName(mSearchParams.game->getPath());
|
||||
}
|
||||
|
|
|
@ -397,8 +397,8 @@ void GuiGamelistOptions::openMetaDataEd()
|
|||
if (it->key == "name") {
|
||||
if (file->isArcadeGame()) {
|
||||
// If it's a MAME or Neo Geo game, expand the game name accordingly.
|
||||
file->metadata.set(
|
||||
it->key, MameNames::getInstance()->getCleanName(file->getCleanName()));
|
||||
file->metadata.set(it->key,
|
||||
MameNames::getInstance().getCleanName(file->getCleanName()));
|
||||
}
|
||||
else {
|
||||
file->metadata.set(it->key, file->getDisplayName());
|
||||
|
|
|
@ -230,7 +230,7 @@ void GuiScraperMulti::doNextSearch()
|
|||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||
scrapeName =
|
||||
Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath()) + " (" +
|
||||
MameNames::getInstance()->getCleanName(mSearchQueue.front().game->getCleanName()) +
|
||||
MameNames::getInstance().getCleanName(mSearchQueue.front().game->getCleanName()) +
|
||||
")";
|
||||
else
|
||||
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.
|
||||
if (params.game->isArcadeGame() &&
|
||||
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
||||
searchString = MameNames::getInstance()->getCleanName(params.game->getCleanName());
|
||||
searchString = MameNames::getInstance().getCleanName(params.game->getCleanName());
|
||||
else
|
||||
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
|
||||
// or directory.
|
||||
if (scrapedGame->isArcadeGame())
|
||||
defaultName = MameNames::getInstance()->getCleanName(scrapedGame->getCleanName());
|
||||
defaultName = MameNames::getInstance().getCleanName(scrapedGame->getCleanName());
|
||||
else
|
||||
defaultName = Utils::FileSystem::getStem(scrapedGame->getFileName());
|
||||
|
||||
|
|
|
@ -596,7 +596,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
AudioManager::getInstance();
|
||||
MameNames::init();
|
||||
MameNames::getInstance();
|
||||
loadSystemsReturnCode loadSystemsStatus = loadSystemConfigFile();
|
||||
|
||||
if (loadSystemsStatus) {
|
||||
|
@ -701,7 +701,6 @@ int main(int argc, char* argv[])
|
|||
delete window.peekGui();
|
||||
window.deinit();
|
||||
|
||||
MameNames::deinit();
|
||||
CollectionSystemsManager::deinit();
|
||||
SystemData::deleteSystems();
|
||||
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
|
||||
// TheGamesDB has issues with searching using the short MAME names.
|
||||
if (params.game->isArcadeGame())
|
||||
cleanName = MameNames::getInstance()->getCleanName(params.game->getCleanName());
|
||||
cleanName = MameNames::getInstance().getCleanName(params.game->getCleanName());
|
||||
else
|
||||
cleanName = params.game->getCleanName();
|
||||
}
|
||||
|
|
|
@ -14,33 +14,14 @@
|
|||
#include "Log.h"
|
||||
#include "resources/ResourceManager.h"
|
||||
#include "utils/FileSystemUtil.h"
|
||||
#include "utils/StringUtil.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
#include <string.h>
|
||||
|
||||
MameNames* MameNames::sInstance = nullptr;
|
||||
|
||||
void MameNames::init()
|
||||
MameNames& MameNames::getInstance()
|
||||
{
|
||||
if (!sInstance)
|
||||
sInstance = new MameNames();
|
||||
}
|
||||
|
||||
void MameNames::deinit()
|
||||
{
|
||||
if (sInstance) {
|
||||
delete sInstance;
|
||||
sInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
MameNames* MameNames::getInstance()
|
||||
{
|
||||
if (!sInstance)
|
||||
sInstance = new MameNames();
|
||||
|
||||
return sInstance;
|
||||
static MameNames instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
MameNames::MameNames()
|
||||
|
@ -68,9 +49,8 @@ MameNames::MameNames()
|
|||
|
||||
for (pugi::xml_node gameNode = doc.child("game"); gameNode;
|
||||
gameNode = gameNode.next_sibling("game")) {
|
||||
NamePair namePair = {gameNode.child("mamename").text().get(),
|
||||
gameNode.child("realname").text().get()};
|
||||
mNamePairs.push_back(namePair);
|
||||
mNamePairs[gameNode.child("mamename").text().get()] =
|
||||
gameNode.child("realname").text().get();
|
||||
}
|
||||
|
||||
// Read BIOS file.
|
||||
|
@ -96,7 +76,7 @@ MameNames::MameNames()
|
|||
for (pugi::xml_node biosNode = doc.child("bios"); biosNode;
|
||||
biosNode = biosNode.next_sibling("bios")) {
|
||||
std::string bios = biosNode.text().get();
|
||||
mMameBioses.push_back(bios);
|
||||
mMameBioses.emplace_back(bios);
|
||||
}
|
||||
|
||||
// Read device file.
|
||||
|
@ -122,53 +102,6 @@ MameNames::MameNames()
|
|||
for (pugi::xml_node deviceNode = doc.child("device"); deviceNode;
|
||||
deviceNode = deviceNode.next_sibling("device")) {
|
||||
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
|
||||
#define ES_CORE_MAMENAMES_H
|
||||
|
||||
#include "utils/StringUtil.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Expand MAME names to full game names.
|
||||
// Expand MAME names to full game names and lookup device and BIOS entries.
|
||||
class MameNames
|
||||
{
|
||||
public:
|
||||
static void init();
|
||||
static void deinit();
|
||||
static MameNames* getInstance();
|
||||
std::string getRealName(const std::string& _mameName);
|
||||
std::string getCleanName(const std::string& _mameName);
|
||||
const bool isBios(const std::string& _biosName)
|
||||
static MameNames& getInstance();
|
||||
|
||||
std::string getRealName(const std::string& mameName)
|
||||
{
|
||||
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:
|
||||
struct NamePair {
|
||||
std::string mameName;
|
||||
std::string realName;
|
||||
};
|
||||
|
||||
typedef std::vector<NamePair> namePairVector;
|
||||
|
||||
MameNames();
|
||||
~MameNames() {}
|
||||
|
||||
static MameNames* sInstance;
|
||||
|
||||
namePairVector mNamePairs;
|
||||
std::unordered_map<std::string, std::string> mNamePairs;
|
||||
std::vector<std::string> mMameBioses;
|
||||
std::vector<std::string> mMameDevices;
|
||||
|
||||
const bool find(const std::vector<std::string> devices, const std::string& name);
|
||||
};
|
||||
|
||||
#endif // ES_CORE_MAMENAMES_H
|
||||
|
|
|
@ -262,7 +262,6 @@ void emergencyShutdown()
|
|||
{
|
||||
LOG(LogError) << "Critical - Performing emergency shutdown...";
|
||||
|
||||
MameNames::deinit();
|
||||
// Most of the SDL deinitialization is done in Renderer.
|
||||
Renderer::deinit();
|
||||
Log::flush();
|
||||
|
|
Loading…
Reference in a new issue