mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
First cut of working configuration migration.
This commit is contained in:
parent
92dad92b60
commit
0285723fab
2 changed files with 76 additions and 33 deletions
|
@ -39,7 +39,21 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"backupFileIncompatible": {
|
"backupFileIncompatible": {
|
||||||
"message": "Backup file provided was generated for older version of configurator and is incompatible with this version of configurator. Sorry"
|
"message": "Backup file provided was generated for previous version of the configurator and is incompatible with this version of configurator. Sorry"
|
||||||
|
},
|
||||||
|
|
||||||
|
"backupFileUnmigratable": {
|
||||||
|
"message": "Backup file provided was generated by a previous version of the configurator and is not migratable. Sorry."
|
||||||
|
},
|
||||||
|
|
||||||
|
"configMigrationFrom": {
|
||||||
|
"message": "Migrating configuration file generated by configurator: $1"
|
||||||
|
},
|
||||||
|
"configMigratedTo": {
|
||||||
|
"message": "Migrated configuration to configurator: $1"
|
||||||
|
},
|
||||||
|
"configMigrationSuccessful": {
|
||||||
|
"message": "Configuration migration complete, migrations applied: $1"
|
||||||
},
|
},
|
||||||
|
|
||||||
"tabSetup": {
|
"tabSetup": {
|
||||||
|
|
|
@ -225,7 +225,7 @@ function configuration_restore(callback) {
|
||||||
console.log('Read SUCCESSFUL');
|
console.log('Read SUCCESSFUL');
|
||||||
|
|
||||||
try { // check if string provided is a valid JSON
|
try { // check if string provided is a valid JSON
|
||||||
var deserialized_configuration_object = JSON.parse(e.target.result);
|
var configuration = JSON.parse(e.target.result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// data provided != valid json object
|
// data provided != valid json object
|
||||||
console.log('Data provided != valid JSON string, restore aborted.');
|
console.log('Data provided != valid JSON string, restore aborted.');
|
||||||
|
@ -233,7 +233,23 @@ function configuration_restore(callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration_upload(deserialized_configuration_object, callback);
|
// validate
|
||||||
|
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
||||||
|
|
||||||
|
if (configuration.generatedBy != chrome.runtime.getManifest().version) {
|
||||||
|
if (!migrate(configuration)) {
|
||||||
|
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration_upload(configuration, callback);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
GUI.log(chrome.i18n.getMessage('backupFileIncompatible'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -241,33 +257,51 @@ function configuration_restore(callback) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function configuration_upload(configuration, callback) {
|
function compareVersions(generated, required) {
|
||||||
function compareVersions(generated, required) {
|
var a = generated.split('.'),
|
||||||
var a = generated.split('.'),
|
b = required.split('.');
|
||||||
b = required.split('.');
|
|
||||||
|
|
||||||
for (var i = 0; i < a.length; ++i) {
|
for (var i = 0; i < a.length; ++i) {
|
||||||
a[i] = Number(a[i]);
|
a[i] = Number(a[i]);
|
||||||
}
|
}
|
||||||
for (var i = 0; i < b.length; ++i) {
|
for (var i = 0; i < b.length; ++i) {
|
||||||
b[i] = Number(b[i]);
|
b[i] = Number(b[i]);
|
||||||
}
|
}
|
||||||
if (a.length == 2) {
|
if (a.length == 2) {
|
||||||
a[2] = 0;
|
a[2] = 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (a[0] > b[0]) return true;
|
|
||||||
if (a[0] < b[0]) return false;
|
|
||||||
|
|
||||||
if (a[1] > b[1]) return true;
|
|
||||||
if (a[1] < b[1]) return false;
|
|
||||||
|
|
||||||
if (a[2] > b[2]) return true;
|
|
||||||
if (a[2] < b[2]) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a[0] > b[0]) return true;
|
||||||
|
if (a[0] < b[0]) return false;
|
||||||
|
|
||||||
|
if (a[1] > b[1]) return true;
|
||||||
|
if (a[1] < b[1]) return false;
|
||||||
|
|
||||||
|
if (a[2] > b[2]) return true;
|
||||||
|
if (a[2] < b[2]) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function migrate(configuration) {
|
||||||
|
var appliedMigrationsCount = 0;
|
||||||
|
var migratedVersion = configuration.generatedBy;
|
||||||
|
GUI.log(chrome.i18n.getMessage('configMigrationFrom', [migratedVersion]));
|
||||||
|
|
||||||
|
if (!compareVersions(migratedVersion, '0.59.1')) {
|
||||||
|
|
||||||
|
configuration.MISC.rssi_channel = configuration.MISC.rssi_aux_channel; // variable was renamed
|
||||||
|
configuration.MISC.rssi_aux_channel = undefined;
|
||||||
|
|
||||||
|
migratedVersion = '0.59.1';
|
||||||
|
GUI.log(chrome.i18n.getMessage('configMigratedTo', [migratedVersion]));
|
||||||
|
appliedMigrationsCount++;
|
||||||
|
}
|
||||||
|
GUI.log(chrome.i18n.getMessage('configMigrationSuccessful', [appliedMigrationsCount]));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function configuration_upload(configuration, callback) {
|
||||||
function upload() {
|
function upload() {
|
||||||
var activeProfile = null,
|
var activeProfile = null,
|
||||||
profilesN = 3;
|
profilesN = 3;
|
||||||
|
@ -405,11 +439,6 @@ function configuration_restore(callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
upload();
|
||||||
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
|
||||||
upload();
|
|
||||||
} else {
|
|
||||||
GUI.log(chrome.i18n.getMessage('backupFileIncompatible'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue