Added support for menu directory as an alternative to menu.txt for adding collections to a menu structure.

This commit is contained in:
Pieter Hulshoff 2018-11-01 21:35:37 +01:00
parent 51da8ad436
commit fc9f1db66f
2 changed files with 59 additions and 20 deletions

View File

@ -26,6 +26,8 @@
#include <rapidxml.hpp>
#include <fstream>
#include <sstream>
#include <dirent.h>
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());

View File

@ -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( )