Add version checks and enforce current version on write
This commit is contained in:
committed by
Raphael Coeffic
parent
c6b23797a7
commit
112a606ed5
@@ -94,6 +94,14 @@ bool loadRadioSettingsFromYaml(GeneralSettings& settings, const QByteArray& data
|
||||
try {
|
||||
YAML::Node node = loadYamlFromByteArray(data);
|
||||
node >> settings;
|
||||
if (settings.version < CPN_CURRENT_SETTINGS_VERSION) {
|
||||
qDebug() << "Older version of settings detected:" << settings.version;
|
||||
}
|
||||
else if (settings.version > CPN_CURRENT_SETTINGS_VERSION) {
|
||||
qDebug() << "Newer version of settings detected:" << settings.version;
|
||||
QMessageBox::critical(NULL, CPN_STR_APP_NAME, QCoreApplication::translate("EdgeTXInterface", "Companion does not support settings version %1!").arg(settings.version));
|
||||
return false;
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
qDebug() << "YAML::ParserException: " << e.what();
|
||||
return false;
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
||||
|
||||
typedef std::pair<std::string, int> EtxModelfileCategoryPair;
|
||||
typedef std::list<EtxModelfileCategoryPair> EtxModelfiles;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "generalsettings.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "edgetxinterface.h"
|
||||
|
||||
extern const YamlLookupTable beeperModeLut;
|
||||
extern const YamlLookupTable backlightModeLut;
|
||||
@@ -41,8 +42,8 @@ namespace YAML {
|
||||
|
||||
static YAML::Node encode(const GeneralSettings& rhs) {
|
||||
Node node;
|
||||
|
||||
node["version"] = rhs.version;
|
||||
|
||||
node["version"] = CPN_CURRENT_SETTINGS_VERSION;
|
||||
|
||||
// Radio calib
|
||||
YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||
@@ -135,11 +136,11 @@ namespace YAML {
|
||||
static bool decode(const Node& node, GeneralSettings& rhs) {
|
||||
|
||||
if (!node.IsMap()) return false;
|
||||
|
||||
|
||||
// for (const auto& n : node) {
|
||||
// qDebug() << QString::fromStdString(n.first.Scalar());
|
||||
// }
|
||||
|
||||
|
||||
// TODO: check board string and fetch Board instance
|
||||
std::string board;
|
||||
node["board"] >> board;
|
||||
@@ -226,7 +227,7 @@ namespace YAML {
|
||||
YamlStickConfig stickConfig;
|
||||
node["sticksConfig"] >> stickConfig;
|
||||
stickConfig.copy(rhs.stickName);
|
||||
|
||||
|
||||
YamlSwitchConfig switchConfig;
|
||||
node["switchConfig"] >> switchConfig;
|
||||
switchConfig.copy(rhs.switchName, rhs.switchConfig);
|
||||
@@ -250,7 +251,7 @@ namespace YAML {
|
||||
|
||||
// OneBit sampling (X9D only?)
|
||||
node["uartSampleMode"] >> rhs.uartSampleMode;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -254,7 +254,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
|
||||
errors.set(HAS_WARNINGS);
|
||||
}
|
||||
else if (version_error == NOT_OPENTX) {
|
||||
dbg << " not open9x";
|
||||
dbg << " not OpenTX";
|
||||
errors.set(version_error);
|
||||
return errors.to_ulong();
|
||||
}
|
||||
@@ -286,7 +286,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
|
||||
|
||||
uint8_t OpenTxEepromInterface::getLastDataVersion(Board::Type board)
|
||||
{
|
||||
return 220;
|
||||
return 220; // Note: this is the last bin format before the switch to YAML introduced in Companion version 2.6
|
||||
}
|
||||
|
||||
void OpenTxEepromInterface::showErrors(const QString & title, const QStringList & errors)
|
||||
|
||||
Reference in New Issue
Block a user