From 0926f64f3bf2ee004f650da8becfed36b4fef312 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 3 Mar 2017 13:35:24 +1300 Subject: [PATCH] Fixed backup / restore, unified file name generation. --- js/backup_restore.js | 24 +++++++++++++----------- main.js | 30 ++++++++++++++++++++++++++++++ tabs/onboard_logging.js | 28 ++++------------------------ 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/js/backup_restore.js b/js/backup_restore.js index 6ca21f38..3de8d816 100644 --- a/js/backup_restore.js +++ b/js/backup_restore.js @@ -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 { diff --git a/main.js b/main.js index 2e86bc10..82244cca 100644 --- a/main.js +++ b/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; +} + diff --git a/tabs/onboard_logging.js b/tabs/onboard_logging.js index 7a2dca15..1aa8a991 100644 --- a/tabs/onboard_logging.js +++ b/tabs/onboard_logging.js @@ -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) {