mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-16 11:48:53 +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 <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string Configuration::AbsolutePath;
|
std::string Configuration::AbsolutePath;
|
||||||
|
|
||||||
Configuration::Configuration()
|
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 Configuration::Import(std::string keyPrefix, std::string file)
|
||||||
{
|
{
|
||||||
bool retVal = true;
|
bool retVal = true;
|
||||||
|
|||||||
@ -12,6 +12,10 @@ class Configuration
|
|||||||
public:
|
public:
|
||||||
Configuration();
|
Configuration();
|
||||||
virtual ~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
|
// gets the global configuration
|
||||||
bool Import(std::string keyPrefix, std::string file);
|
bool Import(std::string keyPrefix, std::string file);
|
||||||
@ -24,9 +28,6 @@ public:
|
|||||||
bool PropertyExists(std::string key);
|
bool PropertyExists(std::string key);
|
||||||
bool PropertyPrefixExists(std::string key);
|
bool PropertyPrefixExists(std::string key);
|
||||||
bool GetPropertyAbsolutePath(std::string key, std::string &value);
|
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;
|
bool IsVerbose() const;
|
||||||
void SetVerbose(bool verbose);
|
void SetVerbose(bool verbose);
|
||||||
bool IsRequiredPropertiesSet();
|
bool IsRequiredPropertiesSet();
|
||||||
|
|||||||
@ -16,45 +16,13 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool ImportConfiguration(Configuration *c);
|
static bool ImportConfiguration(Configuration *c);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
Configuration::Initialize();
|
||||||
|
|
||||||
Configuration config;
|
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
|
// set the log file to write to
|
||||||
std::string logFile = Configuration::GetAbsolutePath() + "/Log.txt";
|
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");
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux");
|
||||||
#endif
|
#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());
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Absolute path: " + Configuration::GetAbsolutePath());
|
||||||
|
|
||||||
if(!ImportConfiguration(&config))
|
if(!ImportConfiguration(&config))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
||||||
|
|
||||||
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
||||||
std::ifstream infile(dbFile.c_str());
|
std::ifstream infile(dbFile.c_str());
|
||||||
|
|
||||||
DB db;
|
DB db;
|
||||||
if(!db.Initialize())
|
if(!db.Initialize())
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user