From 5786ecae7c78367049f4ed070e7786e197d44179 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 8 Sep 2012 13:17:36 -0500 Subject: [PATCH] Added support for lists of file extensions, delimited by a space. --- README.md | 3 ++- changelog.txt | 4 ++++ src/SystemData.cpp | 34 ++++++++++++++++++++++++++-------- src/XMLReader.cpp | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bfc0885d8..f9a51902a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ There are also a few libraries already on the RPi (located in /opt/vc/, like the Configuring =========== -When first run, an example systems configuration file will be created at $HOME/.emulationstation/es_systems.cfg. This example has some comments explaining how to write the configuration file, and an example RetroArch launch command. Keep in mind you can define more than one system! Just use all the variables again. +**~/.emulationstation/es_systems.cfg:** +When first run, an example systems configuration file will be created at $HOME/.emulationstation/es_systems.cfg. This example has some comments explaining how to write the configuration file, and an example RetroArch launch command. Keep in mind you can define more than one system! Just use all the variables again. Also, you can use multiple extensions - just separate them with a space, e.g.: ".nes .NES .bin". If an SDL Joystick is detected at startup, and $HOME/.emulationstation/es_input.cfg is nonexistant, an Input Configuration screen will appear instead of the game list. This should be pretty self-explanatory. If you want to reconfigure, just delete $HOME/.emulationstation/es_input.cfg. diff --git a/changelog.txt b/changelog.txt index 0cf1834a5..80b2949a2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +September 8 +-Added support for multiple filetypes for systems - just separate them with a space. +-Updated example systems config to include example for multiple filetypes and be a little clearer. + September 7 -Tiling is now much faster. -Added --draw-framerate and --help/-h command-line parameters. diff --git a/src/SystemData.cpp b/src/SystemData.cpp index 7dd419f26..ef2d64caf 100644 --- a/src/SystemData.cpp +++ b/src/SystemData.cpp @@ -117,11 +117,29 @@ void SystemData::populateFolder(FolderData* folder) else folder->pushFileData(newFolder); }else{ - if(filePath.extension().string() == mSearchExtension) - { - GameData* newGame = new GameData(this, filePath.string(), filePath.stem().string()); - folder->pushFileData(newGame); - } + //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: + std::string extension = filePath.extension().string(); + std::string chkExt; + size_t extPos = 0; + 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 + if(chkExt == mSearchExtension) + { + GameData* newGame = new GameData(this, filePath.string(), filePath.stem().string()); + folder->pushFileData(newGame); + 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 != ""); } } } @@ -225,13 +243,13 @@ void SystemData::writeExampleConfig() file << "# A sample system might look like this:" << std::endl; file << "#NAME=Nintendo Entertainment System" << std::endl; file << "#PATH=~/ROMs/nes/" << std::endl; - file << "#EXTENSION=.nes" << std::endl; + file << "#EXTENSION=.nes .NES" << std::endl; file << "#COMMAND=retroarch -L ~/cores/libretro-fceumm.so %ROM%" << std::endl << std::endl; file << "#NAME is just a name to identify the system." << std::endl; file << "#PATH is the path to start the recursive search for ROMs in. ~ will be expanded into the $HOME variable." << std::endl; - file << "#EXTENSION is the exact extension to search for. You MUST include the period, and it must be exact - no regex or wildcard support (sorry!)." << std::endl; - file << "#COMMAND is the shell command to execute when a game is selected. %ROM% will be replaced with the path to the ROM." << std::endl << std::endl; + file << "#EXTENSION is a list of extensions to search for, separated by spaces. You MUST include the period, and it must be exact - it's case sensitive, and no wildcards." << std::endl; + file << "#COMMAND is the shell command to execute when a game is selected. %ROM% will be replaced with the (bash special-character escaped) path to the ROM." << std::endl << std::endl; file << "#Now try your own!" << std::endl; file << "NAME=" << std::endl; diff --git a/src/XMLReader.cpp b/src/XMLReader.cpp index 48c20d113..48694d21b 100644 --- a/src/XMLReader.cpp +++ b/src/XMLReader.cpp @@ -85,7 +85,7 @@ GameData* createGameFromPath(std::string gameAbsPath, SystemData* system) //find gameName - std::string gameName = gamePath.substr(separator + 1, gamePath.find(system->getExtension(), separator) - separator - 1); + std::string gameName = gamePath.substr(separator + 1, gamePath.find(".", separator) - separator - 1); GameData* game = new GameData(system, gameAbsPath, gameName); folder->pushFileData(game);