mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-01-27 02:05:06 +01:00
Make config and DB pass by reference for database classes.
This commit is contained in:
parent
f89d817db6
commit
9a56630d46
@ -5,7 +5,7 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
CollectionInfoBuilder::CollectionInfoBuilder(Configuration *c)
|
||||
CollectionInfoBuilder::CollectionInfoBuilder(Configuration &c)
|
||||
: Conf(c)
|
||||
{
|
||||
}
|
||||
@ -26,7 +26,7 @@ bool CollectionInfoBuilder::LoadAllCollections()
|
||||
{
|
||||
std::vector<std::string> collections;
|
||||
|
||||
Conf->GetChildKeyCrumbs("collections", collections);
|
||||
Conf.GetChildKeyCrumbs("collections", collections);
|
||||
|
||||
if(collections.size() == 0)
|
||||
{
|
||||
@ -92,22 +92,22 @@ bool CollectionInfoBuilder::ImportCollection(std::string name)
|
||||
std::string metadataType;
|
||||
std::string metadataPath;
|
||||
|
||||
if(!Conf->GetPropertyAbsolutePath(listItemsPathKey, listItemsPath))
|
||||
if(!Conf.GetPropertyAbsolutePath(listItemsPathKey, listItemsPath))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Collections", "Property \"" + listItemsPathKey + "\" does not exist. Assuming \"" + name + "\" is a menu");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!Conf->GetProperty(extensionsKey, extensions))
|
||||
if(!Conf.GetProperty(extensionsKey, extensions))
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Collections", "Property \"" + extensionsKey + "\" does not exist. Assuming \"" + name + "\" is a menu");
|
||||
return false;
|
||||
}
|
||||
|
||||
(void)Conf->GetProperty(metadataTypeKey, metadataType);
|
||||
(void)Conf->GetProperty(metadataPathKey, metadataPath);
|
||||
(void)Conf.GetProperty(metadataTypeKey, metadataType);
|
||||
(void)Conf.GetProperty(metadataPathKey, metadataPath);
|
||||
|
||||
if(!Conf->GetProperty(launcherKey, launcherName))
|
||||
if(!Conf.GetProperty(launcherKey, launcherName))
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Warning: launcher property \""
|
||||
|
||||
@ -13,7 +13,7 @@ class CollectionInfo;
|
||||
class CollectionInfoBuilder
|
||||
{
|
||||
public:
|
||||
CollectionInfoBuilder(Configuration *c);
|
||||
CollectionInfoBuilder(Configuration &c);
|
||||
virtual ~CollectionInfoBuilder();
|
||||
bool LoadAllCollections();
|
||||
void GetCollections(std::vector<CollectionInfo *> &keys);
|
||||
@ -21,5 +21,5 @@ public:
|
||||
private:
|
||||
bool ImportCollection(std::string name);
|
||||
std::map<std::string, CollectionInfo *> InfoMap;
|
||||
Configuration *Conf;
|
||||
Configuration &Conf;
|
||||
};
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#include <zlib.h>
|
||||
#include <exception>
|
||||
|
||||
CollectionDatabase::CollectionDatabase(DB *db, Configuration *c)
|
||||
CollectionDatabase::CollectionDatabase(DB &db, Configuration &c)
|
||||
: Config(c)
|
||||
, DBInstance(db)
|
||||
{
|
||||
@ -39,7 +39,7 @@ bool CollectionDatabase::ResetDatabase()
|
||||
bool retVal = true;
|
||||
int rc;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "Database", "Erasing");
|
||||
|
||||
@ -65,7 +65,7 @@ bool CollectionDatabase::Initialize()
|
||||
{
|
||||
int rc;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
|
||||
std::string sql;
|
||||
sql.append("CREATE TABLE IF NOT EXISTS CollectionItems(");
|
||||
@ -229,7 +229,7 @@ bool CollectionDatabase::CollectionChanged(CollectionInfo *info, unsigned long c
|
||||
{
|
||||
bool retVal = true;
|
||||
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
@ -255,7 +255,7 @@ bool CollectionDatabase::SetHidden(std::string collectionName, Item *item, bool
|
||||
{
|
||||
bool retVal = true;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
std::string mode = (hidden) ? "hidden":"visible";
|
||||
int isHidden = (hidden)?1:0;
|
||||
|
||||
@ -290,7 +290,7 @@ bool CollectionDatabase::ImportDirectory(CollectionInfo *info, unsigned long crc
|
||||
std::map<std::string, Item *> metaList;
|
||||
bool retVal = true;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
std::string includeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.txt";
|
||||
std::string excludeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Exclude.txt";
|
||||
std::string includeHyperListFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.xml";
|
||||
@ -652,15 +652,15 @@ bool CollectionDatabase::GetCollection(std::string collectionName, std::vector<I
|
||||
{
|
||||
bool retVal = true;
|
||||
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
bool showParenthesis = true;
|
||||
bool showSquareBrackets = true;
|
||||
|
||||
(void)Config->GetProperty("showParenthesis", showParenthesis);
|
||||
(void)Config->GetProperty("showSquareBrackets", showSquareBrackets);
|
||||
(void)Config.GetProperty("showParenthesis", showParenthesis);
|
||||
(void)Config.GetProperty("showSquareBrackets", showSquareBrackets);
|
||||
|
||||
//todo: program crashes if this query fails
|
||||
sqlite3_prepare_v2(handle,
|
||||
@ -731,7 +731,7 @@ bool CollectionDatabase::GetCollection(std::string collectionName, std::vector<I
|
||||
item->SetCloneOf(cloneOf);
|
||||
|
||||
//std::cout << "loading " << title << std::endl;
|
||||
if(Config->GetProperty("collections." + collectionName + ".launcher", launcher))
|
||||
if(Config.GetProperty("collections." + collectionName + ".launcher", launcher))
|
||||
{
|
||||
item->SetLauncher(launcher);
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ class Item;
|
||||
class CollectionDatabase
|
||||
{
|
||||
public:
|
||||
CollectionDatabase(DB *db, Configuration *c);
|
||||
CollectionDatabase(DB &db, Configuration &c);
|
||||
virtual ~CollectionDatabase();
|
||||
bool Initialize();
|
||||
bool Import();
|
||||
@ -39,6 +39,6 @@ private:
|
||||
std::string file,
|
||||
std::map<std::string, Item *> &list);
|
||||
std::map<std::string, Item *> *ImportHyperList(CollectionInfo *info);
|
||||
Configuration *Config;
|
||||
DB *DBInstance;
|
||||
Configuration &Config;
|
||||
DB &DBInstance;
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include <sqlite3.h>
|
||||
|
||||
|
||||
MamelistMetadata::MamelistMetadata(DB *dbInstance)
|
||||
MamelistMetadata::MamelistMetadata(DB &dbInstance)
|
||||
: DBInstance(dbInstance)
|
||||
{
|
||||
}
|
||||
@ -27,7 +27,7 @@ bool MamelistMetadata::Import(std::string filename, std::string collection)
|
||||
rapidxml::xml_document<> doc;
|
||||
rapidxml::xml_node<> * rootNode;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
sqlite3 *handle = DBInstance.GetHandle();
|
||||
|
||||
std::ifstream f(filename.c_str());
|
||||
|
||||
|
||||
@ -10,9 +10,9 @@ class DB;
|
||||
class MamelistMetadata : Metadata
|
||||
{
|
||||
public:
|
||||
MamelistMetadata(DB *dbInstance);
|
||||
MamelistMetadata(DB &dbInstance);
|
||||
virtual ~MamelistMetadata();
|
||||
bool Import(std::string file, std::string collectionName);
|
||||
private:
|
||||
DB *DBInstance;
|
||||
DB &DBInstance;
|
||||
};
|
||||
|
||||
@ -177,7 +177,7 @@ CollectionDatabase *InitializeCollectionDatabase(DB &db, Configuration &config)
|
||||
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())
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user