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 {
|
try {
|
||||||
YAML::Node node = loadYamlFromByteArray(data);
|
YAML::Node node = loadYamlFromByteArray(data);
|
||||||
node >> settings;
|
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) {
|
} catch (const std::runtime_error& e) {
|
||||||
qDebug() << "YAML::ParserException: " << e.what();
|
qDebug() << "YAML::ParserException: " << e.what();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
||||||
|
|
||||||
typedef std::pair<std::string, int> EtxModelfileCategoryPair;
|
typedef std::pair<std::string, int> EtxModelfileCategoryPair;
|
||||||
typedef std::list<EtxModelfileCategoryPair> EtxModelfiles;
|
typedef std::list<EtxModelfileCategoryPair> EtxModelfiles;
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "generalsettings.h"
|
#include "generalsettings.h"
|
||||||
#include "eeprominterface.h"
|
#include "eeprominterface.h"
|
||||||
|
#include "edgetxinterface.h"
|
||||||
|
|
||||||
extern const YamlLookupTable beeperModeLut;
|
extern const YamlLookupTable beeperModeLut;
|
||||||
extern const YamlLookupTable backlightModeLut;
|
extern const YamlLookupTable backlightModeLut;
|
||||||
@@ -42,7 +43,7 @@ namespace YAML {
|
|||||||
static YAML::Node encode(const GeneralSettings& rhs) {
|
static YAML::Node encode(const GeneralSettings& rhs) {
|
||||||
Node node;
|
Node node;
|
||||||
|
|
||||||
node["version"] = rhs.version;
|
node["version"] = CPN_CURRENT_SETTINGS_VERSION;
|
||||||
|
|
||||||
// Radio calib
|
// Radio calib
|
||||||
YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
YamlCalibData calib(rhs.calibMid, rhs.calibSpanNeg, rhs.calibSpanPos);
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
|
|||||||
errors.set(HAS_WARNINGS);
|
errors.set(HAS_WARNINGS);
|
||||||
}
|
}
|
||||||
else if (version_error == NOT_OPENTX) {
|
else if (version_error == NOT_OPENTX) {
|
||||||
dbg << " not open9x";
|
dbg << " not OpenTX";
|
||||||
errors.set(version_error);
|
errors.set(version_error);
|
||||||
return errors.to_ulong();
|
return errors.to_ulong();
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
|
|||||||
|
|
||||||
uint8_t OpenTxEepromInterface::getLastDataVersion(Board::Type board)
|
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)
|
void OpenTxEepromInterface::showErrors(const QString & title, const QStringList & errors)
|
||||||
|
|||||||
Reference in New Issue
Block a user