Commit 99d8becd authored by David Gonçalves's avatar David Gonçalves 📖

swf2exe

parent 47975bc3
"use strict";
// Access File System
//const fs = require("fs");
const path = require('path');
// Execute external program
const {
spawn
......@@ -7,6 +11,7 @@ const {
const translate = require('google-translate-api');
let target_dir = 'uploads/';
let game_dir = 'game/';
function engtochi() {
let eng = document.getElementById("storyname");
......@@ -20,9 +25,6 @@ function engtochi() {
function generateExe() {
if (!fs.existsSync(target_dir)){
fs.mkdirSync(target_dir);
}
......@@ -133,14 +135,14 @@ function generateExe() {
}
create_mod(target_filename);
});
//upload storylist
/*//upload storylist
fs.writeFile(target_file_story_list, storylistdata, err => {
if (err) {
dialog.err(window.lang.savename_error, window.lang.error);
return;
}
create_mod(target_filename);
});
});*/
}
function create_mod(filename) {
......@@ -213,8 +215,59 @@ function create_mod(filename) {
console.log(`stderr: ${data}`);
});
ffdec.on('close', (code) => {
ffdec.on('exit', (code) => {
console.log(`child process exited with code ${code}`);
swf2exe(`${__dirname}/${target_dir}${filename}.swf`, `${__dirname}/${target_dir}${filename}.exe`);
});
// compression is missing -> repalce.sh 25
}
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;
dialog.info("Success", "Success");// TODO Lang
});
});
});
});
});
});
}
function intToByteArray(int) {
// we want to represent the input as a 4-bytes array
var byteArray = [0, 0, 0, 0];
for ( var index = 0; index < byteArray.length; index ++ ) {
var byte = int & 0xff;
byteArray [ index ] = byte;
int = (int - byte) / 256 ;
}
return byteArray;
};
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