From 1b73d7530d6130835107d2035feeeb134704881d Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Sun, 24 Mar 2024 12:39:24 +1100 Subject: [PATCH] fixcpn): use model semver over radio semver for decoding model sources and switches (#4768) --- companion/src/firmwares/edgetx/yaml_modeldata.cpp | 14 +++++++++----- companion/src/firmwares/edgetx/yaml_rawsource.cpp | 6 +++--- companion/src/firmwares/edgetx/yaml_rawswitch.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index b7c1a3279..9514e1442 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -38,8 +38,7 @@ #include "helpers.h" #include - -SemanticVersion version; // used for data conversions +#include void YamlValidateLabelsNames(ModelData& model, Board::Type board) { @@ -867,7 +866,7 @@ struct convert { Node convert::encode(const ModelData& rhs) { - version = SemanticVersion(VERSION); + modelSettingsVersion = SemanticVersion(VERSION); Node node; auto board = getCurrentBoard(); @@ -1163,8 +1162,13 @@ bool convert::decode(const Node& node, ModelData& rhs) qDebug() << "Settings version:" << modelSettingsVersion.toString(); - if (modelSettingsVersion > SemanticVersion(VERSION)) - qDebug() << "Warning: version not supported by Companion!"; + if (modelSettingsVersion > SemanticVersion(VERSION)) { + QString prmpt = QCoreApplication::translate("YamlModelSettings", "Warning: Model 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(modelSettingsVersion.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; + } + } if (node["header"]) { const auto& header = node["header"]; diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index 1ff6d0a1e..35d596166 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -263,7 +263,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::string ana_str; node >> ana_str; - if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { + if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { ana_str = Boards::getLegacyAnalogMappedInputTag(ana_str.c_str()); int idx = Boards::getInputIndex(ana_str.c_str(), Board::LVT_TAG); if (idx >= 0 && Boards::isInputStick(idx)) @@ -280,7 +280,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::string trim_str; node >> trim_str; - if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { + if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { int idx = b.getLegacyTrimSourceIndex(src_str.c_str()); if (idx >= 0) trim_str = Boards::getTrimYamlName(idx, BoardJson::YLT_REF).toStdString(); @@ -296,7 +296,7 @@ RawSource YamlRawSourceDecode(const std::string& src_str) std::string special_str; node >> special_str; - if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { + if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { if (special_str.size() == 6 && special_str.substr(0, 5) == "TIMER") { special_str = "Tmr" + special_str.substr(5, 1); } diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index e42a26b18..d3b4cf507 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -119,7 +119,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) try { mp_input_index = std::stoi(sw_str_tmp.substr(2, val_len - 3)); - if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { + if (modelSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) { if (IS_HORUS_X10(board) || IS_FAMILY_T16(board)) { if (mp_input_index > 2) mp_input_index += 2;