From e566b5960cbda26e7cabd3c68a03c1f5abb50c05 Mon Sep 17 00:00:00 2001 From: Franck Alary Date: Fri, 13 Sep 2024 10:07:14 +0200 Subject: [PATCH] Export story to zip file --- .../MainEvents/Processes/Studio/StudioZip.js | 20 +++++---- public/MainEvents/Studio.js | 42 +++++++++---------- src/Locales/en.js | 6 ++- src/Locales/fr.js | 4 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/public/MainEvents/Processes/Studio/StudioZip.js b/public/MainEvents/Processes/Studio/StudioZip.js index fe0aa62..bb93dee 100644 --- a/public/MainEvents/Processes/Studio/StudioZip.js +++ b/public/MainEvents/Processes/Studio/StudioZip.js @@ -1,21 +1,25 @@ import {getProcessParams} from '../Helpers/ProcessParams.js' -import {pack} from "../BinFiles/7zipCommands.js"; +import {pack} from '../BinFiles/7zipCommands.js' function main(filepath, storyPath) { - pack(storyPath, filepath, (e) => { - if(e) { - process.stderr.write(e.toString()) - } else { - process.stdout.write('success') + pack( + storyPath, + filepath, + (e) => { + if (e) { + process.stderr.write(e.toString()) + } else { + process.stdout.write('success') + } } - }) + ) } const _params_ = getProcessParams() if (_params_.length !== 2) { - process.stderr.write('zip-bad-args') + process.stderr.write('zip-error') } else { main(_params_.shift(), _params_.shift()) } diff --git a/public/MainEvents/Studio.js b/public/MainEvents/Studio.js index c0bfa15..d356400 100644 --- a/public/MainEvents/Studio.js +++ b/public/MainEvents/Studio.js @@ -5,7 +5,7 @@ import {getExtraResourcesPath, getStoriesPath, initTmpPath} from './Helpers/AppP import runProcess from './Processes/RunProcess.js' import {readStoryMetadata} from './Helpers/StoriesFiles.js' import {generateDirNameStory, getMetadataStory} from './Helpers/Stories.js' -import {stringNormalizeFileName} from "./Helpers/Strings.js"; +import {stringNormalizeFileName} from './Helpers/Strings.js' function mainEventStudio(mainWindow) { const @@ -154,38 +154,38 @@ function mainEventStudio(mainWindow) { ipcMain.on( 'studio-story-zip', async (event, storyData) => { - const { canceled, filePath } = await dialog.showSaveDialog(mainWindow, { - filters: [{name: "zip", extensions: ['zip']}], - defaultPath: `${stringNormalizeFileName(storyData.metadata.title).substring(0, 32)}.zip` + mainWindow.webContents.send('studio-story-zip-task', 'story-export', 'waiting-file-path', 1, 100) + + const {canceled, filePath} = await dialog.showSaveDialog(mainWindow, { + filters: [{name: 'zip', extensions: ['zip']}], + defaultPath: `${storyData.metadata.age || 0}+] ${stringNormalizeFileName(storyData.metadata.title).substring(0, 32)}.zip` }) - mainWindow.webContents.send('studio-story-zip-task', 'story-zipping', '', 50, 100) - if(canceled) { + + if (canceled) { mainWindow.webContents.send('studio-story-zip-task', '', '', 0, 0) return } - const storiesDir = getStoriesPath() - const storyDirectory = generateDirNameStory( - storyData.metadata.title, - storyData.metadata.uuid, - storyData.metadata.age, - storyData.metadata.category + + mainWindow.webContents.send('studio-story-zip-task', 'story-export', 'story-zipping', 50, 100) + + const storyPath = getStoriesPath( + generateDirNameStory( + storyData.metadata.title, + storyData.metadata.uuid, + storyData.metadata.age, + storyData.metadata.category + ) ) - const storyPath = path.join(storiesDir, storyDirectory, "*") if (fs.existsSync(filePath)) { fs.rmSync(filePath) } runProcess( path.join('Studio', 'StudioZip.js'), - [filePath , storyPath], - () => { - mainWindow.webContents.send('studio-story-zip-task', '', '', 0, 0) - }, - (message, current, total) => { - mainWindow.webContents.send('studio-story-zip-task', 'story-zipping', message, current, total) - }, + [filePath, storyPath], + () => {}, + (message, current, total) => {}, (error) => { mainWindow.webContents.send('studio-story-zip-error', 'error', error) - mainWindow.webContents.send('studio-story-zip-task', '', '', 0, 0) }, () => { mainWindow.webContents.send('studio-story-zip-task', '', '', 0, 0) diff --git a/src/Locales/en.js b/src/Locales/en.js index bfe9d03..d2c79df 100644 --- a/src/Locales/en.js +++ b/src/Locales/en.js @@ -66,7 +66,7 @@ const en = { 'transfer-files': 'Transfer the files', 'transferring-files': 'Transferring the files', 'no-file': 'No file found', - 'zip-bad-args': 'Error while generating zip', + 'zip-error': 'Error while generating zip', 'drop-files': 'Drop you file', 'drag-drop-medias': 'To import your stories or music, drag and drop them here.', 'error-occurred': 'An error has occurred!', @@ -105,6 +105,7 @@ const en = { 'do-nothing': 'Do nothing', 'put-telmi-picture': 'Put Telmi picture', 'restore-original-picture': 'Restore original picture', + 'waiting-file-path': 'Waiting for a file path', 'action-continue-to': 'Continue to :', 'action-scene-existing': 'Existing scene', @@ -150,7 +151,8 @@ const en = { 'story-display-tiles': 'Display nine story tiles by default', 'story-disable-night-mode': 'Disable night mode', 'story-saving': 'Saving story', - 'story-zipping': 'Exporting story in zip', + 'story-export': 'Exporting story', + 'story-zipping': 'Pack story in a zip file', 'stories': 'Stories', 'stories-local': 'My stories ({0})', 'stories-on-store': '{0} stories on the store', diff --git a/src/Locales/fr.js b/src/Locales/fr.js index dfdb4c5..77126a3 100644 --- a/src/Locales/fr.js +++ b/src/Locales/fr.js @@ -66,7 +66,7 @@ const fr = { 'transfer-files': 'Transferer les fichiers', 'transferring-files': 'Transfert des fichiers en cours', 'no-file': 'Aucun fichier trouvé', - 'zip-bad-args': 'Erreur lors de la génération du zip', + 'zip-error': 'Erreur lors de la génération du zip', 'drop-files': 'Déposez vos fichiers', 'drag-drop-medias': 'Pour importer vos histoires ou musiques, glissez/déposez les ici.', 'error-occurred': 'Une erreur est survenue !', @@ -105,6 +105,7 @@ const fr = { 'do-nothing': 'Ne rien faire', 'put-telmi-picture': 'Mettre l\'image de Telmi', 'restore-original-picture': 'Remettre l\'image originale', + 'waiting-file-path': 'En attente d\'un chemin de fichier', 'action-continue-to': 'Continuer vers :', 'action-scene-existing': 'Scène existante', @@ -150,6 +151,7 @@ const fr = { 'story-display-tiles': 'Affichage de la mosaïque 9 histoires par défaut', 'story-disable-night-mode': 'Désactiver le night mode', 'story-saving': 'Sauvegarde de l\'histoire', + 'story-export': 'Export de l\'histoire', 'story-zipping': 'Export de l\'histoire au format zip', 'stories': 'Histoires', 'stories-local': 'Mes histoires ({0})',