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); + }); +}