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