Skip to content

Commit

Permalink
Export story to zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
DantSu committed Sep 13, 2024
1 parent 0e74049 commit e566b59
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
20 changes: 12 additions & 8 deletions public/MainEvents/Processes/Studio/StudioZip.js
Original file line number Diff line number Diff line change
@@ -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())
}
42 changes: 21 additions & 21 deletions public/MainEvents/Studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/Locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion src/Locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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})',
Expand Down

0 comments on commit e566b59

Please sign in to comment.