From fc9f1db66f196dd46bc91507d9ff86594b884de8 Mon Sep 17 00:00:00 2001 From: Pieter Hulshoff Date: Thu, 1 Nov 2018 21:35:37 +0100 Subject: [PATCH] Added support for menu directory as an alternative to menu.txt for adding collections to a menu structure. --- RetroFE/Source/Collection/MenuParser.cpp | 77 ++++++++++++++++++------ RetroFE/Source/Version.cpp | 2 +- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/RetroFE/Source/Collection/MenuParser.cpp b/RetroFE/Source/Collection/MenuParser.cpp index 62540b7..27a1010 100644 --- a/RetroFE/Source/Collection/MenuParser.cpp +++ b/RetroFE/Source/Collection/MenuParser.cpp @@ -26,6 +26,8 @@ #include #include #include +#include + bool VectorSort(Item *d1, Item *d2) { @@ -59,33 +61,70 @@ bool MenuParser::buildTextMenu(CollectionInfo *collection, bool sort) if (!includeStream.good()) { - Logger::write(Logger::ZONE_INFO, "Menu", "File does not exist: \"" + file + "\""); - return false; - } - Logger::write(Logger::ZONE_INFO, "Menu", "Found: \"" + file + "\""); + Logger::write(Logger::ZONE_INFO, "Menu", "File does not exist: \"" + file + "\"; trying menu directory."); - std::string line; + DIR *dp; + struct dirent *dirp; + std::string path = Utils::combinePath(Configuration::absolutePath, "collections", collection->name, "menu"); + dp = opendir(path.c_str()); - while(std::getline(includeStream, line)) - { - line = Utils::filterComments(line); - - if(!line.empty()) + while((dirp = readdir(dp)) != NULL) { - std::string title = line; - Item *item = new Item(); - item->title = title; - item->fullTitle = title; - item->name = title; - item->leaf = false; - item->collectionInfo = collection; + std::string file = dirp->d_name; - menuItems.push_back(item); + size_t position = file.find_last_of("."); + std::string basename = (std::string::npos == position)? file : file.substr(0, position); + + std::string comparator = ".txt"; + int start = file.length() - comparator.length(); + + if(start >= 0) + { + if(file.compare(start, comparator.length(), comparator) == 0) + { + std::string title = basename; + Item *item = new Item(); + item->title = title; + item->fullTitle = title; + item->name = title; + item->leaf = false; + item->collectionInfo = collection; + + menuItems.push_back(item); + } + } + } + + closedir(dp); + + } + else + { + + Logger::write(Logger::ZONE_INFO, "Menu", "Found: \"" + file + "\""); + + std::string line; + + while(std::getline(includeStream, line)) + { + line = Utils::filterComments(line); + + if(!line.empty()) + { + std::string title = line; + Item *item = new Item(); + item->title = title; + item->fullTitle = title; + item->name = title; + item->leaf = false; + item->collectionInfo = collection; + + menuItems.push_back(item); + } } } - collection->menusort = sort; collection->items.insert(collection->items.begin(), menuItems.begin(), menuItems.end()); diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index 6984b95..f008af1 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 = "19"; +std::string retrofe_version_build = "20"; std::string Version::getString( )