From 6a4c73ba7f82165ebd2b6f236360804d51b49045 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 9 Aug 2018 17:16:34 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20Use=20executable=20for=20install?= =?UTF-8?q?ation=20instead=20of=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/findReleasePath.ts | 2 +- src/ssn/getPatch.ts | 13 +++++++------ src/ssn/patcher-installer/launch.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/ssn/patcher-installer/launch.ts diff --git a/src/ssn/findReleasePath.ts b/src/ssn/findReleasePath.ts index a0801ed..d435244 100644 --- a/src/ssn/findReleasePath.ts +++ b/src/ssn/findReleasePath.ts @@ -1,5 +1,5 @@ import { Product } from '../interfaces/ISettings'; -import verifyProductName from '../ssn/verify/verifyProductName'; +import verifyProductName from './verify/verifyProductName'; /** For the given release in the given product, returns from which releases we can patch to this release. */ function getFromList({ product, to: releaseTo}: {product: Product, to: number}) { diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index dc818e0..3cf84c0 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -7,6 +7,7 @@ import { Product } from '../interfaces/ISettings'; import { SsnDiffType } from '../interfaces/ISsnFileEntry'; import extractFileAsStream from './extractFileAsStream'; import getSolidpkg from './getSolidpkg'; +import launch from './patcher-installer/launch'; import readSsnFile from './reader/readSsnFile'; import getFileFromDisks from './streams/getFileFromDisks'; import verifyPatch from './verify/verifyPatch'; @@ -83,15 +84,15 @@ export default async function getPatch({ product, from, to, sourceDirectory, tar //Extract newly added files fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { try { - //extract file - const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, length: file.compressedSize }); - const fileContents = await extractFileAsStream(file, fileStream); - - //write to disk + //create file write stream const outputName = path.join(targetDir, file.name); await createDirRecursively(path.dirname(outputName)); const outputStream = fs.createWriteStream(outputName); - fileContents.pipe(outputStream); + + //start installation + await launch(diskFilenames[file.diskNumberStart], file.offset, file.compressedSize, file.decryptionKeys, outputStream); + + outputStream.close(); } catch (error) { console.error(`Could not extract file "${file.name}"`, error); } diff --git a/src/ssn/patcher-installer/launch.ts b/src/ssn/patcher-installer/launch.ts new file mode 100644 index 0000000..7eee7d0 --- /dev/null +++ b/src/ssn/patcher-installer/launch.ts @@ -0,0 +1,26 @@ +import * as childProcess from 'child_process'; +import * as fs from 'fs'; +import * as path from 'path'; + +const processPath = path.join(__dirname, '../../lib/patcher-installer'); + +export default function launchProcess(diskFile: string, offset: number, compressedSize: number, decryptionKeys: [number, number, number] | undefined, outputStream: fs.WriteStream) { + return new Promise((resolve, reject) => { + const parameters = [ + diskFile, + offset, + compressedSize, + ]; + if (decryptionKeys !== undefined) { + parameters.push(...decryptionKeys); + } + const spawnedProcess = childProcess.spawn(processPath, parameters.map((value) => value.toString(), { cwd: '.' })); + + spawnedProcess.stdout.pipe(outputStream); + //spawnedProcess.stdout.on('data', console.log); + spawnedProcess.stdout.on('end', resolve); + + spawnedProcess.stderr.setEncoding('utf8'); + spawnedProcess.stderr.on('data', reject); + }); +}