mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-02-18 04:45:39 +00:00
SystemData now stores extension lists as a vector internally.
Don't write gamelist.xml changes if IGNOREGAMELIST is true.
This commit is contained in:
parent
20c367daa7
commit
68841aa654
|
@ -18,9 +18,9 @@ std::vector<SystemData*> SystemData::sSystemVector;
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
std::string SystemData::getStartPath() { return mStartPath; }
|
std::string SystemData::getStartPath() { return mStartPath; }
|
||||||
std::string SystemData::getExtension() { return mSearchExtension; }
|
std::vector<std::string> SystemData::getExtensions() { return mSearchExtensions; }
|
||||||
|
|
||||||
SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::string& extension,
|
SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions,
|
||||||
const std::string& command, PlatformIds::PlatformId platformId)
|
const std::string& command, PlatformIds::PlatformId platformId)
|
||||||
{
|
{
|
||||||
mName = name;
|
mName = name;
|
||||||
|
@ -34,7 +34,7 @@ SystemData::SystemData(const std::string& name, const std::string& fullName, con
|
||||||
mStartPath.insert(0, getHomePath());
|
mStartPath.insert(0, getHomePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
mSearchExtension = extension;
|
mSearchExtensions = extensions;
|
||||||
mLaunchCommand = command;
|
mLaunchCommand = command;
|
||||||
mPlatformId = platformId;
|
mPlatformId = platformId;
|
||||||
|
|
||||||
|
@ -122,42 +122,31 @@ void SystemData::populateFolder(FolderData* folder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs::path filePath;
|
||||||
|
std::string extension;
|
||||||
|
bool isGame;
|
||||||
for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir)
|
for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir)
|
||||||
{
|
{
|
||||||
fs::path filePath = (*dir).path();
|
filePath = (*dir).path();
|
||||||
|
|
||||||
if(filePath.stem().string().empty())
|
if(filePath.stem().string().empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//this is a little complicated because we allow a list of extensions to be defined (delimited with a space)
|
//this is a little complicated because we allow a list of extensions to be defined (delimited with a space)
|
||||||
//we first get the extension of the file itself:
|
//we first get the extension of the file itself:
|
||||||
std::string extension = filePath.extension().string();
|
extension = filePath.extension().string();
|
||||||
std::string chkExt;
|
|
||||||
size_t extPos = 0;
|
|
||||||
|
|
||||||
//folders *can* also match the extension and be added as games - this is mostly just to support higan
|
//fyi, folders *can* also match the extension and be added as games - this is mostly just to support higan
|
||||||
//see issue #75: https://github.com/Aloshi/EmulationStation/issues/75
|
//see issue #75: https://github.com/Aloshi/EmulationStation/issues/75
|
||||||
bool isGame = false;
|
|
||||||
do {
|
|
||||||
//now we loop through every extension in the list
|
|
||||||
size_t cpos = extPos;
|
|
||||||
extPos = mSearchExtension.find(" ", extPos);
|
|
||||||
chkExt = mSearchExtension.substr(cpos, ((extPos == std::string::npos) ? mSearchExtension.length() - cpos: extPos - cpos));
|
|
||||||
|
|
||||||
//if it matches, add it
|
isGame = false;
|
||||||
if(chkExt == extension)
|
if(std::find(mSearchExtensions.begin(), mSearchExtensions.end(), extension) != mSearchExtensions.end())
|
||||||
{
|
{
|
||||||
GameData* newGame = new GameData(filePath.generic_string(), MetaDataList(getGameMDD()));
|
GameData* newGame = new GameData(filePath.generic_string(), MetaDataList(getGameMDD()));
|
||||||
folder->pushFileData(newGame);
|
folder->pushFileData(newGame);
|
||||||
isGame = true;
|
isGame = true;
|
||||||
break;
|
|
||||||
}else if(extPos != std::string::npos) //if not, add one to the "next position" marker to skip the space when reading the next extension
|
|
||||||
{
|
|
||||||
extPos++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(extPos != std::string::npos && chkExt != "" && chkExt.find(".") != std::string::npos);
|
|
||||||
|
|
||||||
//add directories that also do not match an extension as folders
|
//add directories that also do not match an extension as folders
|
||||||
if(!isGame && fs::is_directory(filePath))
|
if(!isGame && fs::is_directory(filePath))
|
||||||
{
|
{
|
||||||
|
@ -218,18 +207,30 @@ bool SystemData::loadConfig(const std::string& path, bool writeExample)
|
||||||
|
|
||||||
for(pugi::xml_node system = systemList.child("system"); system; system = system.next_sibling("system"))
|
for(pugi::xml_node system = systemList.child("system"); system; system = system.next_sibling("system"))
|
||||||
{
|
{
|
||||||
std::string name, fullname, path, ext, cmd;
|
std::string name, fullname, path, cmd;
|
||||||
PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN;
|
PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN;
|
||||||
|
|
||||||
name = system.child("name").text().get();
|
name = system.child("name").text().get();
|
||||||
fullname = system.child("fullname").text().get();
|
fullname = system.child("fullname").text().get();
|
||||||
path = system.child("path").text().get();
|
path = system.child("path").text().get();
|
||||||
ext = system.child("extension").text().get();
|
|
||||||
|
//convert extensions list from a string into a vector of strings
|
||||||
|
const pugi::char_t* extStr = system.child("extension").text().get();
|
||||||
|
std::vector<std::string> extensions;
|
||||||
|
std::vector<char> buff(strlen(extStr) + 1);
|
||||||
|
strcpy(buff.data(), extStr);
|
||||||
|
char* ext = strtok(buff.data(), " ");
|
||||||
|
while(ext != NULL)
|
||||||
|
{
|
||||||
|
extensions.push_back(ext);
|
||||||
|
ext = strtok(NULL, " ");
|
||||||
|
}
|
||||||
|
|
||||||
cmd = system.child("command").text().get();
|
cmd = system.child("command").text().get();
|
||||||
platformId = (PlatformIds::PlatformId)system.child("platformid").text().as_uint(PlatformIds::PLATFORM_UNKNOWN);
|
platformId = (PlatformIds::PlatformId)system.child("platformid").text().as_uint(PlatformIds::PLATFORM_UNKNOWN);
|
||||||
|
|
||||||
//validate
|
//validate
|
||||||
if(name.empty() || path.empty() || ext.empty() || cmd.empty())
|
if(name.empty() || path.empty() || extensions.empty() || cmd.empty())
|
||||||
{
|
{
|
||||||
LOG(LogError) << "System \"" << name << "\" is missing name, path, extension, or command!";
|
LOG(LogError) << "System \"" << name << "\" is missing name, path, extension, or command!";
|
||||||
continue;
|
continue;
|
||||||
|
@ -239,7 +240,7 @@ bool SystemData::loadConfig(const std::string& path, bool writeExample)
|
||||||
boost::filesystem::path genericPath(path);
|
boost::filesystem::path genericPath(path);
|
||||||
path = genericPath.generic_string();
|
path = genericPath.generic_string();
|
||||||
|
|
||||||
SystemData* newSys = new SystemData(name, fullname, path, ext, cmd, platformId);
|
SystemData* newSys = new SystemData(name, fullname, path, extensions, cmd, platformId);
|
||||||
if(newSys->getRootFolder()->getFileCount() == 0)
|
if(newSys->getRootFolder()->getFileCount() == 0)
|
||||||
{
|
{
|
||||||
LOG(LogWarning) << "System \"" << name << "\" has no games! Ignoring it.";
|
LOG(LogWarning) << "System \"" << name << "\" has no games! Ignoring it.";
|
||||||
|
|
|
@ -13,19 +13,22 @@ class GameData;
|
||||||
class SystemData
|
class SystemData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::string& extension,
|
SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions,
|
||||||
const std::string& command, PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN);
|
const std::string& command, PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN);
|
||||||
~SystemData();
|
~SystemData();
|
||||||
|
|
||||||
FolderData* getRootFolder();
|
FolderData* getRootFolder();
|
||||||
|
|
||||||
std::string getName();
|
std::string getName();
|
||||||
std::string getFullName();
|
std::string getFullName();
|
||||||
std::string getStartPath();
|
std::string getStartPath();
|
||||||
std::string getExtension();
|
std::vector<std::string> getExtensions();
|
||||||
std::string getGamelistPath();
|
|
||||||
PlatformIds::PlatformId getPlatformId();
|
PlatformIds::PlatformId getPlatformId();
|
||||||
|
|
||||||
|
std::string getGamelistPath();
|
||||||
bool hasGamelist();
|
bool hasGamelist();
|
||||||
std::vector<MetaDataDecl> getGameMDD();
|
std::vector<MetaDataDecl> getGameMDD();
|
||||||
|
|
||||||
unsigned int getGameCount();
|
unsigned int getGameCount();
|
||||||
|
|
||||||
void launchGame(Window* window, GameData* game);
|
void launchGame(Window* window, GameData* game);
|
||||||
|
@ -40,7 +43,7 @@ private:
|
||||||
std::string mName;
|
std::string mName;
|
||||||
std::string mFullName;
|
std::string mFullName;
|
||||||
std::string mStartPath;
|
std::string mStartPath;
|
||||||
std::string mSearchExtension;
|
std::vector<std::string> mSearchExtensions;
|
||||||
std::string mLaunchCommand;
|
std::string mLaunchCommand;
|
||||||
PlatformIds::PlatformId mPlatformId;
|
PlatformIds::PlatformId mPlatformId;
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ void updateGamelist(SystemData* system)
|
||||||
//We have the complete information for every game though, so we can simply remove a game
|
//We have the complete information for every game though, so we can simply remove a game
|
||||||
//we already have in the system from the XML, and then add it back from its GameData information...
|
//we already have in the system from the XML, and then add it back from its GameData information...
|
||||||
|
|
||||||
if(Settings::getInstance()->getBool("DisableGamelistWrites"))
|
if(Settings::getInstance()->getBool("DisableGamelistWrites") || Settings::getInstance()->getBool("IGNOREGAMELIST"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string xmlpath = system->getGamelistPath();
|
std::string xmlpath = system->getGamelistPath();
|
||||||
|
|
Loading…
Reference in a new issue