diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index eeac63e..7aa028f 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -155,6 +155,7 @@ void CollectionInfo::extensionList(std::vector &extensionlist) while(std::getline(ss, token, ',')) { + token = Utils::trimEnds(token); extensionlist.push_back(token); } } diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index bcd7cd7..2710310 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -286,7 +286,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me std::string launcher; bool showMissing = false; bool romHierarchy = false; - bool truRIP = false; + bool emuarc = false; if (mergedCollectionName != "") { @@ -300,8 +300,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me } (void)conf_.getProperty("collections." + info->name + ".list.includeMissingItems", showMissing); (void)conf_.getProperty("collections." + info->name + ".list.romHierarchy", romHierarchy); - (void)conf_.getProperty("collections." + info->name + ".list.truRIP", truRIP); - if (truRIP) + (void)conf_.getProperty("collections." + info->name + ".list.emuarc", emuarc); + if (emuarc) romHierarchy = true; // If no merged file exists, or it is empty, attempt to use the include and exclude from the subcollection @@ -342,7 +342,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me rompath = path; path = ""; } - ImportRomDirectory(rompath, info, includeFilter, excludeFilter, romHierarchy, truRIP); + ImportRomDirectory(rompath, info, includeFilter, excludeFilter, romHierarchy, emuarc); } while (path != ""); } @@ -443,7 +443,7 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) } -void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter, bool romHierarchy, bool truRIP) +void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter, bool romHierarchy, bool emuarc) { DIR *dp; @@ -470,7 +470,7 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo struct stat sb; if (romHierarchy && file != "." && file != ".." && stat( Utils::combinePath( path, file ).c_str(), &sb ) == 0 && S_ISDIR( sb.st_mode )) { - ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter, romHierarchy, truRIP ); + ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter, romHierarchy, emuarc ); } else if (file != "." && file != "..") { @@ -500,7 +500,7 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo i->collectionInfo = info; i->filepath = path + Utils::pathSeparator; - if ( truRIP ) + if ( emuarc ) { i->file = basename; i->name = Utils::getFileName( path ); @@ -508,7 +508,13 @@ void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo i->title = i->name; } - info->items.push_back(i); + // Add item if it doesn't already exist + bool found = false; + for ( std::vector::iterator it = info->items.begin(); it != info->items.end( ); it++ ) + if ( (*it)->name == basename ) + found = true; + if ( !found ) + info->items.push_back(i); } } } diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index 7287160..b3c8255 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -41,5 +41,5 @@ private: MetadataDatabase &metaDB_; bool ImportBasicList(CollectionInfo *info, std::string file, std::map &list); bool ImportDirectory(CollectionInfo *info, std::string mergedCollectionName); - void ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter, bool romHierarchy, bool truRIP); + void ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter, bool romHierarchy, bool emuarc); }; diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index 0907346..db03cc4 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -355,4 +355,18 @@ void UserInput::clearJoysticks( ) { joysticks_[i] = -1; } -} \ No newline at end of file +} + + +void UserInput::reconfigure( ) +{ + for (unsigned int i = 0; i < keyHandlers_.size(); ++i) + { + if (keyHandlers_[i].first) + { + delete keyHandlers_[i].first; + } + } + keyHandlers_.clear(); + initialize( ); +} diff --git a/RetroFE/Source/Control/UserInput.h b/RetroFE/Source/Control/UserInput.h index 3fc0e7e..067231c 100644 --- a/RetroFE/Source/Control/UserInput.h +++ b/RetroFE/Source/Control/UserInput.h @@ -62,6 +62,7 @@ public: bool keystate(KeyCode_E); bool newKeyPressed(KeyCode_E code); void clearJoysticks( ); + void reconfigure( ); private: bool MapKey(std::string keyDescription, KeyCode_E key); diff --git a/RetroFE/Source/Database/MetadataDatabase.cpp b/RetroFE/Source/Database/MetadataDatabase.cpp index bc9be4f..10b9645 100644 --- a/RetroFE/Source/Database/MetadataDatabase.cpp +++ b/RetroFE/Source/Database/MetadataDatabase.cpp @@ -121,7 +121,7 @@ bool MetadataDatabase::importDirectory() struct dirent *dirp; std::string hyperListPath = Utils::combinePath(Configuration::absolutePath, "meta", "hyperlist"); std::string mameListPath = Utils::combinePath(Configuration::absolutePath, "meta", "mamelist"); - std::string truripListPath = Utils::combinePath(Configuration::absolutePath, "meta", "trurip"); + std::string emuarcListPath = Utils::combinePath(Configuration::absolutePath, "meta", "emuarc"); dp = opendir(hyperListPath.c_str()); @@ -188,11 +188,11 @@ bool MetadataDatabase::importDirectory() closedir(dp); } - dp = opendir(truripListPath.c_str()); + dp = opendir(emuarcListPath.c_str()); if(dp == NULL) { - Logger::write(Logger::ZONE_INFO, "MetadataDatabase", "Could not read directory \"" + truripListPath + "\""); + Logger::write(Logger::ZONE_INFO, "MetadataDatabase", "Could not read directory \"" + emuarcListPath + "\""); } else { @@ -209,9 +209,9 @@ bool MetadataDatabase::importDirectory() if(extension == ".dat") { - std::string importFile = Utils::combinePath(truripListPath, std::string(dirp->d_name)); - Logger::write(Logger::ZONE_INFO, "Metadata", "Importing truriplist: " + importFile); - importTruriplist(importFile); + std::string importFile = Utils::combinePath(emuarcListPath, std::string(dirp->d_name)); + Logger::write(Logger::ZONE_INFO, "Metadata", "Importing emuarclist: " + importFile); + importEmuArclist(importFile); } } } @@ -556,13 +556,13 @@ bool MetadataDatabase::importMamelist(std::string filename, std::string collecti } -bool MetadataDatabase::importTruriplist(std::string truriplistFile) +bool MetadataDatabase::importEmuArclist(std::string emuarclistFile) { char *error = NULL; - config_.setProperty("status", "Scraping data from \"" + truriplistFile + "\""); + config_.setProperty("status", "Scraping data from \"" + emuarclistFile + "\""); rapidxml::xml_document<> doc; - std::ifstream file(truriplistFile.c_str()); + std::ifstream file(emuarclistFile.c_str()); std::vector buffer((std::istreambuf_iterator(file)), std::istreambuf_iterator()); try @@ -575,20 +575,20 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile) if(!root) { - Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList file (missing tag)"); + Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList file (missing tag)"); return false; } rapidxml::xml_node<> *header = root->first_node("header"); if (!header) { - Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList file (missing
tag)"); + Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList file (missing
tag)"); return false; } rapidxml::xml_node<> *name = header->first_node("name"); if (!name) { - Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList SuperDat file (missing in
tag)"); + Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList SuperDat file (missing in
tag)"); return false; } std::string collectionName = name->value(); @@ -604,22 +604,22 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile) for(rapidxml::xml_node<> *game = root->first_node("game"); game; game = game->next_sibling("game")) { rapidxml::xml_node<> *descriptionXml = game->first_node("description"); - rapidxml::xml_node<> *truripXml = game->first_node("EmuArc"); - if (!truripXml) + rapidxml::xml_node<> *emuarcXml = game->first_node("EmuArc"); + if (!emuarcXml) { - Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a TruripList SuperDat file (missing tag)"); + Logger::write(Logger::ZONE_ERROR, "Metadata", "Does not appear to be a EmuArcList SuperDat file (missing tag)"); return false; } - rapidxml::xml_node<> *cloneofXml = truripXml->first_node("cloneof"); - rapidxml::xml_node<> *manufacturerXml = truripXml->first_node("publisher"); - rapidxml::xml_node<> *developerXml = truripXml->first_node("developer"); - rapidxml::xml_node<> *yearXml = truripXml->first_node("year"); - rapidxml::xml_node<> *genreXml = truripXml->first_node("genre"); - rapidxml::xml_node<> *subgenreXml = truripXml->first_node("subgenre"); - rapidxml::xml_node<> *ratingXml = truripXml->first_node("ratings"); - rapidxml::xml_node<> *scoreXml = truripXml->first_node("score"); - rapidxml::xml_node<> *numberPlayersXml = truripXml->first_node("players"); - rapidxml::xml_node<> *enabledXml = truripXml->first_node("enabled"); + rapidxml::xml_node<> *cloneofXml = emuarcXml->first_node("cloneof"); + rapidxml::xml_node<> *manufacturerXml = emuarcXml->first_node("publisher"); + rapidxml::xml_node<> *developerXml = emuarcXml->first_node("developer"); + rapidxml::xml_node<> *yearXml = emuarcXml->first_node("year"); + rapidxml::xml_node<> *genreXml = emuarcXml->first_node("genre"); + rapidxml::xml_node<> *subgenreXml = emuarcXml->first_node("subgenre"); + rapidxml::xml_node<> *ratingXml = emuarcXml->first_node("ratings"); + rapidxml::xml_node<> *scoreXml = emuarcXml->first_node("score"); + rapidxml::xml_node<> *numberPlayersXml = emuarcXml->first_node("players"); + rapidxml::xml_node<> *enabledXml = emuarcXml->first_node("enabled"); std::string name = (descriptionXml) ? descriptionXml->value() : ""; std::string description = (descriptionXml) ? descriptionXml->value() : ""; std::string crc = ""; @@ -664,7 +664,7 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile) sqlite3_finalize(stmt); } } - config_.setProperty("status", "Saving data from \"" + truriplistFile + "\" to database"); + config_.setProperty("status", "Saving data from \"" + emuarclistFile + "\" to database"); sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error); return true; @@ -681,7 +681,7 @@ bool MetadataDatabase::importTruriplist(std::string truriplistFile) catch(std::exception &e) { std::string what = e.what(); - Logger::write(Logger::ZONE_ERROR, "Metadata", "Could not parse truriplist file. Reason: " + what); + Logger::write(Logger::ZONE_ERROR, "Metadata", "Could not parse EmuArclist file. Reason: " + what); } diff --git a/RetroFE/Source/Database/MetadataDatabase.h b/RetroFE/Source/Database/MetadataDatabase.h index a6dfc93..7489106 100644 --- a/RetroFE/Source/Database/MetadataDatabase.h +++ b/RetroFE/Source/Database/MetadataDatabase.h @@ -35,7 +35,7 @@ public: void injectMetadata(CollectionInfo *collection); bool importHyperlist(std::string hyperlistFile, std::string collectionName); bool importMamelist(std::string filename, std::string collectionName); - bool importTruriplist(std::string filename); + bool importEmuArclist(std::string filename); private: bool importDirectory(); diff --git a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp index 8a3c8c2..b6354e6 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp @@ -132,12 +132,11 @@ void ReloadableMedia::reloadTexture() names.push_back(selectedItem->name); names.push_back(selectedItem->fullTitle); - names.push_back("default"); - if(selectedItem->cloneof.length() > 0) { names.push_back(selectedItem->cloneof); } + names.push_back("default"); if(isVideo_) { diff --git a/RetroFE/Source/Menu/Menu.cpp b/RetroFE/Source/Menu/Menu.cpp index 16051a3..e30e006 100644 --- a/RetroFE/Source/Menu/Menu.cpp +++ b/RetroFE/Source/Menu/Menu.cpp @@ -17,11 +17,15 @@ #include "Menu.h" #include "../Collection/Item.h" +#include "../Control/UserInput.h" +#include "../Database/Configuration.h" +#include #include -Menu::Menu( Configuration &c ) - : config_( c ) +Menu::Menu( Configuration &c, UserInput &ui ) + : config_( c ), + input_( ui ) { page_ = nullptr; } @@ -30,6 +34,12 @@ Menu::Menu( Configuration &c ) void Menu::handleEntry( Item *item ) { std::cout << "Handling " + item->ctrlType + "." << std::endl; + std::string key = getKey(); + std::string ctrl = item->ctrlType; + ctrl.erase( 0, 1 ); + std::cout << "Setting " + ctrl + " = " + key << std::endl; + config_.setProperty( "controls." + ctrl, key ); + input_.reconfigure(); return; } @@ -44,3 +54,70 @@ void Menu::clearPage( ) { page_ = nullptr; } + + +std::string Menu::getKey() +{ + + SDL_Event event; + std::string return_value = ""; + + while ( return_value == "" ) + { + while ( SDL_PollEvent( &event ) ) + { + switch (event.type) + { + case SDL_KEYDOWN: + if ( return_value.empty() ) + return_value = SDL_GetKeyName( event.key.keysym.sym); + break; + case SDL_JOYBUTTONDOWN: + if ( return_value.empty() ) + return_value = "joyButton" + std::to_string( int( event.jbutton.button ) ); + break; + case SDL_JOYAXISMOTION: + if ((event.jaxis.value > 30000 || event.jaxis.value < -30000) && event.jaxis.axis <= 3) + { + if ( event.jaxis.value > 0 ) + { + if ( return_value.empty() ) + return_value = "joyAxis" + std::to_string( int( event.jaxis.axis ) ) + "+"; + } + else + { + if ( return_value.empty() ) + return_value = "joyAxis" + std::to_string( int( event.jaxis.axis ) ) + "-"; + } + } + break; + case SDL_JOYHATMOTION: + switch( event.jhat.value ) + { + case SDL_HAT_UP: + if ( return_value.empty() ) + return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Up"; + break; + case SDL_HAT_DOWN: + if ( return_value.empty() ) + return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Down"; + break; + case SDL_HAT_LEFT: + if ( return_value.empty() ) + return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Left"; + break; + case SDL_HAT_RIGHT: + if ( return_value.empty() ) + return_value = "joyHat" + std::to_string( int( event.jhat.hat ) ) + "Right"; + break; + } + break; + default: + break; + } + } + } + + return return_value; + +} diff --git a/RetroFE/Source/Menu/Menu.h b/RetroFE/Source/Menu/Menu.h index e17e76f..f9bf70a 100644 --- a/RetroFE/Source/Menu/Menu.h +++ b/RetroFE/Source/Menu/Menu.h @@ -16,7 +16,11 @@ #pragma once +#include + + class Configuration; +class UserInput; class Item; class Page; @@ -25,13 +29,15 @@ class Menu { public: - Menu( Configuration &c ); + Menu( Configuration &c, UserInput &ui ); void handleEntry( Item *item ); void setPage( Page *page ); void clearPage( ); private: + std::string getKey(); Configuration &config_; + UserInput &input_; Page *page_; }; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 8bbbf95..b726fed 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -320,7 +320,7 @@ void RetroFE::run( ) bool exitSplashMode = false; Launcher l( config_ ); - Menu m( config_ ); + Menu m( config_, input_ ); preloadTime = static_cast( SDL_GetTicks( ) ) / 1000; while ( running ) diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index 05cea5c..6984b95 100644 --- a/RetroFE/Source/Version.cpp +++ b/RetroFE/Source/Version.cpp @@ -21,7 +21,7 @@ std::string retrofe_version_major = "0"; std::string retrofe_version_minor = "8"; -std::string retrofe_version_build = "18"; +std::string retrofe_version_build = "19"; std::string Version::getString( )