diff --git a/Package/Environment/Common/settings.conf b/Package/Environment/Common/settings.conf index c4e30a9..ff39ac2 100644 --- a/Package/Environment/Common/settings.conf +++ b/Package/Environment/Common/settings.conf @@ -45,7 +45,7 @@ exitOnFirstPageBack = yes attractModeTime = 45 # remember the last highlighted menu when re-entering a menu -rememberMenu = no +rememberMenu = yes ####################################### # Base folders of media and ROM files diff --git a/README.md b/README.md index fd324dc..6e7ffec 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Compile RetroFE and create a full environment (ensure --os=mac !): python Scripts/Package.py --os=mac --build=full Copy your live RetroFE system to any folder of your choosing: - cp -r Artifacts/linux/RetroFE /your/ideal/retrofe/path + cp -r Artifacts/mac/RetroFE /your/ideal/retrofe/path # Compiling and installing on Ubuntu Linux (10.04 or newer) # diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 1a0e368..ee5a97c 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -69,9 +69,9 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name) std::cout << "Creating folder \"" << *it << "\"" << std::endl; #if defined(_WIN32) && !defined(__GNUC__) - if(!CreateDirectory(it->c_str(), NULL)) + if (!CreateDirectory(it->c_str(), NULL)) { - if(ERROR_ALREADY_EXISTS != GetLastError()) + if (ERROR_ALREADY_EXISTS != GetLastError()) { std::cout << "Could not create folder \"" << *it << "\"" << std::endl; return false; @@ -79,9 +79,9 @@ bool CollectionInfoBuilder::createCollectionDirectory(std::string name) } #else #if defined(__MINGW32__) - if(mkdir(it->c_str()) == -1) + if (mkdir(it->c_str()) == -1) #else - if(mkdir(it->c_str(), 0755) == -1) + if (mkdir(it->c_str(), 0755) == -1) #endif { std::cout << "Could not create folder \"" << *it << "\":" << errno << std::endl; @@ -171,7 +171,7 @@ CollectionInfo *CollectionInfoBuilder::buildCollection(std::string name, std::st (void)conf_.getProperty(metadataTypeKey, metadataType); (void)conf_.getProperty(metadataPathKey, metadataPath); - if(!conf_.getProperty(launcherKey, launcherName)) + if (!conf_.getProperty(launcherKey, launcherName)) { std::stringstream ss; ss << "\"" @@ -209,7 +209,7 @@ bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string fi { line = Utils::filterComments(line); - if(!line.empty() && list.find(line) == list.end()) + if (!line.empty() && list.find(line) == list.end()) { Item *i = new Item(); @@ -227,11 +227,57 @@ bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string fi return true; } +bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string file, std::vector &list) +{ + std::ifstream includeStream(file.c_str()); + + if (!includeStream.good()) + { + return false; + } + + std::string line; + + while(std::getline(includeStream, line)) + { + line = Utils::filterComments(line); + + if (!line.empty()) + { + + bool found = false; + for (std::vector::iterator it = list.begin(); it != list.end(); ++it) + { + if (line == (*it)->name) + { + found = true; + } + } + + if (!found) + { + Item *i = new Item(); + + line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() ); + + i->fullTitle = line; + i->name = line; + i->title = line; + i->collectionInfo = info; + + list.push_back(i); + } + + } + } + + return true; +} + bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string mergedCollectionName) { - DIR *dp; - struct dirent *dirp; std::string path = info->listpath; + std::vector includeFilterUnsorted; std::map includeFilter; std::map excludeFilter; std::string includeFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "include.txt"); @@ -240,12 +286,13 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me std::string launcher; bool showMissing = false; - if(mergedCollectionName != "") + if (mergedCollectionName != "") { std::string mergedFile = Utils::combinePath(Configuration::absolutePath, "collections", mergedCollectionName, info->name + ".sub"); Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + mergedFile + "\""); (void)conf_.getProperty("collections." + mergedCollectionName + ".list.includeMissingItems", showMissing); + ImportBasicList(info, mergedFile, includeFilterUnsorted); ImportBasicList(info, mergedFile, includeFilter); } @@ -253,82 +300,36 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info, std::string me // If no merged file exists, or it is empty, attempt to use the include and exclude from the subcollection // If this not a merged collection, the size will be 0 anyways and the code below will still execute - if(includeFilter.size() == 0) + if (includeFilter.size() == 0) { Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Checking for \"" + includeFile + "\""); + ImportBasicList(info, includeFile, includeFilterUnsorted); ImportBasicList(info, includeFile, includeFilter); ImportBasicList(info, excludeFile, excludeFilter); } - std::vector extensions; - std::vector::iterator extensionsIt; - - info->extensionList(extensions); - - dp = opendir(path.c_str()); - - Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Scanning directory \"" + path + "\""); - if(dp == NULL) + if (showMissing) { - Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu."); - } - - if(showMissing) - { - for(std::map::iterator it = includeFilter.begin(); it != includeFilter.end(); it++) + for(std::vector::iterator it = includeFilterUnsorted.begin(); it != includeFilterUnsorted.end(); ++it) { - if(excludeFilter.find(it->first) == excludeFilter.end()) + if (excludeFilter.find((*it)->name) == excludeFilter.end()) { - info->items.push_back(it->second); + info->items.push_back(*it); } } } - while(dp != NULL && (dirp = readdir(dp)) != NULL) + // Read ROM directory if showMissing is false + if (!showMissing || includeFilter.size() == 0) { - std::string file = dirp->d_name; - - size_t position = file.find_last_of("."); - std::string basename = (std::string::npos == position)? file : file.substr(0, position); - - // if there is an include list, only include roms that are found and are in the include list - // if there is an exclude list, exclude those roms - if((includeFilter.size() == 0 || (!showMissing && includeFilter.find(basename) != includeFilter.end())) && - (excludeFilter.size() == 0 || excludeFilter.find(basename) == excludeFilter.end())) - { - // iterate through all known file extensions - for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt) - { - std::string comparator = "." + *extensionsIt; - int start = file.length() - comparator.length() + 1; - - if(start >= 0) - { - if(file.compare(start, comparator.length(), *extensionsIt) == 0) - { - Item *i = new Item(); - i->name = basename; - i->fullTitle = basename; - i->title = basename; - i->collectionInfo = info; - - info->items.push_back(i); - } - } - } - } - } - - if(dp != NULL) - { - closedir(dp); + ImportRomDirectory(path, info, includeFilter, excludeFilter); } while(includeFilter.size() > 0) { std::map::iterator it = includeFilter.begin(); // delete the unused items if they were never pushed to the main collection - if(!showMissing) + if (!showMissing) { delete it->second; } @@ -372,7 +373,7 @@ void CollectionInfoBuilder::addFavorites(CollectionInfo *info) for(std::vector::iterator it = info->items.begin(); it != info->items.end(); it++) { - if( (*it)->name == itemName && (*it)->collectionInfo->name == collectionName) + if ( (*it)->name == itemName && (*it)->collectionInfo->name == collectionName) { info->playlists["favorites"]->push_back((*it)); } @@ -383,6 +384,78 @@ void CollectionInfoBuilder::addFavorites(CollectionInfo *info) } +void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter) +{ + + DIR *dp; + struct dirent *dirp; + std::vector extensions; + std::vector::iterator extensionsIt; + + info->extensionList(extensions); + + dp = opendir(path.c_str()); + + Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Scanning directory \"" + path + "\""); + if (dp == NULL) + { + Logger::write(Logger::ZONE_INFO, "CollectionInfoBuilder", "Could not read directory \"" + path + "\". Ignore if this is a menu."); + } + + while(dp != NULL && (dirp = readdir(dp)) != NULL) + { + std::string file = dirp->d_name; + + // Check if the file is a directory or a file + struct stat sb; + if (file != "." && file != ".." && stat( Utils::combinePath( path, file ).c_str(), &sb ) == 0 && S_ISDIR( sb.st_mode )) + { + ImportRomDirectory( Utils::combinePath( path, file ), info, includeFilter, excludeFilter ); + } + else if (file != "." && file != "..") + { + size_t position = file.find_last_of("."); + std::string basename = (std::string::npos == position)? file : file.substr(0, position); + + // if there is an include list, only include roms that are found and are in the include list + // if there is an exclude list, exclude those roms + if ((includeFilter.size() == 0 || (includeFilter.find(basename) != includeFilter.end())) && + (excludeFilter.size() == 0 || excludeFilter.find(basename) == excludeFilter.end())) + { + // iterate through all known file extensions + for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt) + { + std::string comparator = "." + *extensionsIt; + int start = file.length() - comparator.length() + 1; + + if (start >= 0) + { + if (file.compare(start, comparator.length(), *extensionsIt) == 0) + { + Item *i = new Item(); + + i->name = basename; + i->fullTitle = basename; + i->title = basename; + i->collectionInfo = info; + i->filepath = path + Utils::pathSeparator; + + info->items.push_back(i); + } + } + } + } + } + } + + if (dp != NULL) + { + closedir(dp); + } + + return; + +} void CollectionInfoBuilder::injectMetadata(CollectionInfo *info) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index cad87f5..070a1a1 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -39,5 +39,7 @@ private: Configuration &conf_; MetadataDatabase &metaDB_; bool ImportBasicList(CollectionInfo *info, std::string file, std::map &list); + bool ImportBasicList(CollectionInfo *info, std::string file, std::vector &list); bool ImportDirectory(CollectionInfo *info, std::string mergedCollectionName); + void ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter); }; diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 68e3de0..726cbd7 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -45,19 +45,19 @@ Configuration::~Configuration() void Configuration::initialize() { const char *environment = std::getenv("RETROFE_PATH"); - std::string environmentStr; std::string home_load = std::getenv("HOME") + std::string("/.retrofe"); std::ifstream retrofe_path(home_load.c_str()); + // Check Environment for path if (environment != NULL) { - environmentStr = environment; absolutePath = environment; } - else if (retrofe_path.is_open()) + // Or check for home based flat file works on linux/mac + else if (retrofe_path && std::getline( retrofe_path, absolutePath )) { - std::getline( retrofe_path, absolutePath ); retrofe_path.close(); } + // Or check executable for path else { #ifdef WIN32 diff --git a/RetroFE/Source/Execute/Launcher.cpp b/RetroFE/Source/Execute/Launcher.cpp index c4c62fa..9999c52 100644 --- a/RetroFE/Source/Execute/Launcher.cpp +++ b/RetroFE/Source/Execute/Launcher.cpp @@ -67,6 +67,13 @@ bool Launcher::run(std::string collection, Item *collectionItem) return false; } + + // Overwrite selectedItemsDirectory if already set in the file + if (collectionItem->filepath != "") + { + selectedItemsDirectory = collectionItem->filepath; + } + // It is ok to continue if the file could not be found. We could be launching a merged romset findFile(selectedItemsPath, matchedExtension, selectedItemsDirectory, collectionItem->name, extensionstr); @@ -119,7 +126,7 @@ std::string Launcher::replaceVariables(std::string str, str = Utils::replace(str, "%ITEM_COLLECTION_NAME%", itemCollectionName); str = Utils::replace(str, "%RETROFE_PATH%", Configuration::absolutePath); #ifdef WIN32 - str = Utils::replace(str, "%RETROFE_EXEC_PATH%", Utils::combinePath(Configuration::absolutePath, "RetroFE.exe")); + str = Utils::replace(str, "%RETROFE_EXEC_PATH%", Utils::combinePath(Configuration::absolutePath, "core", "RetroFE.exe")); #else str = Utils::replace(str, "%RETROFE_EXEC_PATH%", Utils::combinePath(Configuration::absolutePath, "RetroFE")); #endif diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 0bd7cfd..a74df24 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -485,7 +485,7 @@ void ScrollingList::update(float dt) Component *c = components_.at(cindex); - if(c && (scrollRequested || scrollChanged)) + if(c && readyToScroll && (scrollRequested || scrollChanged)) { unsigned int nextI = 0; if(currentScrollDirection_ == ScrollDirectionBack) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index d0ea5eb..3176489 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -145,6 +145,18 @@ void Page::onNewItemSelected() } +void Page::highlightLoadArt() +{ + selectedItem_ = activeMenu_->getSelectedItem(); + + for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) + { + (*it)->setNewItemSelected(); + } + +} + + void Page::pushMenu(ScrollingList *s) { menus_.push_back(s); diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 8d0a949..ece1082 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -44,6 +44,7 @@ public: virtual ~Page(); void DeInitialize(); virtual void onNewItemSelected(); + void highlightLoadArt(); bool pushCollection(CollectionInfo *collection); bool popCollection(); void enterMenu(); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index a946152..5747a13 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -378,36 +378,35 @@ void RetroFE::run() } break; - case RETROFE_HIGHLIGHT_REQUEST: - currentPage_->highlightExit(); + case RETROFE_HIGHLIGHT_MENU_IDLE: currentPage_->setScrolling(Page::ScrollDirectionIdle); + if (currentPage_->isIdle()) + { + state = RETROFE_HIGHLIGHT_REQUEST; + } + break; + + case RETROFE_HIGHLIGHT_REQUEST: + currentPage_->setScrolling(Page::ScrollDirectionIdle); + currentPage_->highlightExit(); state = RETROFE_HIGHLIGHT_EXIT; break; case RETROFE_HIGHLIGHT_EXIT: if (processUserInput(currentPage_) == RETROFE_HIGHLIGHT_REQUEST) { - state = RETROFE_HIGHLIGHT_REQUEST; + state = RETROFE_HIGHLIGHT_MENU_IDLE; } - else if ((currentPage_->isGraphicsIdle() && currentPage_->isMenuScrolling()) || - (currentPage_->isIdle())) + else if (currentPage_->isIdle()) { - currentPage_->onNewItemSelected(); + currentPage_->highlightLoadArt(); state = RETROFE_HIGHLIGHT_LOAD_ART; } break; case RETROFE_HIGHLIGHT_LOAD_ART: - if (processUserInput(currentPage_) == RETROFE_HIGHLIGHT_REQUEST) - { - state = RETROFE_HIGHLIGHT_REQUEST; - } - else if ((currentPage_->isGraphicsIdle() && currentPage_->isMenuScrolling()) || - (currentPage_->isIdle())) - { - currentPage_->highlightEnter(); - state = RETROFE_HIGHLIGHT_ENTER; - } + currentPage_->highlightEnter(); + state = RETROFE_HIGHLIGHT_ENTER; break; case RETROFE_HIGHLIGHT_ENTER: @@ -415,7 +414,7 @@ void RetroFE::run() { state = RETROFE_HIGHLIGHT_REQUEST; } - else if (currentPage_->isGraphicsIdle()) + else if (currentPage_->isIdle()) { state = RETROFE_IDLE; } @@ -860,10 +859,14 @@ CollectionInfo *RetroFE::getCollection(std::string collectionName) } } - collection->sortItems(); - bool menuSort = true; config_.getProperty("collections." + collectionName + ".list.menuSort", menuSort); + + if (menuSort) + { + collection->sortItems(); + } + MenuParser mp; mp.buildMenuItems(collection, menuSort); diff --git a/RetroFE/Source/RetroFE.h b/RetroFE/Source/RetroFE.h index 620f073..69db468 100644 --- a/RetroFE/Source/RetroFE.h +++ b/RetroFE/Source/RetroFE.h @@ -63,6 +63,7 @@ private: RETROFE_HIGHLIGHT_EXIT, RETROFE_HIGHLIGHT_LOAD_ART, RETROFE_HIGHLIGHT_ENTER, + RETROFE_HIGHLIGHT_MENU_IDLE, RETROFE_NEXT_PAGE_REQUEST, RETROFE_NEXT_PAGE_MENU_EXIT, RETROFE_NEXT_PAGE_MENU_LOAD_ART,