11import fs from "fs" ;
22import path from "path" ;
33import { dialog } from "electron" ;
4+ import { formatDateTime } from "@/utils/date.js" ;
5+ import { flightLogFilename } from "./ipc.js" ;
46
57export function exportFlightLogToCSVs ( flightLog ) {
68 let flightLogSections = [ "imu" , "baro" , "flightInfo" , "orientationInfo" , "filteredDataInfo" , "gnssInfo" , "flightStates" , "eventInfo" , "voltageInfo" ] ;
@@ -13,11 +15,10 @@ export function exportFlightLogToCSVs(flightLog) {
1315 return ;
1416 }
1517
16- const exportFolderPath = path . join ( paths [ 0 ] ) ;
18+ const userFolderPath = path . join ( paths [ 0 ] ) ;
19+ const exportFolderPath = `${ userFolderPath } /${ flightLogFilename } _export_${ formatDateTime ( new Date ( ) ) } ` ;
1720
18- if ( ! fs . existsSync ( exportFolderPath ) ) {
19- fs . mkdirSync ( exportFolderPath ) ;
20- }
21+ fs . mkdirSync ( `${ exportFolderPath } ` ) ;
2122
2223 for ( let flightLogSection of flightLogSections ) {
2324 fs . writeFile ( `${ exportFolderPath } /${ flightLogSection } .csv` , objectArrayToCSV ( flightLogSection , flightLog [ flightLogSection ] ) , "utf8" , function ( err ) {
@@ -41,10 +42,6 @@ export function exportFlightLogChartsToHTML(flightLogChartsHTML) {
4142
4243 const exportFolderPath = path . join ( paths [ 0 ] ) ;
4344
44- if ( ! fs . existsSync ( exportFolderPath ) ) {
45- fs . mkdirSync ( exportFolderPath ) ;
46- }
47-
4845 const flightLogHtmlDocument = `
4946 <!DOCTYPE html>
5047 <html>
@@ -57,7 +54,7 @@ export function exportFlightLogChartsToHTML(flightLogChartsHTML) {
5754 </html>
5855 ` ;
5956
60- fs . writeFile ( `${ exportFolderPath } /plots .html` , flightLogHtmlDocument , 'utf8' , function ( err ) {
57+ fs . writeFile ( `${ exportFolderPath } /${ flightLogFilename } _plots_ ${ formatDateTime ( new Date ( ) ) } .html` , flightLogHtmlDocument , 'utf8' , function ( err ) {
6158 if ( err ) {
6259 console . log ( "An error occurred while writing HTML Object to File." ) ;
6360 return console . log ( err ) ;
0 commit comments