Commit cde918d6 authored by David Gonçalves's avatar David Gonçalves 📖

improved a few things

parent b88ed9be
......@@ -5,9 +5,7 @@
const path = require('path');
// Execute external program
const {
spawn
} = require('child_process');
const { spawnSync } = require('child_process');
const translate = require('google-translate-api');
let xml_story_filename;
......@@ -142,121 +140,54 @@ function compileExe() {
let storylist_id = "234";
// Replace Story XML
let ffdec = spawn('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`, '-replace',
let ffdec = spawnSync('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`, '-replace',
`${__dirname}/game/hf.swf`, swf_filename, story_ids[story_number], xml_story_filename]);
ffdec.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ffdec.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
console.log(`stdout: ${ffdec.stdout}`);
console.log(`stderr: ${ffdec.stderr}`);
console.log(`exit: Child process exited with code ${ffdec.status}.`);
ffdec.on('exit', (code) => {
// Replace Story List XML
ffdec = spawnSync('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`, '-replace',
swf_filename, swf_filename, storylist_id, xml_storylist_filename]);
console.log(`Child process exited with code ${code}.`);
console.log(`stdout: ${ffdec.stdout}`);
console.log(`stderr: ${ffdec.stderr}`);
console.log(`exit: Child process exited with code ${ffdec.status}.`);
// Replace Story List XML
let ffdec2 = spawn('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`, '-replace',
swf_filename, swf_filename, storylist_id, xml_storylist_filename]);
// Compress SWF
ffdec = spawnSync('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`,
'-compress', 'zlib', swf_filename, swf_filename + "_compressed"]);
ffdec2.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ffdec2.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
console.log(`stdout: ${ffdec.stdout}`);
console.log(`stderr: ${ffdec.stderr}`);
console.log(`exit: Child process exited with code ${ffdec.status}.`);
ffdec2.on('exit', (code) => {
fs.unlinkSync(swf_filename);
console.log(`child process exited with code ${code}`);
// Compress SWF
let ffdec3 = spawn('java', ['-jar', `${__dirname}/ffdec/ffdec.jar`,
'-compress', 'zlib', swf_filename, swf_filename + "_compressed"]);
ffdec3.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ffdec3.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
swf_filename = swf_filename + "_compressed";
ffdec3.on('exit', (code) => {
swf2exe(swf_filename, exe_filename);
console.log(`child process exited with code ${code}`);
// Delete XML and SWF files
fs.unlinkSync(xml_story_filename);
fs.unlinkSync(xml_storylist_filename);
fs.unlinkSync(swf_filename);
dialog.info(window.lang.exe_success, window.lang.success);
fs.unlink(swf_filename, function(error) {
if (error) {
throw error;
}
});
swf_filename = swf_filename + "_compressed";
swf2exe(swf_filename, exe_filename);
});
});
});
}
function swf2exe(swfFile, outputFile) {
let projectorData = null;
let swfData = null;
let footer = [0x56, 0x34, 0x12, 0xFA];
fs.readFile("swf2exe/Lib/SA.exe", function (err, data) {
if (err) throw err;
projectorData = data;
fs.readFile(swfFile, function (err, data) {
if (err) throw err;
swfData = data;
fs.writeFile(outputFile, projectorData, function (err) {
if (err) throw err;
fs.appendFile(outputFile, swfData, function (err) {
if (err) throw err;
fs.appendFile(outputFile, Buffer.from( new Uint8Array(footer) ), function (err) {
if (err) throw err;
fs.appendFile(outputFile,
Buffer.from( new Uint8Array(intToByteArray(swfData.length))),
function (err)
{
if (err) throw err;
// Delete XML and SWF files
fs.unlink(xml_story_filename, function(error) {
if (error) {
throw error;
}
fs.unlink(xml_storylist_filename, function(error) {
if (error) {
throw error;
}
fs.unlink(swf_filename, function(error) {
if (error) {
throw error;
}
dialog.info(window.lang.exe_success, window.lang.success); // TODO - better message
});
});
});
});
});
});
});
});
});
let projectorData = fs.readFileSync(`${__dirname}/swf2exe/Lib/SA.exe`);
let swfData = fs.readFileSync(swfFile);
fs.writeFileSync(outputFile, projectorData);
fs.appendFileSync(outputFile, swfData);
fs.appendFileSync(outputFile, Buffer.from( new Uint8Array(footer) ));
fs.appendFileSync(outputFile, Buffer.from( new Uint8Array(intToByteArray(swfData.length))));
function intToByteArray(int) {
// we want to represent the input as a 4-bytes array
......
This diff is collapsed.
......@@ -23,7 +23,7 @@
},
"homepage": "https://gitlab.com/zlyfer/HF-Story-Editor#README",
"devDependencies": {
"electron": "^2.0.2",
"electron": "^2.0.8",
"jquery": "^3.3.1"
},
"dependencies": {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment