Adding include/exclude support after porting. Lists are also alphabetical.

This commit is contained in:
Don Honerbrink 2015-02-04 23:47:15 -06:00
parent ccb354e8b6
commit 4429b1edf5
8 changed files with 69 additions and 33 deletions

View File

@ -17,6 +17,7 @@
#include "Item.h"
#include "../Database/Configuration.h"
#include <sstream>
#include <algorithm>
CollectionInfo::CollectionInfo(std::string name,
std::string listPath,
@ -88,5 +89,15 @@ std::vector<Item *> *CollectionInfo::GetItems()
return &Items;
}
bool CollectionInfo::ItemIsLess(Item const *lhs, Item const *rhs)
{
return lhs->GetLCTitle() < rhs->GetLCTitle();
}
void CollectionInfo::SortItems()
{
std::sort(Items.begin(), Items.end(), ItemIsLess);
}

View File

@ -32,9 +32,12 @@ public:
std::string GetMetadataPath() const;
std::string GetExtensions() const;
std::vector<Item *> *GetItems();
void SortItems();
void GetExtensions(std::vector<std::string> &extensions);
private:
static bool ItemIsLess(Item const *lhs, Item const *rhs);
std::string Name;
std::string ListPath;
std::string Extensions;

View File

@ -24,6 +24,7 @@
#include <dirent.h>
#include <sstream>
#include <vector>
#include <algorithm>
CollectionInfoBuilder::CollectionInfoBuilder(Configuration &c, MetadataDatabase &mdb)
: Conf(c)
@ -78,6 +79,33 @@ CollectionInfo *CollectionInfoBuilder::BuildCollection(std::string name)
return collection;
}
bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list)
{
std::ifstream includeStream(file.c_str());
if (!includeStream.good()) { return false; }
std::string line;
while(std::getline(includeStream, line))
{
if(list.find(line) == list.end())
{
Item *i = new Item();
line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
i->SetFullTitle(line);
list[line] = i;
}
}
return true;
}
bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
{
DIR *dp;
@ -89,6 +117,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
std::string includeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.txt";
std::string excludeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Exclude.txt";
std::string launcher;
ImportBasicList(info, includeFile, includeFilter);
ImportBasicList(info, excludeFile, excludeFilter);
std::vector<std::string> extensions;
std::vector<std::string>::iterator extensionsIt;
@ -96,6 +128,7 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
info->GetExtensions(extensions);
(void)Conf.GetProperty("collections." + info->GetName() + ".launcher", launcher);
Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Check path " + includeFile);
dp = opendir(path.c_str());
@ -138,7 +171,9 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
}
closedir(dp);
info->SortItems();
MetaDB.InjectMetadata(info);
while(includeFilter.size() > 0)

View File

@ -33,6 +33,7 @@ public:
private:
MetadataDatabase &MetaDB;
bool ImportBasicList(CollectionInfo *info, std::string file, std::map<std::string, Item *> &list);
bool ImportDirectory(CollectionInfo *info);
Configuration &Conf;
};

View File

@ -150,13 +150,3 @@ void Item::SetCloneOf(const std::string& cloneOf)
{
CloneOf = cloneOf;
}
bool Item::operator<(const Item &rhs)
{
return LCTitle < rhs.LCTitle;
}
bool Item::operator>(const Item &rhs)
{
return LCTitle > rhs.LCTitle;
}

View File

@ -46,8 +46,6 @@ public:
void SetFullTitle(const std::string& fulltitle);
const std::string& GetCloneOf() const;
void SetCloneOf(const std::string& cloneOf);
bool operator<(const Item& rhs);
bool operator>(const Item& rhs);
private:
std::string Launcher;

View File

@ -206,9 +206,9 @@ bool Configuration::GetProperty(std::string key, std::string &value)
GetRawProperty("baseItemPath", baseItemPath);
collectionName = GetCurrentCollection();
value = Utils::Replace(value, "%BASE_MEDIA_PATH%", baseMediaPath);
value = Utils::Replace(value, "%BASE_ITEM_PATH%", baseItemPath);
value = Utils::Replace(value, "%ITEM_COLLECTION_NAME%", collectionName);
value = Utils::Replace(value, "%BASE_MEDIA_PATH%", baseMediaPath);
value = Utils::Replace(value, "%BASE_ITEM_PATH%", baseItemPath);
value = Utils::Replace(value, "%ITEM_COLLECTION_NAME%", collectionName);
return retVal;
}
@ -343,32 +343,30 @@ void Configuration::GetMediaPropertyAbsolutePath(std::string collectionName, std
{
std::string key = "media." + collectionName + "." + mediaType;
if(!GetPropertyAbsolutePath(key, value))
{
std::string baseMediaPath;
if(!GetPropertyAbsolutePath("baseMediaPath", baseMediaPath))
{
baseMediaPath = "Media";
}
if(GetPropertyAbsolutePath(key, value)) { return; }
value = baseMediaPath + "/" + collectionName + "/" + Utils::UppercaseFirst(Utils::ToLower(mediaType));
std::string baseMediaPath;
if(!GetPropertyAbsolutePath("baseMediaPath", baseMediaPath))
{
baseMediaPath = "Media";
}
value = baseMediaPath + "/" + collectionName + "/" + Utils::ToLower(mediaType);
}
void Configuration::GetCollectionAbsolutePath(std::string collectionName, std::string &value)
{
std::string key = "collections." + collectionName + ".list.path";
if(!GetPropertyAbsolutePath(key, value))
{
std::string baseItemPath;
if(!GetPropertyAbsolutePath("baseItemPath", baseItemPath))
{
baseItemPath = "Assets";
}
if(GetPropertyAbsolutePath(key, value)) { return; }
value = baseItemPath + "/" + collectionName;
std::string baseItemPath;
if(!GetPropertyAbsolutePath("baseItemPath", baseItemPath))
{
baseItemPath = "Assets";
}
value = baseItemPath + "/" + collectionName;
}

View File

@ -48,7 +48,7 @@ std::string Utils::UppercaseFirst(std::string str)
if(str.length() > 0)
{
std::locale loc;
str[0] = std::tolower(str[0], loc);
str[0] = std::toupper(str[0], loc);
}
return str;