mirror of https://github.com/stella-emu/stella.git
Add settings migration on MacOS.
This commit is contained in:
parent
606f027dcb
commit
e4ede14ae5
|
@ -29,6 +29,10 @@
|
||||||
#include "SqliteStatement.hxx"
|
#include "SqliteStatement.hxx"
|
||||||
#include "FSNode.hxx"
|
#include "FSNode.hxx"
|
||||||
|
|
||||||
|
#ifdef BSPF_MACOS
|
||||||
|
#include "SettingsRepositoryMACOS.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr Int32 CURRENT_VERSION = 1;
|
constexpr Int32 CURRENT_VERSION = 1;
|
||||||
|
|
||||||
|
@ -87,22 +91,13 @@ const string StellaDb::databaseFileName() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void StellaDb::initializeDb() const
|
void StellaDb::initializeDb()
|
||||||
{
|
{
|
||||||
FilesystemNode legacyConfigFile{myDatabaseDirectory};
|
importOldSettings();
|
||||||
legacyConfigFile /= LEGACY_SETTINGS_FILE;
|
|
||||||
|
|
||||||
FilesystemNode legacyConfigDatabase{myDatabaseDirectory};
|
|
||||||
legacyConfigDatabase /= "settings.sqlite3";
|
|
||||||
|
|
||||||
FilesystemNode legacyPropertyFile{myDatabaseDirectory};
|
FilesystemNode legacyPropertyFile{myDatabaseDirectory};
|
||||||
legacyPropertyFile /= "stella.pro";
|
legacyPropertyFile /= "stella.pro";
|
||||||
|
|
||||||
if (legacyConfigDatabase.exists() && legacyConfigDatabase.isFile())
|
|
||||||
importOldStellaDb(legacyConfigDatabase);
|
|
||||||
else if (legacyConfigFile.exists() && legacyConfigFile.isFile())
|
|
||||||
importStellarc(legacyConfigFile);
|
|
||||||
|
|
||||||
if (legacyPropertyFile.exists() && legacyPropertyFile.isFile())
|
if (legacyPropertyFile.exists() && legacyPropertyFile.isFile())
|
||||||
importOldPropset(legacyPropertyFile);
|
importOldPropset(legacyPropertyFile);
|
||||||
|
|
||||||
|
@ -110,15 +105,37 @@ void StellaDb::initializeDb() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void StellaDb::importStellarc(const FilesystemNode& node) const
|
void StellaDb::importOldSettings()
|
||||||
{
|
{
|
||||||
Logger::info("importing old settings from " + node.getPath());
|
#ifdef BSPF_MACOS
|
||||||
|
Logger::info("importing old settings");
|
||||||
|
|
||||||
|
mySettingsRepository->save(SettingsRepositoryMACOS().load());
|
||||||
|
#else
|
||||||
|
FilesystemNode legacyConfigFile{myDatabaseDirectory};
|
||||||
|
legacyConfigFile /= LEGACY_SETTINGS_FILE;
|
||||||
|
|
||||||
mySettingsRepository->save(KeyValueRepositoryConfigfile(node).load());
|
FilesystemNode legacyConfigDatabase{myDatabaseDirectory};
|
||||||
|
legacyConfigDatabase /= "settings.sqlite3";
|
||||||
|
|
||||||
|
if (legacyConfigDatabase.exists() && legacyConfigDatabase.isFile())
|
||||||
|
importOldStellaDb(legacyConfigDatabase);
|
||||||
|
else if (legacyConfigFile.exists() && legacyConfigFile.isFile())
|
||||||
|
importStellarc(legacyConfigFile);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void StellaDb::importOldStellaDb(const FilesystemNode& node) const {
|
void StellaDb::importStellarc(const FilesystemNode& node)
|
||||||
|
{
|
||||||
|
Logger::info("importing old settings from " + node.getPath());
|
||||||
|
|
||||||
|
mySettingsRepository->save(KeyValueRepositoryConfigfile(node).load());
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void StellaDb::importOldStellaDb(const FilesystemNode& node)
|
||||||
|
{
|
||||||
Logger::info("importing old settings from " + node.getPath());
|
Logger::info("importing old settings from " + node.getPath());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -138,7 +155,7 @@ void StellaDb::importOldStellaDb(const FilesystemNode& node) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void StellaDb::importOldPropset(const FilesystemNode& node) const
|
void StellaDb::importOldPropset(const FilesystemNode& node)
|
||||||
{
|
{
|
||||||
Logger::info("importing old game properties from " + node.getPath());
|
Logger::info("importing old game properties from " + node.getPath());
|
||||||
|
|
||||||
|
@ -169,7 +186,7 @@ void StellaDb::importOldPropset(const FilesystemNode& node) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void StellaDb::migrate() const
|
void StellaDb::migrate()
|
||||||
{
|
{
|
||||||
Int32 version = myDb->getUserVersion();
|
Int32 version = myDb->getUserVersion();
|
||||||
switch (version) {
|
switch (version) {
|
||||||
|
|
|
@ -40,12 +40,13 @@ class StellaDb
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initializeDb() const;
|
void initializeDb();
|
||||||
void importStellarc(const FilesystemNode& node) const;
|
void importOldSettings();
|
||||||
void importOldStellaDb(const FilesystemNode& node) const;
|
void importStellarc(const FilesystemNode& node);
|
||||||
void importOldPropset(const FilesystemNode& node) const;
|
void importOldStellaDb(const FilesystemNode& node);
|
||||||
|
void importOldPropset(const FilesystemNode& node);
|
||||||
|
|
||||||
void migrate() const;
|
void migrate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
//============================================================================
|
||||||
|
//
|
||||||
|
// 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-2020 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_REPOSITORY_MACOS_HXX
|
||||||
|
#define SETTINGS_REPOSITORY_MACOS_HXX
|
||||||
|
|
||||||
|
#include "repository/KeyValueRepository.hxx"
|
||||||
|
|
||||||
|
class SettingsRepositoryMACOS : public KeyValueRepository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::map<string, Variant> load() override;
|
||||||
|
|
||||||
|
bool save(const std::map<string, Variant>& values) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SETTINGS_REPOSITORY_MACOS_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-2020 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.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#include "SettingsRepositoryMACOS.hxx"
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
std::map<string, Variant> SettingsRepositoryMACOS::load()
|
||||||
|
{
|
||||||
|
std::map<string, Variant> values;
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
NSString* bundleId = [[NSBundle mainBundle] bundleIdentifier];
|
||||||
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
NSArray* keys = [[defaults persistentDomainForName:bundleId] allKeys];
|
||||||
|
|
||||||
|
for (NSString* key in keys) {
|
||||||
|
NSString* value = [defaults stringForKey:key];
|
||||||
|
if (value != nil)
|
||||||
|
values[[key UTF8String]] = string([value UTF8String]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
bool SettingsRepositoryMACOS::save(const std::map<string, Variant>& values)
|
||||||
|
{
|
||||||
|
@autoreleasepool {
|
||||||
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
|
for (const auto& [key, value]: values)
|
||||||
|
[defaults
|
||||||
|
setObject:[NSString stringWithUTF8String:value.toCString()]
|
||||||
|
forKey:[NSString stringWithUTF8String:key.c_str()]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -741,6 +741,8 @@
|
||||||
E0A3841E2589741A0062AA93 /* SqliteTransaction.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0A3840C2589741A0062AA93 /* SqliteTransaction.hxx */; };
|
E0A3841E2589741A0062AA93 /* SqliteTransaction.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0A3840C2589741A0062AA93 /* SqliteTransaction.hxx */; };
|
||||||
E0A755782244294600101889 /* CartCDFInfoWidget.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0A755762244294600101889 /* CartCDFInfoWidget.hxx */; };
|
E0A755782244294600101889 /* CartCDFInfoWidget.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0A755762244294600101889 /* CartCDFInfoWidget.hxx */; };
|
||||||
E0A755792244294600101889 /* CartCDFInfoWidget.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0A755772244294600101889 /* CartCDFInfoWidget.cxx */; };
|
E0A755792244294600101889 /* CartCDFInfoWidget.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0A755772244294600101889 /* CartCDFInfoWidget.cxx */; };
|
||||||
|
E0D4153C25A120340031A8D6 /* SettingsRepositoryMACOS.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0D4153A25A120340031A8D6 /* SettingsRepositoryMACOS.hxx */; };
|
||||||
|
E0D4153D25A120340031A8D6 /* SettingsRepositoryMACOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E0D4153B25A120340031A8D6 /* SettingsRepositoryMACOS.mm */; };
|
||||||
E0DCD3A720A64E96000B614E /* LanczosResampler.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0DCD3A320A64E95000B614E /* LanczosResampler.hxx */; };
|
E0DCD3A720A64E96000B614E /* LanczosResampler.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0DCD3A320A64E95000B614E /* LanczosResampler.hxx */; };
|
||||||
E0DCD3A820A64E96000B614E /* LanczosResampler.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0DCD3A420A64E95000B614E /* LanczosResampler.cxx */; };
|
E0DCD3A820A64E96000B614E /* LanczosResampler.cxx in Sources */ = {isa = PBXBuildFile; fileRef = E0DCD3A420A64E95000B614E /* LanczosResampler.cxx */; };
|
||||||
E0DCD3A920A64E96000B614E /* ConvolutionBuffer.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0DCD3A520A64E96000B614E /* ConvolutionBuffer.hxx */; };
|
E0DCD3A920A64E96000B614E /* ConvolutionBuffer.hxx in Headers */ = {isa = PBXBuildFile; fileRef = E0DCD3A520A64E96000B614E /* ConvolutionBuffer.hxx */; };
|
||||||
|
@ -1544,6 +1546,8 @@
|
||||||
E0A3840C2589741A0062AA93 /* SqliteTransaction.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SqliteTransaction.hxx; sourceTree = "<group>"; };
|
E0A3840C2589741A0062AA93 /* SqliteTransaction.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SqliteTransaction.hxx; sourceTree = "<group>"; };
|
||||||
E0A755762244294600101889 /* CartCDFInfoWidget.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartCDFInfoWidget.hxx; sourceTree = "<group>"; };
|
E0A755762244294600101889 /* CartCDFInfoWidget.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CartCDFInfoWidget.hxx; sourceTree = "<group>"; };
|
||||||
E0A755772244294600101889 /* CartCDFInfoWidget.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CartCDFInfoWidget.cxx; sourceTree = "<group>"; };
|
E0A755772244294600101889 /* CartCDFInfoWidget.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CartCDFInfoWidget.cxx; sourceTree = "<group>"; };
|
||||||
|
E0D4153A25A120340031A8D6 /* SettingsRepositoryMACOS.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SettingsRepositoryMACOS.hxx; sourceTree = "<group>"; };
|
||||||
|
E0D4153B25A120340031A8D6 /* SettingsRepositoryMACOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SettingsRepositoryMACOS.mm; sourceTree = "<group>"; };
|
||||||
E0DCD3A320A64E95000B614E /* LanczosResampler.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = LanczosResampler.hxx; path = audio/LanczosResampler.hxx; sourceTree = "<group>"; };
|
E0DCD3A320A64E95000B614E /* LanczosResampler.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = LanczosResampler.hxx; path = audio/LanczosResampler.hxx; sourceTree = "<group>"; };
|
||||||
E0DCD3A420A64E95000B614E /* LanczosResampler.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LanczosResampler.cxx; path = audio/LanczosResampler.cxx; sourceTree = "<group>"; };
|
E0DCD3A420A64E95000B614E /* LanczosResampler.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LanczosResampler.cxx; path = audio/LanczosResampler.cxx; sourceTree = "<group>"; };
|
||||||
E0DCD3A520A64E96000B614E /* ConvolutionBuffer.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ConvolutionBuffer.hxx; path = audio/ConvolutionBuffer.hxx; sourceTree = "<group>"; };
|
E0DCD3A520A64E96000B614E /* ConvolutionBuffer.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ConvolutionBuffer.hxx; path = audio/ConvolutionBuffer.hxx; sourceTree = "<group>"; };
|
||||||
|
@ -1918,6 +1922,8 @@
|
||||||
2D6050C60898771C00C6DE89 /* macos */ = {
|
2D6050C60898771C00C6DE89 /* macos */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E0D4153A25A120340031A8D6 /* SettingsRepositoryMACOS.hxx */,
|
||||||
|
E0D4153B25A120340031A8D6 /* SettingsRepositoryMACOS.mm */,
|
||||||
DC21E5B921CA903E007D0E1A /* OSystemMACOS.cxx */,
|
DC21E5B921CA903E007D0E1A /* OSystemMACOS.cxx */,
|
||||||
DC21E5BA21CA903E007D0E1A /* OSystemMACOS.hxx */,
|
DC21E5BA21CA903E007D0E1A /* OSystemMACOS.hxx */,
|
||||||
DC21E5BB21CA903E007D0E1A /* SerialPortMACOS.cxx */,
|
DC21E5BB21CA903E007D0E1A /* SerialPortMACOS.cxx */,
|
||||||
|
@ -2807,6 +2813,7 @@
|
||||||
DCC527D310B9DA19005E1287 /* M6502.hxx in Headers */,
|
DCC527D310B9DA19005E1287 /* M6502.hxx in Headers */,
|
||||||
DC3EE8661E2C0E6D00905161 /* inflate.h in Headers */,
|
DC3EE8661E2C0E6D00905161 /* inflate.h in Headers */,
|
||||||
DC21E5C221CA903E007D0E1A /* SerialPortMACOS.hxx in Headers */,
|
DC21E5C221CA903E007D0E1A /* SerialPortMACOS.hxx in Headers */,
|
||||||
|
E0D4153C25A120340031A8D6 /* SettingsRepositoryMACOS.hxx in Headers */,
|
||||||
DCC527D510B9DA19005E1287 /* NullDev.hxx in Headers */,
|
DCC527D510B9DA19005E1287 /* NullDev.hxx in Headers */,
|
||||||
DCC527D710B9DA19005E1287 /* System.hxx in Headers */,
|
DCC527D710B9DA19005E1287 /* System.hxx in Headers */,
|
||||||
CFE3F6161E84A9CE00A8204E /* CartCDF.hxx in Headers */,
|
CFE3F6161E84A9CE00A8204E /* CartCDF.hxx in Headers */,
|
||||||
|
@ -3380,6 +3387,7 @@
|
||||||
DCAACB12188D636F00A4D282 /* CartBFWidget.cxx in Sources */,
|
DCAACB12188D636F00A4D282 /* CartBFWidget.cxx in Sources */,
|
||||||
DCAACB14188D636F00A4D282 /* CartDFSCWidget.cxx in Sources */,
|
DCAACB14188D636F00A4D282 /* CartDFSCWidget.cxx in Sources */,
|
||||||
DCAACB16188D636F00A4D282 /* CartDFWidget.cxx in Sources */,
|
DCAACB16188D636F00A4D282 /* CartDFWidget.cxx in Sources */,
|
||||||
|
E0D4153D25A120340031A8D6 /* SettingsRepositoryMACOS.mm in Sources */,
|
||||||
DC368F5818A2FB710084199C /* SoundSDL2.cxx in Sources */,
|
DC368F5818A2FB710084199C /* SoundSDL2.cxx in Sources */,
|
||||||
DCFF14CD18B0260300A20364 /* EventHandlerSDL2.cxx in Sources */,
|
DCFF14CD18B0260300A20364 /* EventHandlerSDL2.cxx in Sources */,
|
||||||
DC3EE8561E2C0E6D00905161 /* adler32.c in Sources */,
|
DC3EE8561E2C0E6D00905161 /* adler32.c in Sources */,
|
||||||
|
|
Loading…
Reference in New Issue