diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 439f45aa351..ed46ed06084 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -28,9 +28,12 @@ #include "eeprominterface.h" #include "edgetxinterface.h" #include "version.h" +#include "helpers.h" #include +SemanticVersion radioSettingsVersion; + const YamlLookupTable beeperModeLut = { { GeneralSettings::BEEPER_QUIET, "mode_quiet" }, { GeneralSettings::BEEPER_ALARMS_ONLY, "mode_alarms" }, @@ -261,6 +264,7 @@ Node convert::encode(const GeneralSettings& rhs) node["switchConfig"] = switchConfig; } + // combine pots and sliders into potsConfig Node potsConfig; potsConfig = YamlPotConfig(rhs.potName, rhs.potConfig); if (potsConfig && potsConfig.IsMap()) { @@ -314,7 +318,29 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) // qDebug() << QString::fromStdString(n.first.Scalar()); // } - node["semver"] >> rhs.semver; + radioSettingsVersion = SemanticVersion(); + + if (node["semver"]) { + node["semver"] >> rhs.semver; + if (SemanticVersion().isValid(rhs.semver)) { + radioSettingsVersion = SemanticVersion(QString(rhs.semver)); + } + else { + qDebug() << "Invalid settings version:" << rhs.semver; + memset(rhs.semver, 0, sizeof(rhs.semver)); + } + } + + qDebug() << "Settings version:" << radioSettingsVersion.toString(); + + if (radioSettingsVersion > SemanticVersion(VERSION)) { + QString prmpt = QCoreApplication::translate("YamlGeneralSettings", "Warning: Radio settings file version %1 is not supported by this version of Companion!\n\nModel and radio settings may be corrupted if you continue.\n\nI acknowledge and accept the consequences."); + if (QMessageBox::warning(NULL, CPN_STR_APP_NAME, prmpt.arg(radioSettingsVersion.toString()), (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes) { + // TODO: this triggers an error in the calling code so we need a graceful way to handle + return false; + } + } + rhs.version = CPN_CURRENT_SETTINGS_VERSION; // depreciated in EdgeTX however data conversions use // Decoding uses profile firmare therefore all conversions are performed on the fly