Bug fix: configuration was wiping out launcher variables.

This commit is contained in:
emb 2015-01-17 21:16:16 -06:00
parent 5c48661f7b
commit bed4687506
3 changed files with 29 additions and 44 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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<std::string, std::string> PropertiesType;