mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-03-31 01:03:17 +02:00
Cleaned up Main initialization handling. This will need to be refactored into a builder class.
This commit is contained in:
@@ -58,14 +58,11 @@ bool CollectionDatabase::ResetDatabase()
|
|||||||
retVal = false;
|
retVal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//CheckDatabase();
|
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CollectionDatabase::CheckDatabase()
|
bool CollectionDatabase::Initialize()
|
||||||
{
|
{
|
||||||
bool retVal = true;
|
|
||||||
int rc;
|
int rc;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
sqlite3 *handle = DBInstance->GetHandle();
|
sqlite3 *handle = DBInstance->GetHandle();
|
||||||
@@ -101,10 +98,10 @@ bool CollectionDatabase::CheckDatabase()
|
|||||||
ss << "Unable to create Configurations table. Error: " << error;
|
ss << "Unable to create Configurations table. Error: " << error;
|
||||||
Logger::Write(Logger::ZONE_ERROR, "Database", ss.str());
|
Logger::Write(Logger::ZONE_ERROR, "Database", ss.str());
|
||||||
|
|
||||||
retVal = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ class CollectionDatabase
|
|||||||
public:
|
public:
|
||||||
CollectionDatabase(DB *db, Configuration *c);
|
CollectionDatabase(DB *db, Configuration *c);
|
||||||
virtual ~CollectionDatabase();
|
virtual ~CollectionDatabase();
|
||||||
|
bool Initialize();
|
||||||
bool Import();
|
bool Import();
|
||||||
bool ResetDatabase();
|
bool ResetDatabase();
|
||||||
bool CheckDatabase();
|
|
||||||
|
|
||||||
|
|
||||||
bool GetCollection(std::string collectionName, std::vector<Item *> &list);
|
bool GetCollection(std::string collectionName, std::vector<Item *> &list);
|
||||||
|
|||||||
@@ -2,14 +2,13 @@
|
|||||||
* file 'LICENSE.txt', which is part of this source code package.
|
* file 'LICENSE.txt', which is part of this source code package.
|
||||||
*/
|
*/
|
||||||
#include "DB.h"
|
#include "DB.h"
|
||||||
#include "Configuration.h"
|
|
||||||
#include "../Utility/Log.h"
|
#include "../Utility/Log.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
DB::DB()
|
DB::DB(std::string dbFile)
|
||||||
: Path(Configuration::GetAbsolutePath() + "/cache.db")
|
: Path(dbFile)
|
||||||
, Handle(NULL)
|
, Handle(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
class DB
|
class DB
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DB();
|
DB(std::string dbFile);
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
void DeInitialize();
|
void DeInitialize();
|
||||||
virtual ~DB();
|
virtual ~DB();
|
||||||
|
|||||||
101
Source/Main.cpp
101
Source/Main.cpp
@@ -17,6 +17,8 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
static bool ImportConfiguration(Configuration *c);
|
static bool ImportConfiguration(Configuration *c);
|
||||||
|
static bool StartLogging();
|
||||||
|
CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -24,55 +26,39 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Configuration config;
|
Configuration config;
|
||||||
|
|
||||||
// set the log file to write to
|
if(!StartLogging()) {
|
||||||
std::string logFile = Configuration::GetAbsolutePath() + "/Log.txt";
|
return -1;
|
||||||
|
|
||||||
if(!Logger::Initialize(logFile))
|
|
||||||
{
|
|
||||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not open \"" + logFile + "\" for writing");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Version " + Version::GetString() + " starting");
|
|
||||||
#ifdef WIN32
|
|
||||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Windows");
|
|
||||||
#else
|
|
||||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
DB db(Configuration::GetAbsolutePath() + "/cache.db");
|
||||||
std::ifstream infile(dbFile.c_str());
|
|
||||||
|
|
||||||
DB db;
|
|
||||||
if(!db.Initialize())
|
if(!db.Initialize())
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CollectionDatabase cdb(&db, &config);
|
CollectionDatabase *cdb = InitializeCollectionDatabase(db, config);
|
||||||
|
if(!cdb) {
|
||||||
cdb.CheckDatabase();
|
return -1;
|
||||||
|
|
||||||
if(cdb.Import())
|
|
||||||
{
|
|
||||||
RetroFE p(&cdb, &config);
|
|
||||||
|
|
||||||
if(p.Initialize())
|
|
||||||
{
|
|
||||||
p.Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
p.DeInitialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RetroFE p(cdb, &config);
|
||||||
|
|
||||||
|
if(p.Initialize())
|
||||||
|
{
|
||||||
|
p.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
p.DeInitialize();
|
||||||
|
|
||||||
Logger::DeInitialize();
|
Logger::DeInitialize();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +76,6 @@ bool ImportConfiguration(Configuration *c)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!c->Import("controls", configPath + "/Controls.conf"))
|
if(!c->Import("controls", configPath + "/Controls.conf"))
|
||||||
{
|
{
|
||||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
||||||
@@ -157,5 +141,52 @@ bool ImportConfiguration(Configuration *c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StartLogging()
|
||||||
|
{
|
||||||
|
std::string logFile = Configuration::GetAbsolutePath() + "/Log.txt";
|
||||||
|
|
||||||
|
if(!Logger::Initialize(logFile))
|
||||||
|
{
|
||||||
|
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not open \"" + logFile + "\" for writing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Version " + Version::GetString() + " starting");
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Windows");
|
||||||
|
#else
|
||||||
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Absolute path: " + Configuration::GetAbsolutePath());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config)
|
||||||
|
{
|
||||||
|
CollectionDatabase *cdb = NULL;
|
||||||
|
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
||||||
|
std::ifstream infile(dbFile.c_str());
|
||||||
|
|
||||||
|
cdb = new CollectionDatabase(&db, &config);
|
||||||
|
|
||||||
|
if(!cdb->Initialize())
|
||||||
|
{
|
||||||
|
delete cdb;
|
||||||
|
cdb = NULL;
|
||||||
|
}
|
||||||
|
else if(!cdb->Import())
|
||||||
|
{
|
||||||
|
delete cdb;
|
||||||
|
cdb = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cdb;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user