Skip to content

Commit 8adc26b

Browse files
authored
Merge pull request #460 from mikeller/fixed_backup_restore
Fixed backup / restore, unified file name generation.
2 parents 954d33a + 0926f64 commit 8adc26b

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

js/backup_restore.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,13 @@ function configuration_backup(callback) {
163163
function save() {
164164
var chosenFileEntry = null;
165165

166-
var accepts = [{
167-
extensions: ['json']
168-
}];
166+
var prefix = 'betaflight_backup';
167+
var suffix = 'json';
169168

170-
// generate timestamp for the backup file
171-
var now = new Date().toISOString().split(".")[0];
172-
173-
// replace invalid filesystem characters
174-
now = now.replace(new RegExp(':', 'g'), '_');
169+
var filename = generateFilename(prefix, suffix);
175170

176171
// create or load the file
177-
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'betaflight_backup_' + now + '.json', accepts: accepts}, function (fileEntry) {
172+
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: [{ extensions: [suffix] }]}, function (fileEntry) {
178173
if (chrome.runtime.lastError) {
179174
console.error(chrome.runtime.lastError.message);
180175
return;
@@ -241,7 +236,7 @@ function configuration_restore(callback) {
241236
var chosenFileEntry = null;
242237

243238
var accepts = [{
244-
extensions: ['txt']
239+
extensions: ['json']
245240
}];
246241

247242
// load up the file
@@ -288,14 +283,21 @@ function configuration_restore(callback) {
288283
return;
289284
}
290285

286+
291287
// validate
292288
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
293289

294290
if (!migrate(configuration)) {
295291
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
296292
return;
297293
}
298-
294+
295+
if (configuration.BF_CONFIG.features._featureMask) {
296+
var features = new Features(CONFIG);
297+
features.setMask(configuration.BF_CONFIG.features._featureMask);
298+
configuration.BF_CONFIG.features = features;
299+
}
300+
299301
configuration_upload(configuration, callback);
300302

301303
} else {

main.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ function bytesToSize(bytes) {
414414
function isExpertModeEnabled() {
415415
return $('input[name="expertModeCheckbox"]').is(':checked');
416416
}
417+
417418
function updateTabList(features) {
418419
if (features.isEnabled('GPS') && isExpertModeEnabled()) {
419420
$('#tabs ul.mode-connected li.tab_gps').show();
@@ -475,3 +476,32 @@ function updateTabList(features) {
475476
$('#tabs ul.mode-connected li.tab_osd').hide();
476477
}
477478
}
479+
480+
function zeroPad(value, width) {
481+
value = "" + value;
482+
483+
while (value.length < width) {
484+
value = "0" + value;
485+
}
486+
487+
return value;
488+
}
489+
490+
function generateFilename(prefix, suffix) {
491+
var date = new Date();
492+
var filename = prefix;
493+
494+
if (CONFIG && CONFIG.name && CONFIG.name.trim() !== '') {
495+
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');
496+
}
497+
498+
filename = filename + '_' + date.getFullYear()
499+
+ zeroPad(date.getMonth() + 1, 2)
500+
+ zeroPad(date.getDate(), 2)
501+
+ '_' + zeroPad(date.getHours(), 2)
502+
+ zeroPad(date.getMinutes(), 2)
503+
+ zeroPad(date.getSeconds(), 2);
504+
505+
return filename + '.' + suffix;
506+
}
507+

tabs/onboard_logging.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,6 @@ TABS.onboard_logging.initialize = function (callback) {
301301
}
302302

303303
// IO related methods
304-
function zeroPad(value, width) {
305-
value = "" + value;
306-
307-
while (value.length < width) {
308-
value = "0" + value;
309-
}
310-
311-
return value;
312-
}
313-
314304
function flash_save_cancel() {
315305
saveCancelled = true;
316306
}
@@ -409,23 +399,13 @@ TABS.onboard_logging.initialize = function (callback) {
409399
}
410400

411401
function prepare_file(onComplete) {
412-
var date = new Date();
413-
var filename = 'BLACKBOX_LOG';
402+
var suffix = 'BFL';
403+
var prefix = 'BLACKBOX_LOG';
414404

415-
if (CONFIG.name && CONFIG.name.trim() !== '') {
416-
filename = filename + '_' + CONFIG.name.trim().replace(' ', '_');
417-
}
405+
var filename = generateFilename(prefix, suffix);
418406

419-
filename = filename + '_' + date.getFullYear()
420-
+ zeroPad(date.getMonth() + 1, 2)
421-
+ zeroPad(date.getDate(), 2)
422-
+ '_' + zeroPad(date.getHours(), 2)
423-
+ zeroPad(date.getMinutes(), 2)
424-
+ zeroPad(date.getSeconds(), 2)
425-
+ '.BFL';
426-
427407
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
428-
accepts: [{extensions: ['BFL']}]}, function(fileEntry) {
408+
accepts: [{extensions: [suffix]}]}, function(fileEntry) {
429409
var error = chrome.runtime.lastError;
430410

431411
if (error) {

0 commit comments

Comments
 (0)