From b19dd4b82246759eadf8f3e7044ea6f4e7dc167a Mon Sep 17 00:00:00 2001 From: emb <> Date: Sat, 17 Jan 2015 11:55:38 -0600 Subject: [PATCH] Add support to predict the media path if not specified in Settings.conf files. uses %baseMediaPath% --- RetroFE/Source/Database/Configuration.cpp | 17 +++++++++++++++++ RetroFE/Source/Database/Configuration.h | 1 + .../Source/Graphics/Component/ScrollingList.cpp | 5 +++-- RetroFE/Source/Graphics/PageBuilder.cpp | 15 ++++++++++++--- RetroFE/Source/Utility/Utils.cpp | 11 +++++++++++ RetroFE/Source/Utility/Utils.h | 1 + 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 4ca1575..c18edb6 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -324,6 +324,23 @@ bool Configuration::GetPropertyAbsolutePath(std::string key, std::string &value) return retVal; } +void Configuration::GetMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, std::string &value) +{ + std::string key = "media." + collectionName + "." + mediaType; + + if(!GetPropertyAbsolutePath(key, value)) + { + std::string baseMediaPath; + if(!GetPropertyAbsolutePath("baseMediaPath", baseMediaPath)) + { + baseMediaPath = "Media"; + } + + value = baseMediaPath + "/" + collectionName + "/" + Utils::UppercaseFirst(Utils::ToLower(mediaType)); + } +} + + void Configuration::SetAbsolutePath(std::string absolutePath) { AbsolutePath = absolutePath; diff --git a/RetroFE/Source/Database/Configuration.h b/RetroFE/Source/Database/Configuration.h index ecad4e6..4c36d71 100644 --- a/RetroFE/Source/Database/Configuration.h +++ b/RetroFE/Source/Database/Configuration.h @@ -29,6 +29,7 @@ public: bool PropertyExists(std::string key); bool PropertyPrefixExists(std::string key); bool GetPropertyAbsolutePath(std::string key, std::string &value); + void GetMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, std::string &value); bool IsVerbose() const; void SetVerbose(bool verbose); std::string Translate(std::string str); diff --git a/RetroFE/Source/Graphics/Component/ScrollingList.cpp b/RetroFE/Source/Graphics/Component/ScrollingList.cpp index 24e27fe..10fc525 100644 --- a/RetroFE/Source/Graphics/Component/ScrollingList.cpp +++ b/RetroFE/Source/Graphics/Component/ScrollingList.cpp @@ -433,7 +433,6 @@ void ScrollingList::AllocateTexture(ComponentItemBinding *s) //todo: will create a runtime fault if not of the right type //todo: remove coupling from knowing the collection name - std::string collectionKey ="collections." + CollectionName + ".media." + ImageType; std::string videoKey ="collections." + CollectionName + ".media.video"; std::string imagePath; std::string videoPath; @@ -447,9 +446,11 @@ void ScrollingList::AllocateTexture(ComponentItemBinding *s) t = new VideoComponent(videoPath, item->GetFullTitle(), ScaleX, ScaleY); } */ - if(!t && Config.GetPropertyAbsolutePath(collectionKey, imagePath)) + if(!t) { + ImageBuilder imageBuild; + Config.GetMediaPropertyAbsolutePath(CollectionName, ImageType, imagePath); t = imageBuild.CreateImage(imagePath, item->GetName(), ScaleX, ScaleY); if(!t && item->GetTitle() != item->GetFullTitle()) diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index 815c6bf..8027210 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -401,7 +401,6 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName, type = componentXml->first_attribute("imageType"); } - if(!type && tagName == "reloadableVideo") { Logger::Write(Logger::ZONE_WARNING, "Layout", " component in layout does not specify an imageType for when the video does not exist"); @@ -411,19 +410,29 @@ void PageBuilder::LoadReloadableImages(xml_node<> *layout, std::string tagName, Logger::Write(Logger::ZONE_ERROR, "Layout", "Image component in layout does not specify a source image file"); } + Logger::Write(Logger::ZONE_INFO, "Layout", " INFO TEST!!"); if(type && (tagName == "reloadableVideo" || tagName == "reloadableImage")) { std::string configImagePath = "collections." + Collection + ".media." + type->value(); + if(!Config.GetPropertyAbsolutePath(configImagePath, reloadableImagePath)) { - Logger::Write(Logger::ZONE_ERROR, "Layout", "Cannot process reloadable images because property \"" + configImagePath + "\" does not exist"); + std::string baseMediaPath; + Config.GetPropertyAbsolutePath("baseMediaPath", baseMediaPath); + + reloadableImagePath = baseMediaPath + "/" + Collection + "/" + Utils::UppercaseFirst(Utils::ToLower(type->value())); + Logger::Write(Logger::ZONE_INFO, "Layout", "Collection config has not overridden " + configImagePath + ". Using the default path \"" + reloadableImagePath + "\" instead"); } std::string configVideoPath = "collections." + Collection + ".media.video"; if(!Config.GetPropertyAbsolutePath(configVideoPath, reloadableVideoPath)) { - Logger::Write(Logger::ZONE_WARNING, "Layout", "Could not find videos folder as \"" + configVideoPath + "\" does not exist"); + std::string baseMediaPath; + Config.GetPropertyAbsolutePath("baseMediaPath", baseMediaPath); + reloadableVideoPath = baseMediaPath + "/" + Collection + "/Video"; + Logger::Write(Logger::ZONE_INFO, "Layout", "Collection config has not overridden " + configVideoPath + ". Using the default path \"" + reloadableVideoPath + "\" instead"); + } } diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index cd59b94..36bfcd3 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -43,6 +43,17 @@ std::string Utils::ToLower(std::string str) return str; } +std::string Utils::UppercaseFirst(std::string str) +{ + if(str.length() > 0) + { + std::locale loc; + str[0] = std::tolower(str[0], loc); + } + + return str; +} + bool Utils::FindMatchingFile(std::string prefix, std::vector &extensions, std::string &file) { for(unsigned int i = 0; i < extensions.size(); ++i) diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 75e78c1..997a18c 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -20,6 +20,7 @@ public: static std::string GetFileName(std::string filePath); static bool FindMatchingFile(std::string prefix, std::vector &extensions, std::string &file); static std::string ToLower(std::string str); + static std::string UppercaseFirst(std::string str); private: Utils(); virtual ~Utils();