From 4429b1edf518679ebbdb59f06c48fe44d212dc51 Mon Sep 17 00:00:00 2001 From: Don Honerbrink Date: Wed, 4 Feb 2015 23:47:15 -0600 Subject: [PATCH] Adding include/exclude support after porting. Lists are also alphabetical. --- RetroFE/Source/Collection/CollectionInfo.cpp | 11 ++++++ RetroFE/Source/Collection/CollectionInfo.h | 3 ++ .../Collection/CollectionInfoBuilder.cpp | 37 ++++++++++++++++++- .../Source/Collection/CollectionInfoBuilder.h | 1 + RetroFE/Source/Collection/Item.cpp | 10 ----- RetroFE/Source/Collection/Item.h | 2 - RetroFE/Source/Database/Configuration.cpp | 36 +++++++++--------- RetroFE/Source/Utility/Utils.cpp | 2 +- 8 files changed, 69 insertions(+), 33 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index 61b5308..4e51098 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -17,6 +17,7 @@ #include "Item.h" #include "../Database/Configuration.h" #include +#include CollectionInfo::CollectionInfo(std::string name, std::string listPath, @@ -88,5 +89,15 @@ std::vector *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); +} + diff --git a/RetroFE/Source/Collection/CollectionInfo.h b/RetroFE/Source/Collection/CollectionInfo.h index 1edaf1f..ffcc479 100644 --- a/RetroFE/Source/Collection/CollectionInfo.h +++ b/RetroFE/Source/Collection/CollectionInfo.h @@ -32,9 +32,12 @@ public: std::string GetMetadataPath() const; std::string GetExtensions() const; std::vector *GetItems(); + void SortItems(); void GetExtensions(std::vector &extensions); private: + static bool ItemIsLess(Item const *lhs, Item const *rhs); + std::string Name; std::string ListPath; std::string Extensions; diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 43a4703..242bf11 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -24,6 +24,7 @@ #include #include #include +#include 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 &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 extensions; std::vector::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) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index 67ae766..d368bef 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -33,6 +33,7 @@ public: private: MetadataDatabase &MetaDB; + bool ImportBasicList(CollectionInfo *info, std::string file, std::map &list); bool ImportDirectory(CollectionInfo *info); Configuration &Conf; }; diff --git a/RetroFE/Source/Collection/Item.cpp b/RetroFE/Source/Collection/Item.cpp index 6b4e2ae..40247df 100644 --- a/RetroFE/Source/Collection/Item.cpp +++ b/RetroFE/Source/Collection/Item.cpp @@ -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; -} - diff --git a/RetroFE/Source/Collection/Item.h b/RetroFE/Source/Collection/Item.h index 5653396..80da0cf 100644 --- a/RetroFE/Source/Collection/Item.h +++ b/RetroFE/Source/Collection/Item.h @@ -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; diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 3d3a4be..c990f63 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -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; } diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index 36bfcd3..55f349f 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -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;