Cleanup configuration class (moved variables to properties).

This commit is contained in:
Don Honerbrink 2015-06-23 11:54:19 -05:00
parent 3ea62b9c64
commit 5afefc7d47
6 changed files with 18 additions and 56 deletions

View File

@ -31,7 +31,6 @@
std::string Configuration::AbsolutePath;
Configuration::Configuration()
: Verbose(false)
{
}
@ -70,16 +69,6 @@ void Configuration::Initialize()
}
}
void Configuration::SetCurrentCollection(std::string collection)
{
CurrentCollection = collection;
}
std::string Configuration::GetCurrentCollection()
{
return CurrentCollection;
}
bool Configuration::Import(std::string keyPrefix, std::string file)
{
bool retVal = true;
@ -183,10 +172,6 @@ bool Configuration::GetRawProperty(std::string key, std::string &value)
retVal = true;
}
else if(Verbose)
{
Logger::Write(Logger::ZONE_DEBUG, "Configuration", "Missing property " + key);
}
return retVal;
}
@ -197,10 +182,10 @@ bool Configuration::GetProperty(std::string key, std::string &value)
std::string baseMediaPath = AbsolutePath;
std::string baseItemPath = AbsolutePath;
std::string collectionName;
GetProperty("currentCollection", collectionName);
GetRawProperty("baseMediaPath", baseMediaPath);
GetRawProperty("baseItemPath", baseItemPath);
collectionName = GetCurrentCollection();
value = Utils::Replace(value, "%BASE_MEDIA_PATH%", baseMediaPath);
value = Utils::Replace(value, "%BASE_ITEM_PATH%", baseItemPath);
@ -407,23 +392,3 @@ void Configuration::GetCollectionAbsolutePath(std::string collectionName, std::s
value = Utils::CombinePath(AbsolutePath, "collections", collectionName, "roms");
}
bool Configuration::IsVerbose() const
{
return Verbose;
}
void Configuration::SetVerbose(bool verbose)
{
this->Verbose = verbose;
}
void Configuration::SetStatus(std::string status)
{
Status = status;
}
std::string Configuration::GetStatus()
{
return Status;
}

View File

@ -26,12 +26,8 @@ public:
virtual ~Configuration();
static void Initialize();
static std::string ConvertToAbsolutePath(std::string prefix, std::string path);
void SetStatus(std::string status);
std::string GetStatus();
// gets the global configuration
bool Import(std::string keyPrefix, std::string file);
void SetCurrentCollection(std::string collection);
std::string GetCurrentCollection();
bool GetProperty(std::string key, std::string &value);
bool GetProperty(std::string key, int &value);
bool GetProperty(std::string key, bool &value);
@ -43,8 +39,6 @@ public:
void GetMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, std::string &value);
void GetMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, bool system, std::string &value);
void GetCollectionAbsolutePath(std::string collectionName, std::string &value);
bool IsVerbose() const;
void SetVerbose(bool verbose);
static std::string AbsolutePath;
private:
@ -53,10 +47,7 @@ private:
std::string TrimEnds(std::string str);
typedef std::map<std::string, std::string> PropertiesType;
typedef std::pair<std::string, std::string> PropertiesPair;
bool Verbose;
std::string CurrentCollection;
PropertiesType Properties;
std::string Status;
};

View File

@ -169,7 +169,7 @@ bool MetadataDatabase::ImportDirectory()
{
std::string importFile = Utils::CombinePath(mameListPath, std::string(dirp->d_name));
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing mamelist: " + importFile);
Config.SetStatus("Scraping data from " + importFile);
Config.SetProperty("status", "Scraping data from " + importFile);
ImportMameList(importFile, collectionName);
}
}
@ -305,7 +305,7 @@ bool MetadataDatabase::ImportHyperList(std::string hyperlistFile, std::string co
{
char *error = NULL;
Config.SetStatus("Scraping data from \"" + hyperlistFile + "\"");
Config.SetProperty("status", "Scraping data from \"" + hyperlistFile + "\"");
rapidxml::xml_document<> doc;
std::ifstream file(hyperlistFile.c_str());
std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
@ -366,7 +366,7 @@ bool MetadataDatabase::ImportHyperList(std::string hyperlistFile, std::string co
sqlite3_finalize(stmt);
}
}
Config.SetStatus("Saving data from \"" + hyperlistFile + "\" to database");
Config.SetProperty("status", "Saving data from \"" + hyperlistFile + "\" to database");
sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error);
return true;
@ -397,7 +397,7 @@ bool MetadataDatabase::ImportMameList(std::string filename, std::string collecti
char *error = NULL;
sqlite3 *handle = DBInstance.Handle;
Config.SetStatus("Scraping data from \"" + filename + "\" (this will take a while)");
Config.SetProperty("status", "Scraping data from \"" + filename + "\" (this will take a while)");
Logger::Write(Logger::ZONE_INFO, "Mamelist", "Importing mamelist file \"" + filename + "\" (this will take a while)");
std::ifstream file(filename.c_str());
@ -478,7 +478,7 @@ bool MetadataDatabase::ImportMameList(std::string filename, std::string collecti
}
}
Config.SetStatus("Saving data from \"" + filename + "\" to database");
Config.SetProperty("status", "Saving data from \"" + filename + "\" to database");
sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error);
return true;

View File

@ -62,7 +62,10 @@ void ReloadableMedia::Update(float dt)
{
if(NewItemSelected)
{
if(!SystemMode || (SystemMode && CurrentCollection != Config.GetCurrentCollection()))
std::string collection;
Config.GetProperty("currentCollection", collection);
if(!SystemMode || (SystemMode && CurrentCollection != collection))
{
ReloadRequested = true;
}
@ -144,7 +147,7 @@ void ReloadableMedia::ReloadTexture()
Item *selectedItem = GetSelectedItem();
CurrentCollection = Config.GetCurrentCollection();
Config.GetProperty("currentCollection", CurrentCollection);
if (selectedItem != NULL)
{

View File

@ -535,7 +535,9 @@ void Page::Update(float dt)
if(TextStatusComponent)
{
TextStatusComponent->SetText(Config.GetStatus());
std::string status;
Config.SetProperty("status", status);
TextStatusComponent->SetText(status);
}
for(unsigned int i = 0; i < NUM_LAYERS; ++i)

View File

@ -278,7 +278,7 @@ void RetroFE::Run()
Config.GetProperty("firstCollection", firstCollection);
CurrentPage->Start();
Config.SetCurrentCollection(firstCollection);
Config.SetProperty("currentCollection", firstCollection);
CollectionInfo *info = GetCollection(firstCollection);
MenuParser mp;
mp.GetMenuItems(info);
@ -307,9 +307,10 @@ void RetroFE::Run()
break;
case RETROFE_BACK_REQUEST:
LastMenuOffsets[CurrentPage->GetCollectionName()] = CurrentPage->GetScrollOffsetIndex();
CurrentPage->PopCollection();
Config.SetCurrentCollection(CurrentPage->GetCollectionName());
Config.SetProperty("currentCollection", CurrentPage->GetCollectionName());
state = RETROFE_NEW;
@ -458,7 +459,7 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
}
else
{
Config.SetCurrentCollection(NextPageItem->Name);
Config.SetProperty("currentCollection", NextPageItem->Name);
CollectionInfo *info = GetCollection(NextPageItem->Name);
MenuParser mp;