mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +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": {
|
||||
"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": {
|
||||
|
|
|
@ -225,7 +225,7 @@ function configuration_restore(callback) {
|
|||
console.log('Read SUCCESSFUL');
|
||||
|
||||
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) {
|
||||
// data provided != valid json object
|
||||
console.log('Data provided != valid JSON string, restore aborted.');
|
||||
|
@ -233,7 +233,23 @@ function configuration_restore(callback) {
|
|||
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) {
|
||||
var a = generated.split('.'),
|
||||
b = required.split('.');
|
||||
|
@ -268,6 +283,25 @@ function configuration_restore(callback) {
|
|||
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() {
|
||||
var activeProfile = null,
|
||||
profilesN = 3;
|
||||
|
@ -405,11 +439,6 @@ function configuration_restore(callback) {
|
|||
}
|
||||
}
|
||||
|
||||
// validate
|
||||
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