From b8e7d708f10b1726376d38974570ed5378fe1f11 Mon Sep 17 00:00:00 2001 From: Don Honerbrink Date: Fri, 26 Jun 2015 09:40:11 -0500 Subject: [PATCH] Support for merged collection mediapaths. --- .hgignore | 1 + RetroFE/Source/Collection/CollectionInfo.cpp | 17 ++++++++++++- RetroFE/Source/Collection/CollectionInfo.h | 3 +++ .../Collection/CollectionInfoBuilder.cpp | 14 ++++++----- .../Source/Collection/CollectionInfoBuilder.h | 2 +- RetroFE/Source/Collection/Item.cpp | 3 ++- RetroFE/Source/Collection/Item.h | 3 ++- RetroFE/Source/Collection/MenuParser.cpp | 14 ++++------- RetroFE/Source/Execute/Launcher.cpp | 2 +- .../Graphics/Component/ReloadableMedia.cpp | 13 +++++----- .../Graphics/Component/ScrollingList.cpp | 24 +++++++++++++++++-- 11 files changed, 67 insertions(+), 29 deletions(-) diff --git a/.hgignore b/.hgignore index 2e155dd..ffb94b6 100644 --- a/.hgignore +++ b/.hgignore @@ -8,4 +8,5 @@ Documentation/Artifacts/* Documentation/Manual/_build/* Configuration/Configuration/bin/** Configuration/Configuration/obj/** +Artifacts/** diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index 0897ac0..de0b0cf 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -35,8 +35,17 @@ CollectionInfo::CollectionInfo(std::string name, CollectionInfo::~CollectionInfo() { - std::vector::iterator it = items.begin(); + // remove items from the subcollections so their destructors do not + // delete the items since the parent collection will delete them. + std::vector::iterator subit; + for (subit != subcollections_.begin(); subit != subcollections_.end(); subit++) + { + CollectionInfo *info = *subit; + info->items.clear(); + } + + std::vector::iterator it = items.begin(); while(it != items.end()) { delete *it; @@ -62,6 +71,12 @@ void CollectionInfo::extensionList(std::vector &extensionlist) } } +void CollectionInfo::addSubcollection(CollectionInfo *newinfo) +{ + subcollections_.push_back(newinfo); + + items.insert(items.begin(), newinfo->items.begin(), newinfo->items.end()); +} bool CollectionInfo::itemIsLess(Item *lhs, Item *rhs) { diff --git a/RetroFE/Source/Collection/CollectionInfo.h b/RetroFE/Source/Collection/CollectionInfo.h index c3589ab..2effbc9 100644 --- a/RetroFE/Source/Collection/CollectionInfo.h +++ b/RetroFE/Source/Collection/CollectionInfo.h @@ -27,13 +27,16 @@ public: virtual ~CollectionInfo(); std::string settingsPath() const; void sortItems(); + void addSubcollection(CollectionInfo *info); void extensionList(std::vector &extensions); std::string name; std::string listpath; std::string metadataType; + std::string launcher; std::vector items; private: + std::vector subcollections_; std::string metadataPath_; std::string extensions_; static bool itemIsLess(Item *lhs, Item *rhs); diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index f6e3374..39e8d13 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -190,13 +190,15 @@ CollectionInfo *CollectionInfoBuilder::buildCollection(std::string name) CollectionInfo *collection = new CollectionInfo(name, listItemsPath, extensions, metadataType, metadataPath); + (void)conf_.getProperty("collections." + collection->name + ".launcher", collection->launcher); + ImportDirectory(collection); return collection; } -bool CollectionInfoBuilder::ImportBasicList(CollectionInfo * /*info*/, std::string file, std::string launcher, std::map &list) +bool CollectionInfoBuilder::ImportBasicList(CollectionInfo *info, std::string file, std::map &list) { std::ifstream includeStream(file.c_str()); @@ -220,7 +222,7 @@ bool CollectionInfoBuilder::ImportBasicList(CollectionInfo * /*info*/, std::stri i->fullTitle = line; i->name = line; i->title = line; - i->launcher = launcher; + i->collectionInfo = info; list[line] = i; } @@ -241,11 +243,10 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info) std::string launcher; bool showMissing = false; - (void)conf_.getProperty("collections." + info->name + ".launcher", launcher); (void)conf_.getProperty("collections." + info->name + ".list.includeMissingItems", showMissing); - ImportBasicList(info, includeFile, launcher, includeFilter); - ImportBasicList(info, excludeFile, launcher, excludeFilter); + ImportBasicList(info, includeFile, includeFilter); + ImportBasicList(info, excludeFile, excludeFilter); std::vector extensions; std::vector::iterator extensionsIt; @@ -299,7 +300,8 @@ bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info) i->name = basename; i->fullTitle = basename; i->title = basename; - i->launcher = launcher; + i->collectionInfo = info; + info->items.push_back(i); } } diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index eacbf3a..5bd5221 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -35,6 +35,6 @@ public: private: Configuration &conf_; MetadataDatabase &metaDB_; - bool ImportBasicList(CollectionInfo *info, std::string file, std::string launcher, std::map &list); + bool ImportBasicList(CollectionInfo *info, std::string file, std::map &list); bool ImportDirectory(CollectionInfo *info); }; diff --git a/RetroFE/Source/Collection/Item.cpp b/RetroFE/Source/Collection/Item.cpp index 7d63809..7f74e79 100644 --- a/RetroFE/Source/Collection/Item.cpp +++ b/RetroFE/Source/Collection/Item.cpp @@ -20,7 +20,8 @@ #include Item::Item() - : leaf(true) + : collectionInfo(NULL) + , leaf(true) { } diff --git a/RetroFE/Source/Collection/Item.h b/RetroFE/Source/Collection/Item.h index c4bd20f..1826f50 100644 --- a/RetroFE/Source/Collection/Item.h +++ b/RetroFE/Source/Collection/Item.h @@ -16,6 +16,7 @@ #pragma once #include +#include "CollectionInfo.h" class Item { @@ -26,7 +27,6 @@ public: std::string lowercaseTitle() ; std::string lowercaseFullTitle(); std::string name; - std::string launcher; std::string filepath; std::string title; std::string fullTitle; @@ -36,6 +36,7 @@ public: std::string cloneof; std::string numberPlayers; std::string numberButtons; + CollectionInfo *collectionInfo; bool leaf; }; diff --git a/RetroFE/Source/Collection/MenuParser.cpp b/RetroFE/Source/Collection/MenuParser.cpp index defee6d..b07beb3 100644 --- a/RetroFE/Source/Collection/MenuParser.cpp +++ b/RetroFE/Source/Collection/MenuParser.cpp @@ -94,23 +94,17 @@ bool MenuParser::buildMenuItems(CollectionInfo *collection, bool sort, Collectio item->fullTitle = title; item->name = collectionAttribute->value(); item->leaf = false; + item->collectionInfo = collection; + menuItems.push_back(item); } else { std::string collectionName = collectionAttribute->value(); Logger::write(Logger::ZONE_INFO, "Menu", "Loading collection into menu: " + collectionName); + CollectionInfo *subcollection = builder.buildCollection(collectionName); - - // todo, there must be a faster way of doing this - collection->items.insert(collection->items.begin(), subcollection->items.begin(), subcollection->items.end()); - - // prevent the temporary collection object from deleting the item pointers - subcollection->items.clear(); - delete subcollection; - - //todo: unsupported option with this refactor - // need to append the collection + collection->addSubcollection(subcollection); } } diff --git a/RetroFE/Source/Execute/Launcher.cpp b/RetroFE/Source/Execute/Launcher.cpp index 2720116..d708c84 100644 --- a/RetroFE/Source/Execute/Launcher.cpp +++ b/RetroFE/Source/Execute/Launcher.cpp @@ -38,7 +38,7 @@ Launcher::Launcher(RetroFE &p, Configuration &c) bool Launcher::run(std::string collection, Item *collectionItem) { - std::string launcherName = collectionItem->launcher; + std::string launcherName = collectionItem->collectionInfo->launcher; std::string executablePath; std::string selectedItemsDirectory; std::string selectedItemsPath; diff --git a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp index 8e846a8..b9f4566 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp @@ -172,11 +172,12 @@ void ReloadableMedia::reloadTexture() { config_.getMediaPropertyAbsolutePath(collectionName, "video", true, videoPath); loadedComponent_ = videoBuild.createVideo(videoPath, "video", scaleX_, scaleY_); - } - else - { - config_.getMediaPropertyAbsolutePath(collectionName, "video", false, videoPath); - loadedComponent_ = videoBuild.createVideo(videoPath, names[n], scaleX_, scaleY_); + + if(!loadedComponent_) + { + config_.getMediaPropertyAbsolutePath(selectedItem->collectionInfo->name, "video", false, videoPath); + loadedComponent_ = videoBuild.createVideo(videoPath, names[n], scaleX_, scaleY_); + } } if(!loadedComponent_ && !systemMode_) @@ -238,7 +239,7 @@ void ReloadableMedia::reloadTexture() } else { - config_.getMediaPropertyAbsolutePath(collectionName, type_, false, imagePath); + config_.getMediaPropertyAbsolutePath(selectedItem->collectionInfo->name, type_, false, imagePath); loadedComponent_ = imageBuild.CreateImage(imagePath, imageBasename, scaleX_, scaleY_); } diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 6068bb0..8f05449 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -782,19 +782,39 @@ bool ScrollingList::allocateTexture(ComponentItemBinding *s) Component *t = NULL; ImageBuilder imageBuild; + + // check collection path for art based on gamename config_.getMediaPropertyAbsolutePath(collectionName, imageType_, false, imagePath); t = imageBuild.CreateImage(imagePath, item->name, scaleX_, scaleY_); + // check sub-collection path for art based on gamename if(!t) { - config_.getMediaPropertyAbsolutePath(item->name, imageType_, true, imagePath); - t = imageBuild.CreateImage(imagePath, imageType_, scaleX_, scaleY_); + config_.getMediaPropertyAbsolutePath(item->collectionInfo->name, imageType_, false, imagePath); + t = imageBuild.CreateImage(imagePath, item->name, scaleX_, scaleY_); } + // check collection path for art based on game name (full title) if(!t && item->title != item->fullTitle) { + config_.getMediaPropertyAbsolutePath(collectionName, imageType_, false, imagePath); t = imageBuild.CreateImage(imagePath, item->fullTitle, scaleX_, scaleY_); } + + // check sub-collection path for art based on game name (full title) + if(!t && item->title != item->fullTitle) + { + config_.getMediaPropertyAbsolutePath(item->collectionInfo->name, imageType_, false, imagePath); + t = imageBuild.CreateImage(imagePath, item->fullTitle, scaleX_, scaleY_); + } + + // check collection path for art based on system name + if(!t) + { + config_.getMediaPropertyAbsolutePath(item->name, imageType_, true, imagePath); + t = imageBuild.CreateImage(imagePath, imageType_, scaleX_, scaleY_); + } + if (!t) { t = new Text(item->title, fontInst_, scaleX_, scaleY_);