From a59a6bd767b8c8dd39452d2959d1772e095b5b12 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 14 Sep 2018 05:14:14 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20patch=20verification=20to?= =?UTF-8?q?=20handle=20*=5Fversion.txt=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/patcher-installer/launch.ts | 2 +- src/ssn/verify/verifyPatch.ts | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ssn/patcher-installer/launch.ts b/src/ssn/patcher-installer/launch.ts index a509db6..0acab2f 100644 --- a/src/ssn/patcher-installer/launch.ts +++ b/src/ssn/patcher-installer/launch.ts @@ -22,7 +22,7 @@ export default function launchProcess( parameters.push('--keys', decryptionKeys.join(',')); } if (previousFile !== undefined) { - parameters.push(previousFile); + parameters.push('--previous', previousFile); } const spawnedProcess = childProcess.spawn(processPath, parameters.map((value) => value.toString(), { cwd: '.' })); diff --git a/src/ssn/verify/verifyPatch.ts b/src/ssn/verify/verifyPatch.ts index 181c729..8c10a22 100644 --- a/src/ssn/verify/verifyPatch.ts +++ b/src/ssn/verify/verifyPatch.ts @@ -6,17 +6,34 @@ import { SsnDiffType } from '../../interfaces/ISsnFileEntry'; export default function verifyPatch(fileEntries: ISsnFileEntry[], product: Product, from: number): void { //There must be at least a .version file if (fileEntries.length === 0) { - throw new Error('Expected at least a version file in the '); + throw new Error('Expected at least a *.version file in the .zip file'); } //Check that last file is the .version file with diffType 0. const lastFile = fileEntries[fileEntries.length - 1]; const validLastFileName = `${product}.version`; - if (lastFile.name !== validLastFileName) { - throw new Error(`Last file must be called "${validLastFileName}" but it was "${lastFile.name}".`); - } - if (lastFile.diffType !== SsnDiffType.NewFile) { - throw new Error(`Last file (.version file) must have diffType 0 but it had diffType ${lastFile.diffType}.`); + const validLastFileAlternate = `Assets/assets_${product}_version.txt`; + if (lastFile.name === validLastFileName) { + if (lastFile.diffType !== SsnDiffType.NewFile) { + throw new Error(`Last file (.version file) must have diffType 0 but it had diffType ${lastFile.diffType}.`); + } + } else if (lastFile.name === validLastFileAlternate) { + //In some early patches, the last file is *_version.txt and the second to last is *.version + if (fileEntries.length === 1) { + throw new Error('Expected at least a *.version file and a *_version.txt file in the .zip file'); + } + if (lastFile.name !== validLastFileAlternate) { + throw new Error(`Last file must be called "${validLastFileAlternate}" if it is not *.version but it was "${lastFile.name}".`); + } + const secondToLastFile = fileEntries[fileEntries.length - 2]; + if (secondToLastFile.name !== validLastFileName) { + throw new Error(`Last or second to last file must be called "${validLastFileName}" but it was "${secondToLastFile.name}".`); + } + if (secondToLastFile.diffType !== SsnDiffType.NewFile) { + throw new Error(`Second to last file (.version file) must have diffType 0 but it had diffType ${secondToLastFile.diffType}.`); + } + } else { + throw new Error(`Last file must be called "${validLastFileName}" or "${validLastFileAlternate}" but it was "${lastFile.name}".`); } //Patches from -1 must not have diff type NewFile