diff --git a/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx b/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx index fba0e7f0f..2fee16125 100644 --- a/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx +++ b/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx @@ -15,86 +15,32 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include -#include - #include "KeyValueRepositorySqlite.hxx" -#include "bspf.hxx" - -#ifdef BSPF_WINDOWS - #define SEPARATOR "\" -#else - #define SEPARATOR "/" -#endif - -namespace { - struct SqliteError { - SqliteError(const string _message) : message(_message) {} - - const string message; - }; - - class Statement { - public: - - Statement(sqlite3* handle, string sql) : myStmt(nullptr) - { - if (sqlite3_prepare_v2(handle, sql.c_str(), -1, &myStmt, nullptr) != SQLITE_OK) - throw SqliteError(sqlite3_errmsg(handle)); - } - - ~Statement() - { - if (myStmt) sqlite3_finalize(myStmt); - } - - operator sqlite3_stmt*() const { return myStmt; } - - private: - - sqlite3_stmt* myStmt; - - private: - - Statement() = delete; - Statement(const Statement&) = delete; - Statement(Statement&&) = delete; - Statement& operator=(const Statement&) = delete; - Statement& operator=(Statement&&) = delete; - }; -} +#include "SqliteError.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - KeyValueRepositorySqlite::KeyValueRepositorySqlite( - const string& databaseDirectory, - const string& databaseName -) : myDatabaseFile(databaseDirectory + SEPARATOR + databaseName + ".sqlite3"), - myIsFailed(false), - myDbHandle(nullptr) + SqliteDatabase& db, + const string& tableName +) : myTableName(tableName), + myDb(db) {} -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -KeyValueRepositorySqlite::~KeyValueRepositorySqlite() -{ - if (myDbHandle) sqlite3_close(myDbHandle); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - std::map KeyValueRepositorySqlite::load() { std::map values; - if (myIsFailed) return values; try { - initializeDb(); - Statement stmt(myDbHandle, "SELECT `key`, `VALUE` FROM `values`"); + myStmtSelect->reset(); - while (sqlite3_step(stmt) == SQLITE_ROW) - values[reinterpret_cast(sqlite3_column_text(stmt, 0))] = - reinterpret_cast(sqlite3_column_text(stmt, 1)); + while (myStmtSelect->step()) + values[myStmtSelect->columnText(0)] = myStmtSelect->columnText(1); + + myStmtSelect->reset(); } catch (SqliteError err) { - cout << "failed to load from sqlite DB " << myDatabaseFile << ": " << err.message << endl; + cout << err.message << std::endl; } return values; @@ -103,66 +49,34 @@ std::map KeyValueRepositorySqlite::load() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void KeyValueRepositorySqlite::save(const std::map& values) { - if (myIsFailed) return; - try { - initializeDb(); - Statement stmt(myDbHandle, "INSERT OR REPLACE INTO `values` VALUES (?, ?)"); + myStmtInsert->reset(); - if (sqlite3_exec(myDbHandle, "BEGIN TRANSACTION", nullptr, nullptr, nullptr) != SQLITE_OK) - throw SqliteError(sqlite3_errmsg(myDbHandle)); + myDb.exec("BEGIN TRANSACTION"); for (const auto& pair: values) { - sqlite3_bind_text(stmt, 1, pair.first.c_str(), -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, pair.second.toCString(), -1, SQLITE_STATIC); - sqlite3_step(stmt); + (*myStmtInsert) + .bind(1, pair.first.c_str()) + .bind(2, pair.second.toCString()) + .step(); - if (sqlite3_reset(stmt) != SQLITE_OK) throw SqliteError(sqlite3_errmsg(myDbHandle)); + myStmtInsert->reset(); } - if (sqlite3_exec(myDbHandle, "COMMIT", nullptr, nullptr, nullptr) != SQLITE_OK) - throw SqliteError(sqlite3_errmsg(myDbHandle)); + myDb.exec("COMMIT"); } catch (SqliteError err) { - cout << "failed to write to sqlite DB " << myDatabaseFile << ": " << err.message << endl; + cout << err.message << endl; } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void KeyValueRepositorySqlite::initializeDb() +void KeyValueRepositorySqlite::initialize() { - if (myIsFailed || myDbHandle) return; + myDb.exec( + "CREATE TABLE IF NOT EXISTS `" + myTableName + "` (`key` TEXT PRIMARY KEY, `value` TEXT) WITHOUT ROWID" + ); - bool dbInitialized = false; - - for (int tries = 1; tries < 3 && !dbInitialized; tries++) { - dbInitialized = (sqlite3_open(myDatabaseFile.c_str(), &myDbHandle) == SQLITE_OK); - - dbInitialized = dbInitialized && (sqlite3_exec( - myDbHandle, - "CREATE TABLE IF NOT EXISTS `values` (`key` TEXT PRIMARY KEY, `value` TEXT) WITHOUT ROWID", - nullptr, nullptr, nullptr - ) == SQLITE_OK); - - if (!dbInitialized && tries == 1) { - cout << "sqlite DB " << myDatabaseFile << " seems to be corrupt, removing and retrying..." << endl; - - remove(myDatabaseFile.c_str()); - } - } - - myIsFailed = !dbInitialized; - - if (myIsFailed) { - if (myDbHandle) { - string emsg = sqlite3_errmsg(myDbHandle); - - sqlite3_close(myDbHandle); - myDbHandle = nullptr; - - throw SqliteError(emsg); - } - - throw SqliteError("unable to initialize sqlite DB " + myDatabaseFile); - }; + myStmtInsert = make_unique(myDb, "INSERT OR REPLACE INTO `" + myTableName + "` VALUES (?, ?)"); + myStmtSelect = make_unique(myDb, "SELECT `key`, `VALUE` FROM `" + myTableName + "`"); } diff --git a/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx b/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx index 2ab4e2a19..7fbfb2c0d 100644 --- a/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx +++ b/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx @@ -18,34 +18,37 @@ #ifndef KEY_VALUE_REPOSITORY_SQLITE_HXX #define KEY_VALUE_REPOSITORY_SQLITE_HXX -#include - +#include "bspf.hxx" #include "repository/KeyValueRepository.hxx" +#include "SqliteDatabase.hxx" +#include "SqliteStatement.hxx" class KeyValueRepositorySqlite : public KeyValueRepository { public: - KeyValueRepositorySqlite(const string& databaseDirectory, const string& databaseName); - - ~KeyValueRepositorySqlite(); + KeyValueRepositorySqlite(SqliteDatabase& db, const string& tableName); virtual std::map load(); virtual void save(const std::map& values); - private: - - void initializeDb(); + void initialize(); private: - string myDatabaseFile; + string myTableName; + SqliteDatabase& myDb; - bool myIsFailed; + unique_ptr myStmtInsert; + unique_ptr myStmtSelect; - sqlite3* myDbHandle; + private: + KeyValueRepositorySqlite(const KeyValueRepositorySqlite&) = delete; + KeyValueRepositorySqlite(KeyValueRepositorySqlite&&) = delete; + KeyValueRepositorySqlite& operator=(const KeyValueRepositorySqlite&) = delete; + KeyValueRepositorySqlite operator=(KeyValueRepositorySqlite&&) = delete; }; #endif // KEY_VALUE_REPOSITORY_SQLITE_HXX diff --git a/src/common/repository/sqlite/SettingsDb.cxx b/src/common/repository/sqlite/SettingsDb.cxx new file mode 100644 index 000000000..598617d29 --- /dev/null +++ b/src/common/repository/sqlite/SettingsDb.cxx @@ -0,0 +1,49 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "SettingsDb.hxx" +#include "SqliteError.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SettingsDb::SettingsDb( + const string& databaseDirectory, + const string& databaseName +) : myDatabaseDirectory(databaseDirectory), + myDatabaseName(databaseName) +{} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SettingsDb::initialize() +{ + try { + myDb = make_unique(myDatabaseDirectory, myDatabaseName); + myDb->initialize(); + + mySettingsRepository = make_unique(*myDb, "settings"); + mySettingsRepository->initialize(); + } + catch (SqliteError err) { + cout << "sqlite DB " << myDb->fileName() << " failed to initialize: " << err.message << endl; + + myDb.reset(); + mySettingsRepository.reset(); + + return false; + } + + return true; +} diff --git a/src/common/repository/sqlite/SettingsDb.hxx b/src/common/repository/sqlite/SettingsDb.hxx new file mode 100644 index 000000000..4992a962b --- /dev/null +++ b/src/common/repository/sqlite/SettingsDb.hxx @@ -0,0 +1,44 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef SETTINGS_DB_HXX +#define SETTINGS_DB_HXX + +#include "bspf.hxx" +#include "SqliteDatabase.hxx" +#include "KeyValueRepositorySqlite.hxx" + +class SettingsDb +{ + public: + + SettingsDb(const string& databaseDirectory, const string& databaseName); + + bool initialize(); + + KeyValueRepository& settingsRepository() const { return *mySettingsRepository; } + + private: + + string myDatabaseDirectory; + string myDatabaseName; + + unique_ptr myDb; + unique_ptr mySettingsRepository; +}; + +#endif // SETTINGS_DB_HXX diff --git a/src/common/repository/sqlite/SqliteDatabase.cxx b/src/common/repository/sqlite/SqliteDatabase.cxx new file mode 100644 index 000000000..5d9b76c48 --- /dev/null +++ b/src/common/repository/sqlite/SqliteDatabase.cxx @@ -0,0 +1,83 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include + +#include "SqliteDatabase.hxx" +#include "SqliteError.hxx" + +#ifdef BSPF_WINDOWS + #define SEPARATOR "\" +#else + #define SEPARATOR "/" +#endif + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SqliteDatabase::SqliteDatabase( + const string& databaseDirectory, + const string& databaseName +) : myDatabaseFile(databaseDirectory + SEPARATOR + databaseName + ".sqlite3"), + myHandle(nullptr) +{} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SqliteDatabase::~SqliteDatabase() +{ + if (myHandle) sqlite3_close_v2(myHandle); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SqliteDatabase::initialize() +{ + if (myHandle) return; + + bool dbInitialized = false; + + for (int tries = 1; tries < 3 && !dbInitialized; tries++) { + dbInitialized = (sqlite3_open(myDatabaseFile.c_str(), &myHandle) == SQLITE_OK); + + if (dbInitialized) + dbInitialized = sqlite3_exec(myHandle, "PRAGMA schema_version", nullptr, nullptr, nullptr) == SQLITE_OK; + + if (!dbInitialized && tries == 1) { + cout << "sqlite DB " << myDatabaseFile << " seems to be corrupt, removing and retrying..." << endl; + + remove(myDatabaseFile.c_str()); + if (myHandle) sqlite3_close_v2(myHandle); + } + } + + if (!dbInitialized) { + if (myHandle) { + string emsg = sqlite3_errmsg(myHandle); + + sqlite3_close_v2(myHandle); + myHandle = nullptr; + + throw SqliteError(emsg); + } + + throw SqliteError("unable to initialize sqlite DB for unknown reason"); + }; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SqliteDatabase::exec(const string& sql) const +{ + if (sqlite3_exec(myHandle, sql.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK) + throw SqliteError(myHandle); +} diff --git a/src/common/repository/sqlite/SqliteDatabase.hxx b/src/common/repository/sqlite/SqliteDatabase.hxx new file mode 100644 index 000000000..213b58bfc --- /dev/null +++ b/src/common/repository/sqlite/SqliteDatabase.hxx @@ -0,0 +1,55 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef SQLITE_DATABASE_HXX +#define SQLITE_DATABASE_HXX + +#include + +#include "bspf.hxx" + +class SqliteDatabase +{ + public: + + SqliteDatabase(const string& databaseDirectory, const string& databaseName); + + ~SqliteDatabase(); + + void initialize(); + + const string fileName() const { return myDatabaseFile; } + + operator sqlite3*() const { return myHandle; } + + void exec(const string &sql) const; + + private: + + string myDatabaseFile; + + sqlite3* myHandle; + + private: + + SqliteDatabase(const SqliteDatabase&) = delete; + SqliteDatabase(SqliteDatabase&&) = delete; + SqliteDatabase& operator=(const SqliteDatabase&) = delete; + SqliteDatabase& operator=(SqliteDatabase&&) = delete; +}; + +#endif // SQLITE_DATABASE_HXX diff --git a/src/common/repository/sqlite/SqliteError.hxx b/src/common/repository/sqlite/SqliteError.hxx new file mode 100644 index 000000000..facb53172 --- /dev/null +++ b/src/common/repository/sqlite/SqliteError.hxx @@ -0,0 +1,32 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef SQLITE_ERROR_HXX +#define SQLITE_ERROR_HXX + +#include +#include "bspf.hxx" + +struct SqliteError { + SqliteError(const string _message) : message(_message) {} + + SqliteError(sqlite3* handle) : message(sqlite3_errmsg(handle)) {} + + const string message; +}; + +#endif // SQLITE_ERROR_HXX diff --git a/src/common/repository/sqlite/SqliteStatement.cxx b/src/common/repository/sqlite/SqliteStatement.cxx new file mode 100644 index 000000000..bdba38f0f --- /dev/null +++ b/src/common/repository/sqlite/SqliteStatement.cxx @@ -0,0 +1,62 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. + +#include "SqliteStatement.hxx" +#include "SqliteError.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SqliteStatement::SqliteStatement(sqlite3* handle, string sql) : myStmt(nullptr), myHandle(handle) +{ + if (sqlite3_prepare_v2(handle, sql.c_str(), -1, &myStmt, nullptr) != SQLITE_OK) + throw SqliteError(handle); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SqliteStatement::~SqliteStatement() +{ + if (myStmt) sqlite3_finalize(myStmt); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +SqliteStatement& SqliteStatement::bind(int index, const string& value) +{ + if (sqlite3_bind_text(myStmt, index, value.c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK) + throw SqliteError(myHandle); + + return *this; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool SqliteStatement::step() const +{ + int result = sqlite3_step(myStmt); + + if (result == SQLITE_ERROR) throw SqliteError(myHandle); + + return result == SQLITE_ROW; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void SqliteStatement::reset() const +{ + if (sqlite3_reset(myStmt) != SQLITE_OK) throw SqliteError(myHandle); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string SqliteStatement::columnText(int index) const +{ + return reinterpret_cast(sqlite3_column_text(myStmt, index)); +} diff --git a/src/common/repository/sqlite/SqliteStatement.hxx b/src/common/repository/sqlite/SqliteStatement.hxx new file mode 100644 index 000000000..5df447103 --- /dev/null +++ b/src/common/repository/sqlite/SqliteStatement.hxx @@ -0,0 +1,57 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef SQLITE_STATEMENT_HXX +#define SQLITE_STATEMENT_HXX + +#include + +#include "bspf.hxx" + +class SqliteStatement { + public: + + SqliteStatement(sqlite3* handle, string sql); + + ~SqliteStatement(); + + operator sqlite3_stmt*() const { return myStmt; } + + SqliteStatement& bind(int index, const string& value); + + bool step() const; + + void reset() const; + + string columnText(int index) const; + + private: + + sqlite3_stmt* myStmt; + + sqlite3* myHandle; + + private: + + SqliteStatement() = delete; + SqliteStatement(const SqliteStatement&) = delete; + SqliteStatement(SqliteStatement&&) = delete; + SqliteStatement& operator=(const SqliteStatement&) = delete; + SqliteStatement& operator=(SqliteStatement&&) = delete; +}; + +#endif // SQLITE_STATEMENT_HXX diff --git a/src/common/repository/sqlite/module.mk b/src/common/repository/sqlite/module.mk index d23fcb37c..ef6f5b207 100644 --- a/src/common/repository/sqlite/module.mk +++ b/src/common/repository/sqlite/module.mk @@ -1,7 +1,10 @@ MODULE := src/common/repository/sqlite MODULE_OBJS := \ - src/common/repository/sqlite/KeyValueRepositorySqlite.o + src/common/repository/sqlite/KeyValueRepositorySqlite.o \ + src/common/repository/sqlite/SettingsDb.o \ + src/common/repository/sqlite/SqliteDatabase.o \ + src/common/repository/sqlite/SqliteStatement.o MODULE_DIRS += \ src/common/repository/sqlite diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index a8201ffbb..ad1a1f59f 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -105,6 +105,8 @@ OSystem::OSystem() myBuildInfo = info.str(); mySettings = MediaFactory::createSettings(); + + myPropSet = make_unique(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -115,8 +117,6 @@ OSystem::~OSystem() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool OSystem::create() { - // Get updated paths for all configuration files - setConfigPaths(); ostringstream buf; buf << "Stella " << STELLA_VERSION << endl << " Features: " << myFeatures << endl @@ -146,9 +146,6 @@ bool OSystem::create() myEventHandler = MediaFactory::createEventHandler(*this); myEventHandler->initialize(); - // Create the ROM properties database - myPropSet = make_unique(myPropertiesFile); - #ifdef CHEATCODE_SUPPORT myCheatManager = make_unique(*this); myCheatManager->loadCheatDatabase(); @@ -205,10 +202,20 @@ void OSystem::loadConfig(const Settings::Options& options) load.makeDir(); myDefaultLoadDir = load.getShortPath(); + // Get updated paths for all configuration files + setConfigPaths(); + +#ifdef SQLITE_SUPPORT + mySettingsDb = make_shared(myBaseDir, "settings"); + if (!mySettingsDb->initialize()) mySettingsDb.reset(); +#endif + mySettings->setRepository(createSettingsRepository()); logMessage("Loading config options ...", 2); mySettings->load(options); + + myPropSet->load(myPropertiesFile); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -751,7 +758,9 @@ void OSystem::mainLoop() shared_ptr OSystem::createSettingsRepository() { #ifdef SQLITE_SUPPORT - return make_shared(myBaseDir, "settings"); + return mySettingsDb + ? shared_ptr(mySettingsDb, &mySettingsDb->settingsRepository()) + : make_shared(); #else if (myConfigFile.empty()) return make_shared(); diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 0f288c453..67faf245e 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -52,6 +52,10 @@ class AudioSettings; #include "bspf.hxx" #include "repository/KeyValueRepository.hxx" +#ifdef SQLITE_SUPPORT +#include "SettingsDb.hxx" +#endif + /** This class provides an interface for accessing operating system specific functions. It also comprises an overall parent object, to which all the @@ -538,6 +542,10 @@ class OSystem static string ourOverrideBaseDir; static bool ourOverrideBaseDirWithApp; + #ifdef SQLITE_SUPPORT + shared_ptr mySettingsDb; + #endif + private: /** Creates the various framebuffers/renderers available in this system. diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 6a8f1da91..328b917cd 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -23,12 +23,6 @@ #include "Props.hxx" #include "PropsSet.hxx" -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -PropertiesSet::PropertiesSet(const string& propsfile) -{ - load(propsfile); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PropertiesSet::load(const string& filename) { diff --git a/src/emucore/PropsSet.hxx b/src/emucore/PropsSet.hxx index 4d5f2ee37..8ed95ec59 100644 --- a/src/emucore/PropsSet.hxx +++ b/src/emucore/PropsSet.hxx @@ -40,11 +40,10 @@ class PropertiesSet { public: /** - Create a properties set object from the specified properties file. + Trivial constructor. */ - explicit PropertiesSet(const string& propsfile); + PropertiesSet() = default; - public: /** Load properties from the specified file, and create an internal searchable list. @@ -119,7 +118,6 @@ class PropertiesSet private: // Following constructors and assignment operators not supported - PropertiesSet() = delete; PropertiesSet(const PropertiesSet&) = delete; PropertiesSet(PropertiesSet&&) = delete; PropertiesSet& operator=(const PropertiesSet&) = delete;