mirror of https://github.com/stella-emu/stella.git
Save settings immediatelly on sqlite and macos.
This commit is contained in:
parent
017c2a7c16
commit
0e6e54f15c
|
@ -32,6 +32,8 @@ class KeyValueRepository
|
|||
virtual std::map<string, Variant> load() = 0;
|
||||
|
||||
virtual void save(const std::map<string, Variant>& values) = 0;
|
||||
|
||||
virtual void save(const string& key, const Variant& value) = 0;
|
||||
};
|
||||
|
||||
#endif // KEY_VALUE_REPOSITORY_HXX
|
||||
|
|
|
@ -26,9 +26,11 @@ class KeyValueRepositoryConfigfile : public KeyValueRepository
|
|||
|
||||
KeyValueRepositoryConfigfile(const string& filename);
|
||||
|
||||
virtual std::map<string, Variant> load();
|
||||
std::map<string, Variant> load() override;
|
||||
|
||||
virtual void save(const std::map<string, Variant>& values);
|
||||
void save(const std::map<string, Variant>& values) override;
|
||||
|
||||
void save(const string& key, const Variant& value) override {}
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ class KeyValueRepositoryNoop : public KeyValueRepository
|
|||
{
|
||||
public:
|
||||
|
||||
virtual std::map<string, Variant> load() {
|
||||
virtual std::map<string, Variant> load() override {
|
||||
return std::map<string, Variant>();
|
||||
}
|
||||
|
||||
virtual void save(const std::map<string, Variant>& values) {}
|
||||
void save(const std::map<string, Variant>& values) override {}
|
||||
|
||||
void save(const string& key, const Variant& value) override {}
|
||||
};
|
||||
|
||||
#endif // KEY_VALUE_REPOSITORY_NOOP_HXX
|
||||
|
|
|
@ -70,6 +70,24 @@ void KeyValueRepositorySqlite::save(const std::map<string, Variant>& values)
|
|||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void KeyValueRepositorySqlite::save(const string& key, const Variant& value)
|
||||
{
|
||||
try {
|
||||
myStmtInsert->reset();
|
||||
|
||||
(*myStmtInsert)
|
||||
.bind(1, key.c_str())
|
||||
.bind(2, value.toCString())
|
||||
.step();
|
||||
|
||||
myStmtInsert->reset();
|
||||
}
|
||||
catch (SqliteError err) {
|
||||
cout << err.message << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void KeyValueRepositorySqlite::initialize()
|
||||
{
|
||||
|
|
|
@ -29,9 +29,11 @@ class KeyValueRepositorySqlite : public KeyValueRepository
|
|||
|
||||
KeyValueRepositorySqlite(SqliteDatabase& db, const string& tableName);
|
||||
|
||||
virtual std::map<string, Variant> load();
|
||||
std::map<string, Variant> load() override;
|
||||
|
||||
virtual void save(const std::map<string, Variant>& values);
|
||||
void save(const std::map<string, Variant>& values) override;
|
||||
|
||||
void save(const string& key, const Variant& value) override;
|
||||
|
||||
void initialize();
|
||||
|
||||
|
|
|
@ -593,8 +593,10 @@ const Variant& Settings::value(const string& key) const
|
|||
void Settings::setValue(const string& key, const Variant& value)
|
||||
{
|
||||
auto it = myPermanentSettings.find(key);
|
||||
if(it != myPermanentSettings.end())
|
||||
if(it != myPermanentSettings.end()) {
|
||||
it->second = value;
|
||||
myRespository->save(key, value);
|
||||
}
|
||||
else
|
||||
myTemporarySettings[key] = value;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
class SettingsRepositoryMACOS : public KeyValueRepository
|
||||
{
|
||||
public:
|
||||
virtual std::map<string, Variant> load();
|
||||
std::map<string, Variant> load() override;
|
||||
|
||||
virtual void save(const std::map<string, Variant>& values);
|
||||
void save(const std::map<string, Variant>& values) override;
|
||||
|
||||
void save(const string& key, const Variant& value) override;
|
||||
};
|
||||
|
||||
#endif // SETTINGS_REPOSITORY_MACOS_HXX
|
||||
|
|
|
@ -51,3 +51,14 @@ void SettingsRepositoryMACOS::save(const std::map<string, Variant>& values)
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SettingsRepositoryMACOS::save(const string& key, const Variant& value)
|
||||
{
|
||||
@autoreleasepool {
|
||||
[[NSUserDefaults standardUserDefaults]
|
||||
setObject:[NSString stringWithUTF8String:value.toCString()]
|
||||
forKey:[NSString stringWithUTF8String:key.c_str()]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue