mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-03-21 11:22:53 +01:00
Setting code formatting standard to allman.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,30 +15,30 @@ class Item;
|
||||
class CollectionDatabase
|
||||
{
|
||||
public:
|
||||
CollectionDatabase(DB *db, Configuration *c);
|
||||
virtual ~CollectionDatabase();
|
||||
bool Initialize();
|
||||
bool Import();
|
||||
bool ResetDatabase();
|
||||
CollectionDatabase(DB *db, Configuration *c);
|
||||
virtual ~CollectionDatabase();
|
||||
bool Initialize();
|
||||
bool Import();
|
||||
bool ResetDatabase();
|
||||
|
||||
|
||||
bool GetCollection(std::string collectionName, std::vector<Item *> &list);
|
||||
bool SetHidden(std::string collectionName, Item *item, bool hidden);
|
||||
bool GetCollection(std::string collectionName, std::vector<Item *> &list);
|
||||
bool SetHidden(std::string collectionName, Item *item, bool hidden);
|
||||
|
||||
private:
|
||||
unsigned long CalculateCollectionCrc32(CollectionInfo *info);
|
||||
bool CollectionChanged(CollectionInfo *info, unsigned long crc32);
|
||||
unsigned long CrcFile(std::string file, unsigned long crc);
|
||||
unsigned long CalculateCollectionCrc32(CollectionInfo *info);
|
||||
bool CollectionChanged(CollectionInfo *info, unsigned long crc32);
|
||||
unsigned long CrcFile(std::string file, unsigned long crc);
|
||||
|
||||
// bool ImportMetadata(CollectionInfo *info);
|
||||
bool ImportDirectory(CollectionInfo *info, unsigned long crc32);
|
||||
bool ImportBasicList(CollectionInfo *info,
|
||||
std::string file,
|
||||
std::map<std::string, Item *> &list);
|
||||
bool ImportHyperList(CollectionInfo *info,
|
||||
std::string file,
|
||||
std::map<std::string, Item *> &list);
|
||||
std::map<std::string, Item *> *ImportHyperList(CollectionInfo *info);
|
||||
Configuration *Config;
|
||||
DB *DBInstance;
|
||||
bool ImportDirectory(CollectionInfo *info, unsigned long crc32);
|
||||
bool ImportBasicList(CollectionInfo *info,
|
||||
std::string file,
|
||||
std::map<std::string, Item *> &list);
|
||||
bool ImportHyperList(CollectionInfo *info,
|
||||
std::string file,
|
||||
std::map<std::string, Item *> &list);
|
||||
std::map<std::string, Item *> *ImportHyperList(CollectionInfo *info);
|
||||
Configuration *Config;
|
||||
DB *DBInstance;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
std::string Configuration::AbsolutePath;
|
||||
|
||||
Configuration::Configuration()
|
||||
: Verbose(false)
|
||||
: Verbose(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,307 +27,307 @@ Configuration::~Configuration()
|
||||
{
|
||||
}
|
||||
|
||||
void Configuration::Initialize()
|
||||
void Configuration::Initialize()
|
||||
{
|
||||
const char *environment = std::getenv("RETROFE_PATH");
|
||||
std::string environmentStr;
|
||||
if (environment != NULL)
|
||||
{
|
||||
environmentStr = environment;
|
||||
Configuration::SetAbsolutePath(environment);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
Configuration::SetAbsolutePath(sPath);
|
||||
}
|
||||
}
|
||||
|
||||
bool Configuration::Import(std::string keyPrefix, std::string file)
|
||||
{
|
||||
bool retVal = true;
|
||||
int lineCount = 0;
|
||||
std::string line;
|
||||
bool retVal = true;
|
||||
int lineCount = 0;
|
||||
std::string line;
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "Configuration", "Importing " + file);
|
||||
Logger::Write(Logger::ZONE_INFO, "Configuration", "Importing " + file);
|
||||
|
||||
std::ifstream ifs(file.c_str());
|
||||
std::ifstream ifs(file.c_str());
|
||||
|
||||
if (!ifs.is_open())
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Could not open " + file);
|
||||
if (!ifs.is_open())
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "Configuration", "Could not open " + file);
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
while (std::getline (ifs, line))
|
||||
{
|
||||
lineCount++;
|
||||
retVal = retVal && ParseLine(keyPrefix, line, lineCount);
|
||||
}
|
||||
while (std::getline (ifs, line))
|
||||
{
|
||||
lineCount++;
|
||||
retVal = retVal && ParseLine(keyPrefix, line, lineCount);
|
||||
}
|
||||
|
||||
ifs.close();
|
||||
ifs.close();
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool Configuration::ParseLine(std::string keyPrefix, std::string line, int lineCount)
|
||||
{
|
||||
bool retVal = false;
|
||||
std::string key;
|
||||
std::string value;
|
||||
size_t position;
|
||||
std::string delimiter = "=";
|
||||
bool retVal = false;
|
||||
std::string key;
|
||||
std::string value;
|
||||
size_t position;
|
||||
std::string delimiter = "=";
|
||||
|
||||
// strip out any comments
|
||||
if((position = line.find("#")) != std::string::npos)
|
||||
{
|
||||
line = line.substr(0, position);
|
||||
}
|
||||
// unix only wants \n. Windows uses \r\n. Strip off the \r for unix.
|
||||
line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
|
||||
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
|
||||
{
|
||||
retVal = true;
|
||||
}
|
||||
// all configuration fields must have an assignment operator
|
||||
else if((position = line.find(delimiter)) != std::string::npos)
|
||||
{
|
||||
if(keyPrefix.size() != 0)
|
||||
{
|
||||
keyPrefix += ".";
|
||||
}
|
||||
// strip out any comments
|
||||
if((position = line.find("#")) != std::string::npos)
|
||||
{
|
||||
line = line.substr(0, position);
|
||||
}
|
||||
// unix only wants \n. Windows uses \r\n. Strip off the \r for unix.
|
||||
line.erase( std::remove(line.begin(), line.end(), '\r'), line.end() );
|
||||
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
|
||||
{
|
||||
retVal = true;
|
||||
}
|
||||
// all configuration fields must have an assignment operator
|
||||
else if((position = line.find(delimiter)) != std::string::npos)
|
||||
{
|
||||
if(keyPrefix.size() != 0)
|
||||
{
|
||||
keyPrefix += ".";
|
||||
}
|
||||
|
||||
key = keyPrefix + line.substr(0, position);
|
||||
key = keyPrefix + line.substr(0, position);
|
||||
|
||||
key = TrimEnds(key);
|
||||
key = TrimEnds(key);
|
||||
|
||||
|
||||
value = line.substr(position + delimiter.length(), line.length());
|
||||
value = TrimEnds(value);
|
||||
value = line.substr(position + delimiter.length(), line.length());
|
||||
value = TrimEnds(value);
|
||||
|
||||
|
||||
Properties.insert(PropertiesPair(key, value));
|
||||
Properties.insert(PropertiesPair(key, value));
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Dump: " << "\"" << key << "\" = \"" << value << "\"";
|
||||
std::stringstream ss;
|
||||
ss << "Dump: " << "\"" << key << "\" = \"" << value << "\"";
|
||||
|
||||
|
||||
Logger::Write(Logger::ZONE_INFO, "Configuration", ss.str());
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Missing an assignment operator (=) on line " << lineCount;
|
||||
Logger::Write(Logger::ZONE_ERROR, "Configuration", ss.str());
|
||||
}
|
||||
Logger::Write(Logger::ZONE_INFO, "Configuration", ss.str());
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Missing an assignment operator (=) on line " << lineCount;
|
||||
Logger::Write(Logger::ZONE_ERROR, "Configuration", ss.str());
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
std::string Configuration::TrimEnds(std::string str)
|
||||
{
|
||||
// strip off any initial tabs or spaces
|
||||
size_t trimStart = str.find_first_not_of(" \t");
|
||||
// strip off any initial tabs or spaces
|
||||
size_t trimStart = str.find_first_not_of(" \t");
|
||||
|
||||
if(trimStart != std::string::npos)
|
||||
{
|
||||
size_t trimEnd = str.find_last_not_of(" \t");
|
||||
if(trimStart != std::string::npos)
|
||||
{
|
||||
size_t trimEnd = str.find_last_not_of(" \t");
|
||||
|
||||
str = str.substr(trimStart, trimEnd - trimStart + 1);
|
||||
}
|
||||
str = str.substr(trimStart, trimEnd - trimStart + 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
bool Configuration::GetProperty(std::string key, std::string &value)
|
||||
{
|
||||
bool retVal = false;
|
||||
if(Properties.find(key) != Properties.end())
|
||||
{
|
||||
value = Properties[key];
|
||||
bool retVal = false;
|
||||
if(Properties.find(key) != Properties.end())
|
||||
{
|
||||
value = Properties[key];
|
||||
|
||||
retVal = true;
|
||||
}
|
||||
else if(Verbose)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Configuration", "Missing property " + key);
|
||||
}
|
||||
retVal = true;
|
||||
}
|
||||
else if(Verbose)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_DEBUG, "Configuration", "Missing property " + key);
|
||||
}
|
||||
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool Configuration::GetProperty(std::string key, int &value)
|
||||
{
|
||||
std::string strValue;
|
||||
std::string strValue;
|
||||
|
||||
bool retVal = GetProperty(key, strValue);
|
||||
bool retVal = GetProperty(key, strValue);
|
||||
|
||||
if(retVal)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << strValue;
|
||||
ss >> value;
|
||||
}
|
||||
if(retVal)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << strValue;
|
||||
ss >> value;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool Configuration::GetProperty(std::string key, bool &value)
|
||||
{
|
||||
std::string strValue;
|
||||
std::string strValue;
|
||||
|
||||
bool retVal = GetProperty(key, strValue);
|
||||
bool retVal = GetProperty(key, strValue);
|
||||
|
||||
if(retVal)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << strValue;
|
||||
if(retVal)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << strValue;
|
||||
|
||||
for(unsigned int i=0; i < strValue.length(); ++i)
|
||||
{
|
||||
std::locale loc;
|
||||
strValue[i] = std::tolower(strValue[i], loc);
|
||||
}
|
||||
for(unsigned int i=0; i < strValue.length(); ++i)
|
||||
{
|
||||
std::locale loc;
|
||||
strValue[i] = std::tolower(strValue[i], loc);
|
||||
}
|
||||
|
||||
if(!strValue.compare("yes") || !strValue.compare("true"))
|
||||
{
|
||||
value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
if(!strValue.compare("yes") || !strValue.compare("true"))
|
||||
{
|
||||
value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void Configuration::SetProperty(std::string key, std::string value)
|
||||
{
|
||||
Properties[key] = value;
|
||||
Properties[key] = value;
|
||||
}
|
||||
|
||||
bool Configuration::PropertyExists(std::string key)
|
||||
{
|
||||
return (Properties.find(key) != Properties.end());
|
||||
return (Properties.find(key) != Properties.end());
|
||||
}
|
||||
|
||||
bool Configuration::PropertyPrefixExists(std::string key)
|
||||
{
|
||||
PropertiesType::iterator it;
|
||||
PropertiesType::iterator it;
|
||||
|
||||
for(it = Properties.begin(); it != Properties.end(); ++it)
|
||||
{
|
||||
std::string search = key + ".";
|
||||
if(it->first.compare(0, search.length(), search) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(it = Properties.begin(); it != Properties.end(); ++it)
|
||||
{
|
||||
std::string search = key + ".";
|
||||
if(it->first.compare(0, search.length(), search) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Configuration::GetChildKeyCrumbs(std::string parent, std::vector<std::string> &children)
|
||||
{
|
||||
PropertiesType::iterator it;
|
||||
PropertiesType::iterator it;
|
||||
|
||||
for(it = Properties.begin(); it != Properties.end(); ++it)
|
||||
{
|
||||
std::string search = parent + ".";
|
||||
if(it->first.compare(0, search.length(), search) == 0)
|
||||
{
|
||||
std::string crumb = Utils::Replace(it->first, search, "");
|
||||
for(it = Properties.begin(); it != Properties.end(); ++it)
|
||||
{
|
||||
std::string search = parent + ".";
|
||||
if(it->first.compare(0, search.length(), search) == 0)
|
||||
{
|
||||
std::string crumb = Utils::Replace(it->first, search, "");
|
||||
|
||||
std::size_t end = crumb.find_first_of(".");
|
||||
std::size_t end = crumb.find_first_of(".");
|
||||
|
||||
if(end != std::string::npos)
|
||||
{
|
||||
crumb = crumb.substr(0, end);
|
||||
}
|
||||
if(end != std::string::npos)
|
||||
{
|
||||
crumb = crumb.substr(0, end);
|
||||
}
|
||||
|
||||
if(std::find(children.begin(), children.end(), crumb) == children.end())
|
||||
{
|
||||
children.push_back(crumb);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(std::find(children.begin(), children.end(), crumb) == children.end())
|
||||
{
|
||||
children.push_back(crumb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Configuration::ConvertToAbsolutePath(std::string prefix, std::string path)
|
||||
{
|
||||
char first = ' ';
|
||||
char second = ' ';
|
||||
char first = ' ';
|
||||
char second = ' ';
|
||||
|
||||
if(path.length() >= 0)
|
||||
{
|
||||
first = path.c_str()[0];
|
||||
}
|
||||
if(path.length() >= 1)
|
||||
{
|
||||
second = path.c_str()[1];
|
||||
}
|
||||
if(path.length() >= 0)
|
||||
{
|
||||
first = path.c_str()[0];
|
||||
}
|
||||
if(path.length() >= 1)
|
||||
{
|
||||
second = path.c_str()[1];
|
||||
}
|
||||
|
||||
// check to see if it is already an absolute path
|
||||
if((first != '/') &&
|
||||
(first != '\\') &&
|
||||
//(first != '.') &&
|
||||
(second != ':'))
|
||||
{
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
// check to see if it is already an absolute path
|
||||
if((first != '/') &&
|
||||
(first != '\\') &&
|
||||
//(first != '.') &&
|
||||
(second != ':'))
|
||||
{
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
|
||||
return path;
|
||||
return path;
|
||||
}
|
||||
|
||||
bool Configuration::GetPropertyAbsolutePath(std::string key, std::string &value)
|
||||
{
|
||||
bool retVal = GetProperty(key, value);
|
||||
bool retVal = GetProperty(key, value);
|
||||
|
||||
if(retVal)
|
||||
{
|
||||
value = ConvertToAbsolutePath(GetAbsolutePath(), value);
|
||||
}
|
||||
if(retVal)
|
||||
{
|
||||
value = ConvertToAbsolutePath(GetAbsolutePath(), value);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void Configuration::SetAbsolutePath(std::string absolutePath)
|
||||
{
|
||||
AbsolutePath = absolutePath;
|
||||
AbsolutePath = absolutePath;
|
||||
}
|
||||
|
||||
std::string Configuration::GetAbsolutePath()
|
||||
{
|
||||
return AbsolutePath;
|
||||
return AbsolutePath;
|
||||
}
|
||||
|
||||
bool Configuration::IsVerbose() const
|
||||
{
|
||||
return Verbose;
|
||||
return Verbose;
|
||||
}
|
||||
|
||||
void Configuration::SetVerbose(bool verbose)
|
||||
{
|
||||
this->Verbose = verbose;
|
||||
this->Verbose = verbose;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,35 +10,35 @@
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
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);
|
||||
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
|
||||
bool Import(std::string keyPrefix, std::string file);
|
||||
// gets the global configuration
|
||||
bool Import(std::string keyPrefix, std::string file);
|
||||
|
||||
bool GetProperty(std::string key, std::string &value);
|
||||
bool GetProperty(std::string key, int &value);
|
||||
bool GetProperty(std::string key, bool &value);
|
||||
void GetChildKeyCrumbs(std::string parent, std::vector<std::string> &children);
|
||||
void SetProperty(std::string key, std::string value);
|
||||
bool PropertyExists(std::string key);
|
||||
bool PropertyPrefixExists(std::string key);
|
||||
bool GetPropertyAbsolutePath(std::string key, std::string &value);
|
||||
bool IsVerbose() const;
|
||||
void SetVerbose(bool verbose);
|
||||
bool IsRequiredPropertiesSet();
|
||||
bool GetProperty(std::string key, std::string &value);
|
||||
bool GetProperty(std::string key, int &value);
|
||||
bool GetProperty(std::string key, bool &value);
|
||||
void GetChildKeyCrumbs(std::string parent, std::vector<std::string> &children);
|
||||
void SetProperty(std::string key, std::string value);
|
||||
bool PropertyExists(std::string key);
|
||||
bool PropertyPrefixExists(std::string key);
|
||||
bool GetPropertyAbsolutePath(std::string key, std::string &value);
|
||||
bool IsVerbose() const;
|
||||
void SetVerbose(bool verbose);
|
||||
bool IsRequiredPropertiesSet();
|
||||
|
||||
private:
|
||||
bool ParseLine(std::string keyPrefix, std::string line, int lineCount);
|
||||
std::string TrimEnds(std::string str);
|
||||
typedef std::map<std::string, std::string> PropertiesType;
|
||||
typedef std::pair<std::string, std::string> PropertiesPair;
|
||||
bool Verbose;
|
||||
bool ParseLine(std::string keyPrefix, std::string line, int lineCount);
|
||||
std::string TrimEnds(std::string str);
|
||||
typedef std::map<std::string, std::string> PropertiesType;
|
||||
typedef std::pair<std::string, std::string> PropertiesPair;
|
||||
bool Verbose;
|
||||
|
||||
static std::string AbsolutePath;
|
||||
PropertiesType Properties;
|
||||
static std::string AbsolutePath;
|
||||
PropertiesType Properties;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#include "DB.h"
|
||||
#include "../Utility/Log.h"
|
||||
@@ -8,42 +8,42 @@
|
||||
#include <fstream>
|
||||
|
||||
DB::DB(std::string dbFile)
|
||||
: Path(dbFile)
|
||||
, Handle(NULL)
|
||||
: Path(dbFile)
|
||||
, Handle(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
DB::~DB()
|
||||
{
|
||||
DeInitialize();
|
||||
DeInitialize();
|
||||
}
|
||||
|
||||
bool DB::Initialize()
|
||||
{
|
||||
bool retVal = false;
|
||||
bool retVal = false;
|
||||
|
||||
if(sqlite3_open(Path.c_str(), &Handle) != 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Cannot open database: \"" << Path << "\"" << sqlite3_errmsg(Handle);
|
||||
Logger::Write(Logger::ZONE_ERROR, "Database", ss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Database", "Opened database \"" + Path + "\"");
|
||||
retVal = true;
|
||||
}
|
||||
if(sqlite3_open(Path.c_str(), &Handle) != 0)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Cannot open database: \"" << Path << "\"" << sqlite3_errmsg(Handle);
|
||||
Logger::Write(Logger::ZONE_ERROR, "Database", ss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Database", "Opened database \"" + Path + "\"");
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
void DB::DeInitialize()
|
||||
{
|
||||
if(Handle != NULL)
|
||||
{
|
||||
sqlite3_close(Handle);
|
||||
Handle = NULL;
|
||||
}
|
||||
if(Handle != NULL)
|
||||
{
|
||||
sqlite3_close(Handle);
|
||||
Handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -8,14 +8,17 @@
|
||||
class DB
|
||||
{
|
||||
public:
|
||||
DB(std::string dbFile);
|
||||
bool Initialize();
|
||||
void DeInitialize();
|
||||
virtual ~DB();
|
||||
sqlite3 *GetHandle() { return Handle; }
|
||||
DB(std::string dbFile);
|
||||
bool Initialize();
|
||||
void DeInitialize();
|
||||
virtual ~DB();
|
||||
sqlite3 *GetHandle()
|
||||
{
|
||||
return Handle;
|
||||
}
|
||||
|
||||
private:
|
||||
sqlite3 *Handle;
|
||||
std::string Path;
|
||||
sqlite3 *Handle;
|
||||
std::string Path;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#include "MamelistMetadata.h"
|
||||
#include "DB.h"
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
MamelistMetadata::MamelistMetadata(DB *dbInstance)
|
||||
: DBInstance(dbInstance)
|
||||
: DBInstance(dbInstance)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,97 +23,97 @@ MamelistMetadata::~MamelistMetadata()
|
||||
|
||||
bool MamelistMetadata::Import(std::string filename, std::string collection)
|
||||
{
|
||||
bool retVal = true;
|
||||
rapidxml::xml_document<> doc;
|
||||
rapidxml::xml_node<> * rootNode;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
bool retVal = true;
|
||||
rapidxml::xml_document<> doc;
|
||||
rapidxml::xml_node<> * rootNode;
|
||||
char *error = NULL;
|
||||
sqlite3 *handle = DBInstance->GetHandle();
|
||||
|
||||
std::ifstream f(filename.c_str());
|
||||
std::ifstream f(filename.c_str());
|
||||
|
||||
if (!f.good())
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "Mamelist", "Could not find mamelist metadata file at \"" + filename + "\"");
|
||||
if (!f.good())
|
||||
{
|
||||
Logger::Write(Logger::ZONE_ERROR, "Mamelist", "Could not find mamelist metadata file at \"" + filename + "\"");
|
||||
|
||||
retVal = false;
|
||||
}
|
||||
retVal = false;
|
||||
}
|
||||
|
||||
f.close();
|
||||
f.close();
|
||||
|
||||
if(retVal)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Mamelist", "Importing mamelist file \"" + filename + "\"");
|
||||
std::ifstream file(filename.c_str());
|
||||
std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
if(retVal)
|
||||
{
|
||||
Logger::Write(Logger::ZONE_INFO, "Mamelist", "Importing mamelist file \"" + filename + "\"");
|
||||
std::ifstream file(filename.c_str());
|
||||
std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
|
||||
buffer.push_back('\0');
|
||||
buffer.push_back('\0');
|
||||
|
||||
doc.parse<0>(&buffer[0]);
|
||||
doc.parse<0>(&buffer[0]);
|
||||
|
||||
rootNode = doc.first_node("mame");
|
||||
rootNode = doc.first_node("mame");
|
||||
|
||||
sqlite3_exec(handle, "BEGIN IMMEDIATE TRANSACTION;", NULL, NULL, &error);
|
||||
for (rapidxml::xml_node<> * game = rootNode->first_node("game"); game; game = game->next_sibling())
|
||||
{
|
||||
rapidxml::xml_attribute<> *nameNode = game->first_attribute("name");
|
||||
rapidxml::xml_attribute<> *cloneOfXml = game->first_attribute("cloneof");
|
||||
sqlite3_exec(handle, "BEGIN IMMEDIATE TRANSACTION;", NULL, NULL, &error);
|
||||
for (rapidxml::xml_node<> * game = rootNode->first_node("game"); game; game = game->next_sibling())
|
||||
{
|
||||
rapidxml::xml_attribute<> *nameNode = game->first_attribute("name");
|
||||
rapidxml::xml_attribute<> *cloneOfXml = game->first_attribute("cloneof");
|
||||
|
||||
if(nameNode != NULL)
|
||||
{
|
||||
std::string name = nameNode->value();
|
||||
rapidxml::xml_node<> *descriptionNode = game->first_node("description");
|
||||
rapidxml::xml_node<> *yearNode = game->first_node("year");
|
||||
rapidxml::xml_node<> *manufacturerNode = game->first_node("manufacturer");
|
||||
rapidxml::xml_node<> *inputNode = game->first_node("input");
|
||||
if(nameNode != NULL)
|
||||
{
|
||||
std::string name = nameNode->value();
|
||||
rapidxml::xml_node<> *descriptionNode = game->first_node("description");
|
||||
rapidxml::xml_node<> *yearNode = game->first_node("year");
|
||||
rapidxml::xml_node<> *manufacturerNode = game->first_node("manufacturer");
|
||||
rapidxml::xml_node<> *inputNode = game->first_node("input");
|
||||
|
||||
std::string description = (descriptionNode == NULL) ? nameNode->value() : descriptionNode->value();
|
||||
std::string year = (yearNode == NULL) ? "" : yearNode->value();
|
||||
std::string manufacturer = (manufacturerNode == NULL) ? "" : manufacturerNode->value();
|
||||
std::string cloneOf = (cloneOfXml == NULL) ? "" : cloneOfXml->value();
|
||||
std::string players;
|
||||
std::string buttons;
|
||||
std::string description = (descriptionNode == NULL) ? nameNode->value() : descriptionNode->value();
|
||||
std::string year = (yearNode == NULL) ? "" : yearNode->value();
|
||||
std::string manufacturer = (manufacturerNode == NULL) ? "" : manufacturerNode->value();
|
||||
std::string cloneOf = (cloneOfXml == NULL) ? "" : cloneOfXml->value();
|
||||
std::string players;
|
||||
std::string buttons;
|
||||
|
||||
if(inputNode != NULL)
|
||||
{
|
||||
rapidxml::xml_attribute<> *playersAttribute = inputNode->first_attribute("players");
|
||||
rapidxml::xml_attribute<> *buttonsAttribute = inputNode->first_attribute("buttons");
|
||||
if(inputNode != NULL)
|
||||
{
|
||||
rapidxml::xml_attribute<> *playersAttribute = inputNode->first_attribute("players");
|
||||
rapidxml::xml_attribute<> *buttonsAttribute = inputNode->first_attribute("buttons");
|
||||
|
||||
if(playersAttribute)
|
||||
{
|
||||
players = playersAttribute->value();
|
||||
}
|
||||
if(playersAttribute)
|
||||
{
|
||||
players = playersAttribute->value();
|
||||
}
|
||||
|
||||
if(buttonsAttribute)
|
||||
{
|
||||
buttons = buttonsAttribute->value();
|
||||
}
|
||||
if(buttonsAttribute)
|
||||
{
|
||||
buttons = buttonsAttribute->value();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_prepare_v2(handle,
|
||||
"UPDATE OR REPLACE Meta SET title=?, year=?, manufacturer=?, players=?, buttons=?, cloneOf=? WHERE name=? AND collectionName=?;",
|
||||
-1, &stmt, 0);
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3_prepare_v2(handle,
|
||||
"UPDATE OR REPLACE Meta SET title=?, year=?, manufacturer=?, players=?, buttons=?, cloneOf=? WHERE name=? AND collectionName=?;",
|
||||
-1, &stmt, 0);
|
||||
|
||||
sqlite3_bind_text(stmt, 1, description.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 2, year.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 3, manufacturer.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 4, players.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 5, buttons.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 6, cloneOf.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 7, name.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 8, collection.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 1, description.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 2, year.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 3, manufacturer.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 4, players.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 5, buttons.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 6, cloneOf.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 7, name.c_str(), -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_text(stmt, 8, collection.c_str(), -1, SQLITE_TRANSIENT);
|
||||
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
}
|
||||
}
|
||||
sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error);
|
||||
}
|
||||
}
|
||||
sqlite3_exec(handle, "COMMIT TRANSACTION;", NULL, NULL, &error);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
/* This file is subject to the terms and conditions defined in
|
||||
* file 'LICENSE.txt', which is part of this source code package.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
@@ -10,9 +10,9 @@ class DB;
|
||||
class MamelistMetadata : Metadata
|
||||
{
|
||||
public:
|
||||
MamelistMetadata(DB *dbInstance);
|
||||
virtual ~MamelistMetadata();
|
||||
bool Import(std::string file, std::string collectionName);
|
||||
MamelistMetadata(DB *dbInstance);
|
||||
virtual ~MamelistMetadata();
|
||||
bool Import(std::string file, std::string collectionName);
|
||||
private:
|
||||
DB *DBInstance;
|
||||
DB *DBInstance;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
class Metadata
|
||||
{
|
||||
public:
|
||||
virtual ~Metadata() {}
|
||||
virtual bool Import(std::string file, std::string collectionName) = 0;
|
||||
virtual ~Metadata() {}
|
||||
virtual bool Import(std::string file, std::string collectionName) = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user