mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15: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/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
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -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
30048
src/MameNameMap.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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/";
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue