Added a "MAME name to real name" translator.

Uses the latest version of MAME for names.
Hopefully will be replaced by emulator scripting in the future...
This commit is contained in:
Aloshi 2014-05-28 09:34:25 -05:00
parent 2342521316
commit 7250d0b00b
11 changed files with 30089 additions and 10 deletions

View file

@ -238,6 +238,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNameMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MathExp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/MathExp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MetaData.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/MetaData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp

View file

@ -1,14 +1,15 @@
#include "FileData.h" #include "FileData.h"
#include "SystemData.h"
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
std::string getCleanFileName(const fs::path& path) std::string removeParenthesis(const std::string& str)
{ {
// remove anything in parenthesis or brackets // remove anything in parenthesis or brackets
// should be roughly equivalent to the regex replace "\((.*)\)|\[(.*)\]" with "" // should be roughly equivalent to the regex replace "\((.*)\)|\[(.*)\]" with ""
// I would love to just use regex, but it's not worth pulling in another boost lib for one function that is used once // I would love to just use regex, but it's not worth pulling in another boost lib for one function that is used once
std::string ret = path.stem().generic_string(); std::string ret = str;
size_t start, end; size_t start, end;
static const int NUM_TO_REPLACE = 2; static const int NUM_TO_REPLACE = 2;
@ -40,7 +41,7 @@ FileData::FileData(FileType type, const fs::path& path, SystemData* system)
{ {
// metadata needs at least a name field (since that's what getName() will return) // metadata needs at least a name field (since that's what getName() will return)
if(metadata.get("name").empty()) if(metadata.get("name").empty())
metadata.set("name", getCleanFileName(mPath)); metadata.set("name", getCleanName());
} }
FileData::~FileData() FileData::~FileData()
@ -52,6 +53,15 @@ FileData::~FileData()
delete mChildren.back(); delete mChildren.back();
} }
std::string FileData::getCleanName() const
{
std::string stem = mPath.stem().generic_string();
if(mSystem && mSystem->getPlatformId() == PlatformIds::ARCADE || mSystem->getPlatformId() == PlatformIds::NEOGEO)
stem = PlatformIds::getCleanMameName(stem.c_str());
return removeParenthesis(stem);
}
const std::string& FileData::getThumbnailPath() const const std::string& FileData::getThumbnailPath() const
{ {
if(!metadata.get("thumbnail").empty()) if(!metadata.get("thumbnail").empty())

View file

@ -25,7 +25,8 @@ enum FileChangeType
const char* fileTypeToString(FileType type); const char* fileTypeToString(FileType type);
FileType stringToFileType(const char* str); FileType stringToFileType(const char* str);
std::string getCleanFileName(const boost::filesystem::path& path); // Remove (.*) and [.*] from str
std::string removeParenthesis(const std::string& str);
// A tree node that holds information for a file. // A tree node that holds information for a file.
class FileData class FileData
@ -48,6 +49,8 @@ public:
void addChild(FileData* file); // Error if mType != FOLDER void addChild(FileData* file); // Error if mType != FOLDER
void removeChild(FileData* file); //Error if mType != FOLDER void removeChild(FileData* file); //Error if mType != FOLDER
// Returns our best guess at the "real" name for this file (will strip parenthesis and attempt to perform MAME name translation)
std::string getCleanName() const;
typedef bool ComparisonFunction(const FileData* a, const FileData* b); typedef bool ComparisonFunction(const FileData* a, const FileData* b);
struct SortType struct SortType

30048
src/MameNameMap.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,8 @@
#include "PlatformId.h" #include "PlatformId.h"
#include <string.h> #include <string.h>
extern const char* mameNameToRealName[];
namespace PlatformIds namespace PlatformIds
{ {
const char* PlatformNames[PLATFORM_COUNT + 1] = { const char* PlatformNames[PLATFORM_COUNT + 1] = {
@ -75,4 +77,17 @@ namespace PlatformIds
{ {
return PlatformNames[id]; return PlatformNames[id];
} }
const char* getCleanMameName(const char* from)
{
const char** mameNames = mameNameToRealName;
while(*mameNames != NULL && strcmp(from, *mameNames) != 0)
mameNames += 2;
if(*mameNames)
return *(mameNames + 1);
return from;
}
} }

View file

@ -61,4 +61,6 @@ namespace PlatformIds
PlatformId getPlatformId(const char* str); PlatformId getPlatformId(const char* str);
const char* getPlatformName(PlatformId id); const char* getPlatformName(PlatformId id);
const char* getCleanMameName(const char* from);
} }

View file

@ -186,7 +186,7 @@ void addGameDataNode(pugi::xml_node& parent, const FileData* game, SystemData* s
if(newGame.children().begin() == newGame.child("name") //first element is name if(newGame.children().begin() == newGame.child("name") //first element is name
&& ++newGame.children().begin() == newGame.children().end() //theres only one element && ++newGame.children().begin() == newGame.children().end() //theres only one element
&& newGame.child("name").text().get() == getCleanFileName(game->getPath())) //the name is the default && newGame.child("name").text().get() == game->getCleanName()) //the name is the default
{ {
//if the only info is the default name, don't bother with this node //if the only info is the default name, don't bother with this node
parent.remove_child(newGame); parent.remove_child(newGame);
@ -206,7 +206,7 @@ void addFileDataNode(pugi::xml_node& parent, const FileData* file, const char* t
if(newNode.children().begin() == newNode.child("name") //first element is name if(newNode.children().begin() == newNode.child("name") //first element is name
&& ++newNode.children().begin() == newNode.children().end() //theres only one element && ++newNode.children().begin() == newNode.children().end() //theres only one element
&& newNode.child("name").text().get() == getCleanFileName(file->getPath())) //the name is the default && newNode.child("name").text().get() == file->getCleanName()) //the name is the default
{ {
//if the only info is the default name, don't bother with this node //if the only info is the default name, don't bother with this node
//delete it and ultimately do nothing //delete it and ultimately do nothing

View file

@ -452,7 +452,7 @@ void ScraperSearchComponent::openInputScreen(ScraperSearchParams& params)
stop(); stop();
mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR", mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR",
// initial value is last search if there was one, otherwise the clean path name // initial value is last search if there was one, otherwise the clean path name
params.nameOverride.empty() ? getCleanFileName(params.game->getPath()) : params.nameOverride, params.nameOverride.empty() ? params.game->getCleanName() : params.nameOverride,
searchForFunc, false, "SEARCH")); searchForFunc, false, "SEARCH"));
} }

View file

@ -64,7 +64,7 @@ std::unique_ptr<ScraperSearchHandle> GamesDBScraper::getResultsAsync(const Scrap
std::string cleanName = params.nameOverride; std::string cleanName = params.nameOverride;
if(cleanName.empty()) if(cleanName.empty())
cleanName = getCleanFileName(params.game->getPath()); cleanName = params.game->getCleanName();
path += "name=" + HttpReq::urlEncode(cleanName); path += "name=" + HttpReq::urlEncode(cleanName);

View file

@ -174,7 +174,7 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
std::string getSaveAsPath(const ScraperSearchParams& params, const std::string& suffix, const std::string& url) std::string getSaveAsPath(const ScraperSearchParams& params, const std::string& suffix, const std::string& url)
{ {
const std::string subdirectory = params.system->getName(); const std::string subdirectory = params.system->getName();
const std::string name = getCleanFileName(params.game->getPath()) + "-" + suffix; const std::string name = params.game->getPath().stem().generic_string() + "-" + suffix;
std::string path = getHomePath() + "/.emulationstation/downloaded_images/"; std::string path = getHomePath() + "/.emulationstation/downloaded_images/";

View file

@ -12,7 +12,7 @@ std::unique_ptr<ScraperSearchHandle> TheArchiveScraper::getResultsAsync(const Sc
std::string cleanName = params.nameOverride; std::string cleanName = params.nameOverride;
if(cleanName.empty()) if(cleanName.empty())
cleanName = getCleanFileName(params.game->getPath()); cleanName = params.game->getCleanName();
path += HttpReq::urlEncode(cleanName); path += HttpReq::urlEncode(cleanName);
//platform TODO, should use some params.system get method //platform TODO, should use some params.system get method