Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions js/backup_restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,7 +236,7 @@ function configuration_restore(callback) {
var chosenFileEntry = null;

var accepts = [{
extensions: ['txt']
extensions: ['json']
}];

// load up the file
Expand Down Expand Up @@ -288,14 +283,21 @@ function configuration_restore(callback) {
return;
}


// validate
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {

if (!migrate(configuration)) {
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 {
Expand Down
30 changes: 30 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

28 changes: 4 additions & 24 deletions tabs/onboard_logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down