From cf43d3ed405e09b4060e05001586073a5d859f4b Mon Sep 17 00:00:00 2001 From: elecpower Date: Thu, 18 Nov 2021 07:12:40 +1100 Subject: [PATCH] Fix settings conversion --- companion/src/storage/appdata.cpp | 21 ++++++++++++++++----- companion/src/storage/appdata.h | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/companion/src/storage/appdata.cpp b/companion/src/storage/appdata.cpp index 805953306..cd5c129e4 100644 --- a/companion/src/storage/appdata.cpp +++ b/companion/src/storage/appdata.cpp @@ -412,7 +412,7 @@ void AppData::convertSettings(QSettings & settings) if (savedVer == CPN_SETTINGS_VERSION) return; if (savedVer > CPN_SETTINGS_VERSION) { - qWarning().noquote() << "Saved settings version is newer than current, skippig conversions. Saved:" << fmtHex(savedVer) << "Current:" << fmtHex(CPN_SETTINGS_VERSION); + qWarning().noquote() << "Saved settings version is newer than current, skipping conversions. Saved:" << fmtHex(savedVer) << "Current:" << fmtHex(CPN_SETTINGS_VERSION); return; } @@ -428,13 +428,21 @@ void AppData::convertSettings(QSettings & settings) // firmwares renamed from opentx-* to edgetx-* at 2.6 if (savedMajMin < 0x206) { + qInfo().noquote() << "Converting profiles"; static const QString profileFwTypePath = QStringLiteral("Profiles/profile%1/fwType"); for (int i = 0; i < MAX_PROFILES; i++) { if (settings.contains(profileFwTypePath.arg(i))) { const QVariant oldValue = settings.value(profileFwTypePath.arg(i)); if (oldValue.isValid()) { - QString val = settings.value(profileFwTypePath.arg(i)).toString(); - settings.setValue(profileFwTypePath.arg(i), val.replace("opentx-", "edgetx-")); + const QString oldval = settings.value(profileFwTypePath.arg(i)).toString(); + QString newval = oldval; + newval.replace("opentx-", "edgetx-"); + if (oldval != newval) { + settings.setValue(profileFwTypePath.arg(i), newval); + qInfo().noquote().nospace() << "Converted entry " << profileFwTypePath.arg(i) + << " from (" << oldval << ")" + << " to (" << newval << ")"; + } } } } @@ -485,7 +493,8 @@ bool AppData::findPreviousVersionSettings(QString * version) const bool AppData::importSettings(const QString & fromVersion) { - QString fromProduct; + QString fromProduct = PRODUCT_NO_VERS % " " % fromVersion; + //qDebug() << "From Product:" << fromProduct; upgradeFromVersion.clear(); upgradeFromVersion = fromVersion; @@ -501,8 +510,10 @@ bool AppData::importSettings(QSettings * fromSettings) // Create temporary settings because we may modify them before import. QSettings tempSettings(COMPANY, PRODUCT % "_import"); - for (const QString & key : fromSettings->allKeys()) + for (const QString & key : fromSettings->allKeys()) { tempSettings.setValue(key, fromSettings->value(key)); + //qInfo().noquote() << "Import key(" << key << ") value(" << fromSettings->value(key) << ")"; + } // convert settings first to simplify import process convertSettings(tempSettings); diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index f0ad887aa..3afa1dc77 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -47,6 +47,7 @@ #define COMPANY QStringLiteral("EdgeTX") #define COMPANY_DOMAIN QStringLiteral("edgetx.org") +#define PRODUCT_NO_VERS QStringLiteral("Companion") #define PRODUCT QStringLiteral("Companion " QT_STRINGIFY(VERSION_MAJOR) "." QT_STRINGIFY(VERSION_MINOR)) #define APP_COMPANION QStringLiteral("EdgeTX Companion") #define APP_SIMULATOR QStringLiteral("EdgeTX Simulator")