mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-14 18:58:52 +01:00
Moved path detection/initialization from main to configuration class.
This commit is contained in:
parent
c30bbb92d7
commit
48ac11f01a
@ -9,6 +9,13 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -16,45 +16,13 @@
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#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())
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user