mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-17 05:15:21 +03:00
Fixed backup / restore, unified file name generation.
This commit is contained in:
parent
954d33a8ef
commit
0926f64f3b
3 changed files with 47 additions and 35 deletions
|
@ -163,18 +163,13 @@ function configuration_backup(callback) {
|
||||||
function save() {
|
function save() {
|
||||||
var chosenFileEntry = null;
|
var chosenFileEntry = null;
|
||||||
|
|
||||||
var accepts = [{
|
var prefix = 'betaflight_backup';
|
||||||
extensions: ['json']
|
var suffix = 'json';
|
||||||
}];
|
|
||||||
|
|
||||||
// generate timestamp for the backup file
|
var filename = generateFilename(prefix, suffix);
|
||||||
var now = new Date().toISOString().split(".")[0];
|
|
||||||
|
|
||||||
// replace invalid filesystem characters
|
|
||||||
now = now.replace(new RegExp(':', 'g'), '_');
|
|
||||||
|
|
||||||
// create or load the file
|
// 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) {
|
if (chrome.runtime.lastError) {
|
||||||
console.error(chrome.runtime.lastError.message);
|
console.error(chrome.runtime.lastError.message);
|
||||||
return;
|
return;
|
||||||
|
@ -241,7 +236,7 @@ function configuration_restore(callback) {
|
||||||
var chosenFileEntry = null;
|
var chosenFileEntry = null;
|
||||||
|
|
||||||
var accepts = [{
|
var accepts = [{
|
||||||
extensions: ['txt']
|
extensions: ['json']
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// load up the file
|
// load up the file
|
||||||
|
@ -288,6 +283,7 @@ function configuration_restore(callback) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
if (typeof configuration.generatedBy !== 'undefined' && compareVersions(configuration.generatedBy, CONFIGURATOR.backupFileMinVersionAccepted)) {
|
||||||
|
|
||||||
|
@ -295,7 +291,13 @@ function configuration_restore(callback) {
|
||||||
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
GUI.log(chrome.i18n.getMessage('backupFileUnmigratable'));
|
||||||
return;
|
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);
|
configuration_upload(configuration, callback);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
30
main.js
30
main.js
|
@ -414,6 +414,7 @@ function bytesToSize(bytes) {
|
||||||
function isExpertModeEnabled() {
|
function isExpertModeEnabled() {
|
||||||
return $('input[name="expertModeCheckbox"]').is(':checked');
|
return $('input[name="expertModeCheckbox"]').is(':checked');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTabList(features) {
|
function updateTabList(features) {
|
||||||
if (features.isEnabled('GPS') && isExpertModeEnabled()) {
|
if (features.isEnabled('GPS') && isExpertModeEnabled()) {
|
||||||
$('#tabs ul.mode-connected li.tab_gps').show();
|
$('#tabs ul.mode-connected li.tab_gps').show();
|
||||||
|
@ -475,3 +476,32 @@ function updateTabList(features) {
|
||||||
$('#tabs ul.mode-connected li.tab_osd').hide();
|
$('#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
|
// IO related methods
|
||||||
function zeroPad(value, width) {
|
|
||||||
value = "" + value;
|
|
||||||
|
|
||||||
while (value.length < width) {
|
|
||||||
value = "0" + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function flash_save_cancel() {
|
function flash_save_cancel() {
|
||||||
saveCancelled = true;
|
saveCancelled = true;
|
||||||
}
|
}
|
||||||
|
@ -409,23 +399,13 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_file(onComplete) {
|
function prepare_file(onComplete) {
|
||||||
var date = new Date();
|
var suffix = 'BFL';
|
||||||
var filename = 'BLACKBOX_LOG';
|
var prefix = 'BLACKBOX_LOG';
|
||||||
|
|
||||||
if (CONFIG.name && CONFIG.name.trim() !== '') {
|
var filename = generateFilename(prefix, suffix);
|
||||||
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)
|
|
||||||
+ '.BFL';
|
|
||||||
|
|
||||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
|
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
|
||||||
accepts: [{extensions: ['BFL']}]}, function(fileEntry) {
|
accepts: [{extensions: [suffix]}]}, function(fileEntry) {
|
||||||
var error = chrome.runtime.lastError;
|
var error = chrome.runtime.lastError;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue