mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 07:35:38 +00:00
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:
parent
2342521316
commit
7250d0b00b
|
@ -238,6 +238,7 @@ set(ES_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.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/MetaData.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include "FileData.h"
|
||||
#include "SystemData.h"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
std::string getCleanFileName(const fs::path& path)
|
||||
std::string removeParenthesis(const std::string& str)
|
||||
{
|
||||
// remove anything in parenthesis or brackets
|
||||
// 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
|
||||
|
||||
std::string ret = path.stem().generic_string();
|
||||
std::string ret = str;
|
||||
size_t start, end;
|
||||
|
||||
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)
|
||||
if(metadata.get("name").empty())
|
||||
metadata.set("name", getCleanFileName(mPath));
|
||||
metadata.set("name", getCleanName());
|
||||
}
|
||||
|
||||
FileData::~FileData()
|
||||
|
@ -52,6 +53,15 @@ FileData::~FileData()
|
|||
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
|
||||
{
|
||||
if(!metadata.get("thumbnail").empty())
|
||||
|
|
|
@ -25,7 +25,8 @@ enum FileChangeType
|
|||
const char* fileTypeToString(FileType type);
|
||||
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.
|
||||
class FileData
|
||||
|
@ -48,6 +49,8 @@ public:
|
|||
void addChild(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);
|
||||
struct SortType
|
||||
|
|
30048
src/MameNameMap.cpp
Normal file
30048
src/MameNameMap.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,8 @@
|
|||
#include "PlatformId.h"
|
||||
#include <string.h>
|
||||
|
||||
extern const char* mameNameToRealName[];
|
||||
|
||||
namespace PlatformIds
|
||||
{
|
||||
const char* PlatformNames[PLATFORM_COUNT + 1] = {
|
||||
|
@ -75,4 +77,17 @@ namespace PlatformIds
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,4 +61,6 @@ namespace PlatformIds
|
|||
|
||||
PlatformId getPlatformId(const char* str);
|
||||
const char* getPlatformName(PlatformId id);
|
||||
|
||||
const char* getCleanMameName(const char* from);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
&& ++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
|
||||
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
|
||||
&& ++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
|
||||
//delete it and ultimately do nothing
|
||||
|
|
|
@ -452,7 +452,7 @@ void ScraperSearchComponent::openInputScreen(ScraperSearchParams& params)
|
|||
stop();
|
||||
mWindow->pushGui(new GuiTextEditPopup(mWindow, "SEARCH FOR",
|
||||
// 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"));
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ std::unique_ptr<ScraperSearchHandle> GamesDBScraper::getResultsAsync(const Scrap
|
|||
|
||||
std::string cleanName = params.nameOverride;
|
||||
if(cleanName.empty())
|
||||
cleanName = getCleanFileName(params.game->getPath());
|
||||
cleanName = params.game->getCleanName();
|
||||
|
||||
path += "name=" + HttpReq::urlEncode(cleanName);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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/";
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ std::unique_ptr<ScraperSearchHandle> TheArchiveScraper::getResultsAsync(const Sc
|
|||
|
||||
std::string cleanName = params.nameOverride;
|
||||
if(cleanName.empty())
|
||||
cleanName = getCleanFileName(params.game->getPath());
|
||||
cleanName = params.game->getCleanName();
|
||||
|
||||
path += HttpReq::urlEncode(cleanName);
|
||||
//platform TODO, should use some params.system get method
|
||||
|
|
Loading…
Reference in a new issue