mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 18:25:30 +02:00
Setting code formatting standard to allman.
This commit is contained in:
254
Source/Main.cpp
254
Source/Main.cpp
@@ -22,171 +22,173 @@ CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Configuration::Initialize();
|
||||
Configuration::Initialize();
|
||||
|
||||
Configuration config;
|
||||
Configuration config;
|
||||
|
||||
if(!StartLogging()) {
|
||||
return -1;
|
||||
}
|
||||
if(!StartLogging())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!ImportConfiguration(&config))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(!ImportConfiguration(&config))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
DB db(Configuration::GetAbsolutePath() + "/cache.db");
|
||||
DB db(Configuration::GetAbsolutePath() + "/cache.db");
|
||||
|
||||
if(!db.Initialize())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!db.Initialize())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
CollectionDatabase *cdb = InitializeCollectionDatabase(db, config);
|
||||
if(!cdb) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
RetroFE p(cdb, &config);
|
||||
CollectionDatabase *cdb = InitializeCollectionDatabase(db, config);
|
||||
if(!cdb)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(p.Initialize())
|
||||
{
|
||||
p.Run();
|
||||
}
|
||||
RetroFE p(cdb, &config);
|
||||
|
||||
p.DeInitialize();
|
||||
if(p.Initialize())
|
||||
{
|
||||
p.Run();
|
||||
}
|
||||
|
||||
Logger::DeInitialize();
|
||||
p.DeInitialize();
|
||||
|
||||
return 0;
|
||||
Logger::DeInitialize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ImportConfiguration(Configuration *c)
|
||||
{
|
||||
std::string configPath = Configuration::GetAbsolutePath();
|
||||
std::string launchersPath = Configuration::GetAbsolutePath() + "/Launchers";
|
||||
std::string collectionsPath = Configuration::GetAbsolutePath() + "/Collections";
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
std::string configPath = Configuration::GetAbsolutePath();
|
||||
std::string launchersPath = Configuration::GetAbsolutePath() + "/Launchers";
|
||||
std::string collectionsPath = Configuration::GetAbsolutePath() + "/Collections";
|
||||
DIR *dp;
|
||||
struct dirent *dirp;
|
||||
|
||||
if(!c->Import("", configPath + "/Settings.conf"))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
||||
return false;
|
||||
}
|
||||
if(!c->Import("", configPath + "/Settings.conf"))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!c->Import("controls", configPath + "/Controls.conf"))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
||||
return false;
|
||||
}
|
||||
if(!c->Import("controls", configPath + "/Controls.conf"))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + configPath + "/Settings.conf\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
dp = opendir(launchersPath.c_str());
|
||||
dp = opendir(launchersPath.c_str());
|
||||
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not read directory \"" + launchersPath + "\"");
|
||||
return false;
|
||||
}
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not read directory \"" + launchersPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
|
||||
{
|
||||
std::string basename = dirp->d_name;
|
||||
|
||||
// if(basename.length() > 0)
|
||||
{
|
||||
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
|
||||
basename = basename.substr(0, basename.find_last_of("."));
|
||||
|
||||
if(extension == ".conf")
|
||||
{
|
||||
std::string prefix = "launchers." + basename;
|
||||
|
||||
std::string importFile = launchersPath + "/" + std::string(dirp->d_name);
|
||||
|
||||
if(!c->Import(prefix, importFile))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dp = opendir(collectionsPath.c_str());
|
||||
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not read directory \"" + collectionsPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if (dirp->d_type == DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
|
||||
{
|
||||
std::string prefix = "collections." + std::string(dirp->d_name);
|
||||
|
||||
std::string settingsFile = collectionsPath + "/" + dirp->d_name + "/Settings.conf";
|
||||
|
||||
if(!c->Import(prefix, settingsFile))
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsFile + "\"");
|
||||
return false;
|
||||
std::string basename = dirp->d_name;
|
||||
|
||||
// if(basename.length() > 0)
|
||||
{
|
||||
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
|
||||
basename = basename.substr(0, basename.find_last_of("."));
|
||||
|
||||
if(extension == ".conf")
|
||||
{
|
||||
std::string prefix = "launchers." + basename;
|
||||
|
||||
std::string importFile = launchersPath + "/" + std::string(dirp->d_name);
|
||||
|
||||
if(!c->Import(prefix, importFile))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
||||
dp = opendir(collectionsPath.c_str());
|
||||
|
||||
return true;
|
||||
if(dp == NULL)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not read directory \"" + collectionsPath + "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
while((dirp = readdir(dp)) != NULL)
|
||||
{
|
||||
if (dirp->d_type == DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
|
||||
{
|
||||
std::string prefix = "collections." + std::string(dirp->d_name);
|
||||
|
||||
std::string settingsFile = collectionsPath + "/" + dirp->d_name + "/Settings.conf";
|
||||
|
||||
if(!c->Import(prefix, settingsFile))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsFile + "\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StartLogging()
|
||||
bool StartLogging()
|
||||
{
|
||||
std::string logFile = Configuration::GetAbsolutePath() + "/Log.txt";
|
||||
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;
|
||||
}
|
||||
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");
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Version " + Version::GetString() + " starting");
|
||||
|
||||
#ifdef WIN32
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Windows");
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Windows");
|
||||
#else
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux");
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "OS: Linux");
|
||||
#endif
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Absolute path: " + Configuration::GetAbsolutePath());
|
||||
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Absolute path: " + Configuration::GetAbsolutePath());
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config)
|
||||
CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config)
|
||||
{
|
||||
CollectionDatabase *cdb = NULL;
|
||||
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
||||
std::ifstream infile(dbFile.c_str());
|
||||
CollectionDatabase *cdb = NULL;
|
||||
std::string dbFile = (Configuration::GetAbsolutePath() + "/cache.db");
|
||||
std::ifstream infile(dbFile.c_str());
|
||||
|
||||
cdb = new CollectionDatabase(&db, &config);
|
||||
cdb = new CollectionDatabase(&db, &config);
|
||||
|
||||
if(!cdb->Initialize())
|
||||
{
|
||||
delete cdb;
|
||||
cdb = NULL;
|
||||
}
|
||||
else if(!cdb->Import())
|
||||
{
|
||||
delete cdb;
|
||||
cdb = NULL;
|
||||
}
|
||||
if(!cdb->Initialize())
|
||||
{
|
||||
delete cdb;
|
||||
cdb = NULL;
|
||||
}
|
||||
else if(!cdb->Import())
|
||||
{
|
||||
delete cdb;
|
||||
cdb = NULL;
|
||||
}
|
||||
|
||||
return cdb;
|
||||
return cdb;
|
||||
}
|
||||
Reference in New Issue
Block a user