From bed4687506842faf6bb7a35e922fd7f6e13c7505 Mon Sep 17 00:00:00 2001 From: emb <> Date: Sat, 17 Jan 2015 21:16:16 -0600 Subject: [PATCH] Bug fix: configuration was wiping out launcher variables. --- .../Collection/CollectionInfoBuilder.cpp | 3 + RetroFE/Source/Database/Configuration.cpp | 68 +++++++------------ RetroFE/Source/Database/Configuration.h | 2 +- 3 files changed, 29 insertions(+), 44 deletions(-) diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 5c669a1..41138be 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -59,6 +59,8 @@ bool CollectionInfoBuilder::LoadAllCollections() // I remove this conditional check. if(*it != "Main") { + std::string oldCollection = Conf.GetCurrentCollection(); + Conf.SetCurrentCollection(*it); if(ImportCollection(*it)) { Logger::Write(Logger::ZONE_INFO, "Collections", "Adding collection " + *it); @@ -69,6 +71,7 @@ bool CollectionInfoBuilder::LoadAllCollections() // ImportCollection() will print out an error to the log file. retVal = false; } + Conf.SetCurrentCollection(oldCollection); } } diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index f970ca0..fd29b7c 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -177,7 +177,7 @@ std::string Configuration::TrimEnds(std::string str) return str; } -bool Configuration::GetProperty(std::string key, std::string &value) +bool Configuration::GetRawProperty(std::string key, std::string &value) { bool retVal = false; @@ -192,7 +192,28 @@ bool Configuration::GetProperty(std::string key, std::string &value) Logger::Write(Logger::ZONE_DEBUG, "Configuration", "Missing property " + key); } - value = Translate(value); + return retVal; +} +bool Configuration::GetProperty(std::string key, std::string &value) +{ + bool retVal = GetRawProperty(key, value); + + std::string baseMediaPath; + std::string baseItemPath; + std::string collectionName; + + GetRawProperty("baseMediaPath", baseMediaPath); + GetRawProperty("baseItemPath", baseItemPath); + collectionName = GetCurrentCollection(); + + Logger::Write(Logger::ZONE_INFO, "Configuration", "PROPERTY " + key + " BEFORE " + value); + + value = Utils::Replace(value, "%BASE_MEDIA_PATH%", baseMediaPath); + value = Utils::Replace(value, "%BASE_ITEM_PATH%", baseItemPath); + value = Utils::Replace(value, "%COLLECTION_NAME%", collectionName); + + Logger::Write(Logger::ZONE_INFO, "Configuration", "PROPERTY "+ key + " AFTER " + value); + return retVal; } @@ -342,7 +363,7 @@ void Configuration::GetMediaPropertyAbsolutePath(std::string collectionName, std void Configuration::GetCollectionAbsolutePath(std::string collectionName, std::string &value) { - std::string key = "collections" + collectionName + ".list.path"; + std::string key = "collections." + collectionName + ".list.path"; if(!GetPropertyAbsolutePath(key, value)) { @@ -375,43 +396,4 @@ bool Configuration::IsVerbose() const void Configuration::SetVerbose(bool verbose) { this->Verbose = verbose; -} - -std::string Configuration::Translate(std::string str) -{ - std::string translated; - std::size_t startIndex = 0; - - while(str.find("%") != std::string::npos) - { - std::size_t startIndex = str.find("%"); - std::string var = str.substr(startIndex + 1); - - // copy everything before the first % - translated += str.substr(0, startIndex); - - str = var; // discard the old unprocessed data up until the first % - - std::size_t endIndex = var.find("%"); - var = var.substr(0, endIndex); - str = str.substr(endIndex + 1); - - std::string result; - - if(var == "collectionName") - { - result = GetCurrentCollection(); - } - else - { - GetProperty(var, result); - } - - translated += result; - } - - //copy the remaining string - translated += str; - return translated; -} - +} \ No newline at end of file diff --git a/RetroFE/Source/Database/Configuration.h b/RetroFE/Source/Database/Configuration.h index 0a1f03d..c486259 100644 --- a/RetroFE/Source/Database/Configuration.h +++ b/RetroFE/Source/Database/Configuration.h @@ -33,9 +33,9 @@ public: void GetCollectionAbsolutePath(std::string collectionName, std::string &value); bool IsVerbose() const; void SetVerbose(bool verbose); - std::string Translate(std::string str); private: + bool GetRawProperty(std::string key, std::string &value); bool ParseLine(std::string keyPrefix, std::string line, int lineCount); std::string TrimEnds(std::string str); typedef std::map PropertiesType;