mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 17:25:13 +03:00
Improve settings migration and management (#5107)
* Settings can now be optionally removed during uninstall (didn't find how to translate) * Settings import from previous versions now optional * Hopefully cleaner implementation * This crashes (already on 2.2) * Translation * Remove broken settings import from companion9x * Fixes for MainWindow
This commit is contained in:
parent
96f1a16744
commit
b3e9d8d97d
4 changed files with 74 additions and 74 deletions
|
@ -71,6 +71,20 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
CustomDebug::setFilterRules();
|
CustomDebug::setFilterRules();
|
||||||
|
|
||||||
|
if (!g.hasCurrentSettings()) {
|
||||||
|
QString previousVersion;
|
||||||
|
if (g.findPreviousVersionSettings(&previousVersion)) {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText(QObject::tr("We have found existing settings for Companion version: %1.\nDo you want to import them?").arg(previousVersion));
|
||||||
|
msgBox.setIcon(QMessageBox::Information);
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||||
|
int ret = msgBox.exec();
|
||||||
|
|
||||||
|
if (ret == QMessageBox::Yes)
|
||||||
|
g.importSettings(previousVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
g.init();
|
g.init();
|
||||||
|
|
||||||
QStringList strl = QApplication::arguments();
|
QStringList strl = QApplication::arguments();
|
||||||
|
|
|
@ -538,12 +538,10 @@ void AppData::init()
|
||||||
qRegisterMetaTypeStreamOperators<SimulatorOptions>("SimulatorOptions");
|
qRegisterMetaTypeStreamOperators<SimulatorOptions>("SimulatorOptions");
|
||||||
|
|
||||||
firstUse = false;
|
firstUse = false;
|
||||||
upgradeFromVersion = "";
|
|
||||||
|
|
||||||
QSettings settings(COMPANY, PRODUCT);
|
QSettings settings(COMPANY, PRODUCT);
|
||||||
if (!settings.contains("settings_version")) {
|
if (!settings.contains("settings_version")) {
|
||||||
if (!importSettings(settings))
|
firstUse = true;
|
||||||
firstUse = true;
|
|
||||||
}
|
}
|
||||||
convertSettings(settings);
|
convertSettings(settings);
|
||||||
|
|
||||||
|
@ -652,14 +650,24 @@ void AppData::convertSettings(QSettings & settings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppData::importSettings(QSettings & toSettings)
|
bool AppData::hasCurrentSettings()
|
||||||
|
{
|
||||||
|
QSettings settings(COMPANY, PRODUCT);
|
||||||
|
if (!settings.contains("settings_version")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppData::findPreviousVersionSettings(QString * version)
|
||||||
{
|
{
|
||||||
QSettings * fromSettings = NULL;
|
QSettings * fromSettings = NULL;
|
||||||
|
*version = "";
|
||||||
|
|
||||||
QSettings settings21("OpenTX", "Companion 2.1");
|
QSettings settings21("OpenTX", "Companion 2.1");
|
||||||
if (settings21.contains("settings_version")) {
|
if (settings21.contains("settings_version")) {
|
||||||
fromSettings = &settings21;
|
fromSettings = &settings21;
|
||||||
upgradeFromVersion = "2.1";
|
*version = "2.1";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
settings21.clear();
|
settings21.clear();
|
||||||
|
@ -669,7 +677,7 @@ bool AppData::importSettings(QSettings & toSettings)
|
||||||
if (settings20.contains("settings_version")) {
|
if (settings20.contains("settings_version")) {
|
||||||
if (!fromSettings) {
|
if (!fromSettings) {
|
||||||
fromSettings = &settings20;
|
fromSettings = &settings20;
|
||||||
upgradeFromVersion = "2.0";
|
*version = "2.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -680,27 +688,47 @@ bool AppData::importSettings(QSettings & toSettings)
|
||||||
if (settings16.contains("settings_version")) {
|
if (settings16.contains("settings_version")) {
|
||||||
if (!fromSettings) {
|
if (!fromSettings) {
|
||||||
fromSettings = &settings16;
|
fromSettings = &settings16;
|
||||||
upgradeFromVersion = "1.x";
|
*version = "1.x";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
settings16.clear();
|
settings16.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings9x("companion9x", "companion9x");
|
|
||||||
if (settings9x.contains("default_mode")) {
|
|
||||||
if (!fromSettings) {
|
|
||||||
fromSettings = &settings9x;
|
|
||||||
upgradeFromVersion = "Companion9X";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
settings9x.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fromSettings)
|
if (!fromSettings)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppData::importSettings(QString fromVersion)
|
||||||
|
{
|
||||||
|
QSettings toSettings(COMPANY, PRODUCT);
|
||||||
|
|
||||||
|
QString fromCompany;
|
||||||
|
QString fromProduct;
|
||||||
|
|
||||||
|
upgradeFromVersion = "";
|
||||||
|
|
||||||
|
if (fromVersion == "2.1") {
|
||||||
|
fromCompany = "OpenTX";
|
||||||
|
fromProduct = "Companion 2.1";
|
||||||
|
}
|
||||||
|
else if (fromVersion == "2.0") {
|
||||||
|
fromCompany = "OpenTX";
|
||||||
|
fromProduct = "Companion 2.0";
|
||||||
|
}
|
||||||
|
else if (fromVersion == "1.x") {
|
||||||
|
fromCompany = "OpenTX";
|
||||||
|
fromProduct = "OpenTX Companion";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
upgradeFromVersion = fromVersion;
|
||||||
|
|
||||||
|
QSettings fromSettings(fromCompany, fromProduct);
|
||||||
|
|
||||||
// do not copy these settings
|
// do not copy these settings
|
||||||
QStringList excludeKeys = QStringList() << "compilation-server";
|
QStringList excludeKeys = QStringList() << "compilation-server";
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
@ -711,59 +739,11 @@ bool AppData::importSettings(QSettings & toSettings)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// import settings
|
// import settings
|
||||||
foreach (const QString & key, fromSettings->allKeys()) {
|
foreach (const QString & key, fromSettings.allKeys()) {
|
||||||
if (fromSettings->value(key).isValid() && !excludeKeys.contains(key)) {
|
if (fromSettings.value(key).isValid() && !excludeKeys.contains(key)) {
|
||||||
toSettings.setValue(key, fromSettings->value(key));
|
toSettings.setValue(key, fromSettings.value(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional adjustments for companion9x settings
|
|
||||||
if (fromSettings->applicationName() == "companion9x") {
|
|
||||||
// Store old values in new locations
|
|
||||||
autoCheckApp(toSettings.value("startup_check_companion9x", true).toBool());
|
|
||||||
toSettings.setValue("useWizard", toSettings.value("wizardEnable", true));
|
|
||||||
|
|
||||||
// Convert and store the firmware type
|
|
||||||
QString fwType = toSettings.value("firmware", "").toString();
|
|
||||||
fwType.replace("open9x", "opentx");
|
|
||||||
fwType.replace("x9da", "x9d");
|
|
||||||
|
|
||||||
profile[0].init( 0 );
|
|
||||||
profile[0].fwType( fwType );
|
|
||||||
// Move the Companion9x profile settings to profile0, the new default profile
|
|
||||||
profile[0].name( toSettings.value( "Name", "My Radio").toString());
|
|
||||||
profile[0].sdPath( toSettings.value( "sdPath", "" ).toString());
|
|
||||||
profile[0].splashFile( toSettings.value( "SplashFileName", "" ).toString());
|
|
||||||
profile[0].burnFirmware( toSettings.value( "burnFirmware", false ).toBool());
|
|
||||||
profile[0].renameFwFiles( toSettings.value( "rename_firmware_files", false ).toBool());
|
|
||||||
profile[0].channelOrder( toSettings.value( "default_channel_order", "0" ).toInt());
|
|
||||||
profile[0].defaultMode( toSettings.value( "default_mode", "1" ).toInt());
|
|
||||||
|
|
||||||
// Ensure that the default profile has a name
|
|
||||||
if ( profile[0].name().isEmpty() )
|
|
||||||
profile[0].name("My Radio");
|
|
||||||
|
|
||||||
// Delete obsolete settings fields from companion9x
|
|
||||||
toSettings.remove("ActiveProfile");
|
|
||||||
toSettings.remove("burnFirmware");
|
|
||||||
toSettings.remove("custom_id");
|
|
||||||
toSettings.remove("default_channel_order");
|
|
||||||
toSettings.remove("default_mode");
|
|
||||||
toSettings.remove("firmware");
|
|
||||||
toSettings.remove("lastFw");
|
|
||||||
toSettings.remove("modelEditTab");
|
|
||||||
toSettings.remove("Name");
|
|
||||||
toSettings.remove("patchImage");
|
|
||||||
toSettings.remove("rename_firmware_files");
|
|
||||||
toSettings.remove("sdPath");
|
|
||||||
toSettings.remove("SplashFileName");
|
|
||||||
toSettings.remove("startup_check_companion9x");
|
|
||||||
toSettings.remove("warningId");
|
|
||||||
toSettings.remove("wizardEnable");
|
|
||||||
|
|
||||||
// Select the new default profile as current profile
|
|
||||||
id( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -419,10 +419,12 @@ class AppData: protected CompStoreObj
|
||||||
QMap<int, QString> getActiveProfiles();
|
QMap<int, QString> getActiveProfiles();
|
||||||
inline bool isFirstUse() const { return firstUse; }
|
inline bool isFirstUse() const { return firstUse; }
|
||||||
inline QString previousVersion() const { return upgradeFromVersion; }
|
inline QString previousVersion() const { return upgradeFromVersion; }
|
||||||
|
bool hasCurrentSettings();
|
||||||
|
bool findPreviousVersionSettings(QString * version);
|
||||||
|
bool importSettings(QString fromVersion);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void convertSettings(QSettings & settings);
|
void convertSettings(QSettings & settings);
|
||||||
bool importSettings(QSettings & toSettings);
|
|
||||||
|
|
||||||
bool firstUse;
|
bool firstUse;
|
||||||
QString upgradeFromVersion;
|
QString upgradeFromVersion;
|
||||||
|
|
|
@ -77,13 +77,13 @@
|
||||||
!define MUI_FINISHPAGE_NOAUTOCLOSE
|
!define MUI_FINISHPAGE_NOAUTOCLOSE
|
||||||
!define MUI_FINISHPAGE_RUN
|
!define MUI_FINISHPAGE_RUN
|
||||||
!define MUI_FINISHPAGE_RUN_CHECKED
|
!define MUI_FINISHPAGE_RUN_CHECKED
|
||||||
!define MUI_FINISHPAGE_RUN_TEXT "Launch OpenTX Companion @VERSION_FAMILY@"
|
|
||||||
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
|
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
|
||||||
# !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
|
# !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
|
||||||
# !define MUI_FINISHPAGE_SHOWREADME $INSTDIR\readme.txt
|
# !define MUI_FINISHPAGE_SHOWREADME $INSTDIR\readme.txt
|
||||||
!insertmacro MUI_PAGE_FINISH
|
!insertmacro MUI_PAGE_FINISH
|
||||||
|
|
||||||
!insertmacro MUI_UNPAGE_CONFIRM
|
!insertmacro MUI_UNPAGE_CONFIRM
|
||||||
|
!insertmacro MUI_UNPAGE_COMPONENTS
|
||||||
!insertmacro MUI_UNPAGE_INSTFILES
|
!insertmacro MUI_UNPAGE_INSTFILES
|
||||||
|
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
;Installer Sections
|
;Installer Sections
|
||||||
|
|
||||||
Section "OpenTX Companion" SecDummy
|
Section "OpenTX Companion @VERSION_FAMILY@" SecDummy
|
||||||
|
|
||||||
Delete "$INSTDIR\opentx-*-simulator.dll"
|
Delete "$INSTDIR\opentx-*-simulator.dll"
|
||||||
Delete "$INSTDIR\lang\*.*"
|
Delete "$INSTDIR\lang\*.*"
|
||||||
|
@ -189,7 +189,9 @@ SectionEnd
|
||||||
;--------------------------------
|
;--------------------------------
|
||||||
;Uninstaller Section
|
;Uninstaller Section
|
||||||
|
|
||||||
Section "Uninstall"
|
Section "un.OpenTX Companion @VERSION_FAMILY@"
|
||||||
|
|
||||||
|
SectionIn RO ; Not deselectable
|
||||||
|
|
||||||
;ADD YOUR OWN FILES HERE...
|
;ADD YOUR OWN FILES HERE...
|
||||||
|
|
||||||
|
@ -243,9 +245,11 @@ Section "Uninstall"
|
||||||
Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall Companion @VERSION_FAMILY@.lnk"
|
Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall Companion @VERSION_FAMILY@.lnk"
|
||||||
RMDir "$SMPROGRAMS\$StartMenuFolder"
|
RMDir "$SMPROGRAMS\$StartMenuFolder"
|
||||||
|
|
||||||
DeleteRegKey /ifempty HKCU "Software\OpenTX Companion @VERSION_FAMILY@"
|
|
||||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenTX Companion @VERSION_FAMILY@"
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenTX Companion @VERSION_FAMILY@"
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
Section /o "un.Settings"
|
||||||
|
DeleteRegKey HKCU "Software\OpenTX\Companion @VERSION_FAMILY@"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Function LaunchLink
|
Function LaunchLink
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue