Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore filenames when loading systems #761

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ All systems must be contained within the <systemList> tag.-->
You MUST include the period at the start of the extension! It's also case sensitive. -->
<extension>.smc .sfc .SMC .SFC</extension>

<!-- A list of filenames to ignore, delimited by any of the whitespace characters (", \r\n\t").
You MUST wrap each filename in double quotes (since some filenames contain spaces). Not case sensitive. -->
<ignore>"filename1.bin" "filename2.iso" "filename3.zip"</ignore>

<!-- The shell command executed when a game is selected. A few special tags are replaced if found in a command, like %ROM% (see below). -->
<command>snesemulator %ROM%</command>
<!-- This example would run the bash command "snesemulator /home/user/roms/snes/Super\ Mario\ World.sfc". -->
Expand Down
2 changes: 2 additions & 0 deletions es-app/src/CollectionSystemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ CollectionSystemManager::CollectionSystemManager(Window* window) : mWindow(windo
mCollectionEnvData->mStartPath = "";
std::vector<std::string> exts;
mCollectionEnvData->mSearchExtensions = exts;
std::vector<std::string> ignores;
mCollectionEnvData->mFilesToIgnore = ignores;
mCollectionEnvData->mLaunchCommand = "";
std::vector<PlatformIds::PlatformId> allPlatformIds;
allPlatformIds.push_back(PlatformIds::PLATFORM_IGNORE);
Expand Down
33 changes: 32 additions & 1 deletion es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ void SystemData::populateFolder(FileData* folder)
// skip hidden files and folders
if(!showHidden && Utils::FileSystem::isHidden(filePath))
continue;


// skip ignored files and folders
std::string fileName = Utils::String::toLower(Utils::FileSystem::getFileName(filePath));
if(std::find(mEnvData->mFilesToIgnore.cbegin(), mEnvData->mFilesToIgnore.cend(), fileName) != mEnvData->mFilesToIgnore.cend())
continue;

//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:
extension = Utils::String::toLower(Utils::FileSystem::getExtension(filePath));
Expand Down Expand Up @@ -189,6 +194,27 @@ SystemData* SystemData::loadSystem(pugi::xml_node system)
extensions.push_back(xt);
}

list.clear();

list = readList(system.child("ignore").text().get());
std::vector<std::string> ignores;

for (auto ignore = list.cbegin(); ignore != list.cend(); ignore++)
{
std::string ig = Utils::String::toLower(*ignore);



ig = Utils::String::replace(ig, "\"", "");



if (std::find(ignores.begin(), ignores.end(), ig) == ignores.end())
ignores.push_back(ig);
}

list.clear();

cmd = system.child("command").text().get();

// platform id list
Expand Down Expand Up @@ -239,6 +265,7 @@ SystemData* SystemData::loadSystem(pugi::xml_node system)
SystemEnvironmentData* envData = new SystemEnvironmentData;
envData->mStartPath = path;
envData->mSearchExtensions = extensions;
envData->mFilesToIgnore = ignores;
envData->mLaunchCommand = cmd;
envData->mPlatformIds = platformIds;

Expand Down Expand Up @@ -409,6 +436,10 @@ void SystemData::writeExampleConfig(const std::string& path)
" You MUST include the period at the start of the extension! It's also case sensitive. -->\n"
" <extension>.nes .NES</extension>\n"
"\n"
" <!-- A list of filenames to ignore, delimited by any of the whitespace characters (\", \\r\\n\\t\").\n"
" You MUST wrap each filename in double quotes (since some filenames contain spaces). Not case sensitive. -->\n"
" <ignore>\"filename1.bin\" \"filename2.iso\" \"filename3.zip\"</ignore>\n"
"\n"
" <!-- The shell command executed when a game is selected. A few special tags are replaced if found in a command:\n"
" %ROM% is replaced by a bash-special-character-escaped absolute path to the ROM.\n"
" %BASENAME% is replaced by the \"base\" name of the ROM. For example, \"/foo/bar.rom\" would have a basename of \"bar\". Useful for MAME.\n"
Expand Down
2 changes: 2 additions & 0 deletions es-app/src/SystemData.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct SystemEnvironmentData
{
std::string mStartPath;
std::vector<std::string> mSearchExtensions;
std::vector<std::string> mFilesToIgnore;
std::string mLaunchCommand;
std::vector<PlatformIds::PlatformId> mPlatformIds;
};
Expand All @@ -35,6 +36,7 @@ class SystemData
inline const std::string& getFullName() const { return mFullName; }
inline const std::string& getStartPath() const { return mEnvData->mStartPath; }
inline const std::vector<std::string>& getExtensions() const { return mEnvData->mSearchExtensions; }
inline const std::vector<std::string>& getFilesToIgnore() const { return mEnvData->mFilesToIgnore; }
inline const std::string& getThemeFolder() const { return mThemeFolder; }
inline SystemEnvironmentData* getSystemEnvData() const { return mEnvData; }
inline const std::vector<PlatformIds::PlatformId>& getPlatformIds() const { return mEnvData->mPlatformIds; }
Expand Down