diff --git a/Source/Database/Configuration.cpp b/Source/Database/Configuration.cpp index d50c09f..08d0191 100644 --- a/Source/Database/Configuration.cpp +++ b/Source/Database/Configuration.cpp @@ -9,6 +9,13 @@ #include #include +#ifdef WIN32 +#include +#else +#include +#include +#endif + std::string Configuration::AbsolutePath; Configuration::Configuration() @@ -20,6 +27,37 @@ Configuration::~Configuration() { } +void Configuration::Initialize() +{ + const char *environment = std::getenv("RETROFE_PATH"); + std::string environmentStr; + if (environment != NULL) + { + environmentStr = environment; + Configuration::SetAbsolutePath(environment); + } + else + { +#ifdef WIN32 + HMODULE hModule = GetModuleHandle(NULL); + CHAR exe[MAX_PATH]; + GetModuleFileName(hModule, exe, MAX_PATH); + std::string sPath(exe); + sPath = Utils::GetDirectory(sPath); + sPath = Utils::GetParentDirectory(sPath); +#else + char exepath[1024]; + sprintf(exepath, "/proc/%d/exe", getpid()); + readlink(exepath, exepath, sizeof(exepath)); + std::string sPath(exepath); + sPath = Utils::GetDirectory(sPath); +#endif + + + Configuration::SetAbsolutePath(sPath); + } +} + bool Configuration::Import(std::string keyPrefix, std::string file) { bool retVal = true; diff --git a/Source/Database/Configuration.h b/Source/Database/Configuration.h index f181722..bf3929b 100644 --- a/Source/Database/Configuration.h +++ b/Source/Database/Configuration.h @@ -12,6 +12,10 @@ class Configuration public: Configuration(); virtual ~Configuration(); + static void Initialize(); + static void SetAbsolutePath(std::string absolutePath); + static std::string GetAbsolutePath(); + static std::string ConvertToAbsolutePath(std::string prefix, std::string path); // gets the global configuration bool Import(std::string keyPrefix, std::string file); @@ -24,9 +28,6 @@ public: bool PropertyExists(std::string key); bool PropertyPrefixExists(std::string key); bool GetPropertyAbsolutePath(std::string key, std::string &value); - static void SetAbsolutePath(std::string absolutePath); - static std::string GetAbsolutePath(); - static std::string ConvertToAbsolutePath(std::string prefix, std::string path); bool IsVerbose() const; void SetVerbose(bool verbose); bool IsRequiredPropertiesSet(); diff --git a/Source/Main.cpp b/Source/Main.cpp index 064e989..9d9a556 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -16,45 +16,13 @@ #include #include -#ifdef WIN32 -#include -#else -#include -#include -#endif - static bool ImportConfiguration(Configuration *c); int main(int argc, char *argv[]) { + Configuration::Initialize(); + Configuration config; - const char *environment = std::getenv("RETROFE_PATH"); - std::string environmentStr; - if (environment != NULL) - { - environmentStr = environment; - Configuration::SetAbsolutePath(environment); - } - else - { -#ifdef WIN32 - HMODULE hModule = GetModuleHandle(NULL); - CHAR exe[MAX_PATH]; - GetModuleFileName(hModule, exe, MAX_PATH); - std::string sPath(exe); - sPath = Utils::GetDirectory(sPath); - sPath = Utils::GetParentDirectory(sPath); -#else - char exepath[1024]; - sprintf(exepath, "/proc/%d/exe", getpid()); - readlink(exepath, exepath, sizeof(exepath)); - std::string sPath(exepath); - sPath = Utils::GetDirectory(sPath); -#endif - - - Configuration::SetAbsolutePath(sPath); - } // set the log file to write to std::string logFile = Configuration::GetAbsolutePath() + "/Log.txt"; @@ -71,22 +39,17 @@ int main(int argc, char *argv[]) Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux"); #endif - if(environment) - { - Logger::Write(Logger::ZONE_INFO, "RetroFE", "Environment variable set: RetroFE_PATH=" + environmentStr); - } - Logger::Write(Logger::ZONE_INFO, "RetroFE", "Absolute path: " + Configuration::GetAbsolutePath()); if(!ImportConfiguration(&config)) { return -1; } - Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration"); std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db"); std::ifstream infile(dbFile.c_str()); + DB db; if(!db.Initialize()) {