1
0
Fork 0
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:
Dominic Clifton 2015-01-07 15:41:34 +00:00
parent 92dad92b60
commit 0285723fab
2 changed files with 76 additions and 33 deletions

View file

@ -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": {

View file

@ -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,7 +257,6 @@ 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('.');
@ -268,6 +283,25 @@ function configuration_restore(callback) {
return true; 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
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
upload(); upload();
} else {
GUI.log(chrome.i18n.getMessage('backupFileIncompatible'));
}
} }
} }