Merge pull request #460 from mikeller/fixed_backup_restore
Fixed backup / restore, unified file name generation.10.3.x-maintenance
commit
8adc26b350
|
@ -163,18 +163,13 @@ function configuration_backup(callback) {
|
|||
function save() {
|
||||
var chosenFileEntry = null;
|
||||
|
||||
var accepts = [{
|
||||
extensions: ['json']
|
||||
}];
|
||||
var prefix = 'betaflight_backup';
|
||||
var suffix = 'json';
|
||||
|
||||
// generate timestamp for the backup file
|
||||
var now = new Date().toISOString().split(".")[0];
|
||||
|
||||
// replace invalid filesystem characters
|
||||
now = now.replace(new RegExp(':', 'g'), '_');
|
||||
var filename = generateFilename(prefix, suffix);
|
||||
|
||||
// create or load the file
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'betaflight_backup_' + now + '.json', accepts: accepts}, function (fileEntry) {
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: [{ extensions: [suffix] }]}, function (fileEntry) {
|
||||
if (chrome.runtime.lastError) {
|
||||
console.error(chrome.runtime.lastError.message);
|
||||
return;
|
||||
|
@ -241,7 +236,7 @@ function configuration_restore(callback) {
|
|||
var chosenFileEntry = null;
|
||||
|
||||
var accepts = [{
|
||||
extensions: ['txt']
|
||||
extensions: ['json']
|
||||
}];
|
||||
|
||||
// load up the file
|
||||
|
@ -288,6 +283,7 @@ function configuration_restore(callback) {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
// validate
|
||||
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
||||
|
||||
|
@ -295,7 +291,13 @@ function configuration_restore(callback) {
|
|||
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (configuration.BF_CONFIG.features._featureMask) {
|
||||
var features = new Features(CONFIG);
|
||||
features.setMask(configuration.BF_CONFIG.features._featureMask);
|
||||
configuration.BF_CONFIG.features = features;
|
||||
}
|
||||
|
||||
configuration_upload(configuration, callback);
|
||||
|
||||
} else {
|
||||
|
|
30
main.js
30
main.js
|
@ -414,6 +414,7 @@ function bytesToSize(bytes) {
|
|||
function isExpertModeEnabled() {
|
||||
return $('input[name="expertModeCheckbox"]').is(':checked');
|
||||
}
|
||||
|
||||
function updateTabList(features) {
|
||||
if (features.isEnabled('GPS') && isExpertModeEnabled()) {
|
||||
$('#tabs ul.mode-connected li.tab_gps').show();
|
||||
|
@ -475,3 +476,32 @@ function updateTabList(features) {
|
|||
$('#tabs ul.mode-connected li.tab_osd').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function zeroPad(value, width) {
|
||||
value = "" + value;
|
||||
|
||||
while (value.length < width) {
|
||||
value = "0" + value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function generateFilename(prefix, suffix) {
|
||||
var date = new Date();
|
||||
var filename = prefix;
|
||||
|
||||
if (CONFIG && CONFIG.name && CONFIG.name.trim() !== '') {
|
||||
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');
|
||||
}
|
||||
|
||||
filename = filename + '_' + date.getFullYear()
|
||||
+ zeroPad(date.getMonth() + 1, 2)
|
||||
+ zeroPad(date.getDate(), 2)
|
||||
+ '_' + zeroPad(date.getHours(), 2)
|
||||
+ zeroPad(date.getMinutes(), 2)
|
||||
+ zeroPad(date.getSeconds(), 2);
|
||||
|
||||
return filename + '.' + suffix;
|
||||
}
|
||||
|
||||
|
|
|
@ -301,16 +301,6 @@ TABS.onboard_logging.initialize = function (callback) {
|
|||
}
|
||||
|
||||
// IO related methods
|
||||
function zeroPad(value, width) {
|
||||
value = "" + value;
|
||||
|
||||
while (value.length < width) {
|
||||
value = "0" + value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function flash_save_cancel() {
|
||||
saveCancelled = true;
|
||||
}
|
||||
|
@ -409,23 +399,13 @@ TABS.onboard_logging.initialize = function (callback) {
|
|||
}
|
||||
|
||||
function prepare_file(onComplete) {
|
||||
var date = new Date();
|
||||
var filename = 'BLACKBOX_LOG';
|
||||
var suffix = 'BFL';
|
||||
var prefix = 'BLACKBOX_LOG';
|
||||
|
||||
if (CONFIG.name && CONFIG.name.trim() !== '') {
|
||||
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');
|
||||
}
|
||||
var filename = generateFilename(prefix, suffix);
|
||||
|
||||
filename = filename + '_' + date.getFullYear()
|
||||
+ zeroPad(date.getMonth() + 1, 2)
|
||||
+ zeroPad(date.getDate(), 2)
|
||||
+ '_' + zeroPad(date.getHours(), 2)
|
||||
+ zeroPad(date.getMinutes(), 2)
|
||||
+ zeroPad(date.getSeconds(), 2)
|
||||
+ '.BFL';
|
||||
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
|
||||
accepts: [{extensions: ['BFL']}]}, function(fileEntry) {
|
||||
accepts: [{extensions: [suffix]}]}, function(fileEntry) {
|
||||
var error = chrome.runtime.lastError;
|
||||
|
||||
if (error) {
|
||||
|
|
Loading…
Reference in New Issue