From d8b4f8594d5e22c2d2ab3451cd0b467603364270 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Tue, 28 Feb 2017 11:48:52 -0500 Subject: [PATCH] [Companion] Smarter app settings import from old versions... (#4485) * [Companion] Smarter app settings import from old versions; Do not import flash tool locations on Windows which are already included with Companion (closes #4330). * [Companion] Exclude Windows installation-specific keys when importing settings from previous versions (truly fixes #2645). --- companion/src/storage/appdata.cpp | 214 +++++++++++++----------------- companion/src/storage/appdata.h | 4 + 2 files changed, 96 insertions(+), 122 deletions(-) diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index 10a1a5e8a..0c9ae6dfe 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -547,134 +547,18 @@ void AppData::init() { qRegisterMetaTypeStreamOperators("SimulatorOptions"); - //Initialize the profiles + QSettings settings(COMPANY, PRODUCT); + if (!settings.contains("settings_version")) + importSettings(settings); + + // Initialize the profiles for (int i=0; i AppData::getActiveProfiles() } return active; } + +bool AppData::importSettings(QSettings & toSettings) +{ + QSettings * fromSettings; + + QSettings settings21("OpenTX", "Companion 2.1"); + QSettings settings20("OpenTX", "Companion 2.0"); + QSettings settings16("OpenTX", "OpenTX Companion"); + QSettings settings9x("companion9x", "companion9x"); + + if (settings21.contains("settings_version")) + fromSettings = &settings21; + else if (settings20.contains("settings_version")) + fromSettings = &settings20; + else if (settings16.contains("settings_version")) + fromSettings = &settings16; + else if (settings9x.contains("default_mode")) + fromSettings = &settings9x; + else + return false; + + // do not copy these settings + QStringList excludeKeys = QStringList() << "compilation-server"; +#ifdef WIN32 + // locations of tools which come with Companion distros + excludeKeys << "avrdude_location" << "avrdudeLocation" << "dfu_location"; + // install-specific keys; "." is the "default" key which may contain install path + excludeKeys << "Start Menu Folder" << "."; +#endif + + // import settings + foreach (const QString & key, fromSettings->allKeys()) { + if (fromSettings->value(key).isValid() && !excludeKeys.contains(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()); + useWizard(toSettings.value("wizardEnable", true).toBool()); + + // 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("wizardEnable"); + + // Select the new default profile as current profile + id( 0 ); + } + + return true; +} diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index ba0a1781d..f7d3d0cd4 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -414,6 +414,10 @@ class AppData: protected CompStoreObj void init(); QMap getActiveProfiles(); + + protected: + bool importSettings(QSettings & toSettings); + }; extern AppData g;