🐛 Fix patch verification to handle *_version.txt case

This commit is contained in:
C-3PO 2018-09-14 05:14:14 +02:00
parent 34cccd0d04
commit a59a6bd767
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
2 changed files with 24 additions and 7 deletions

View file

@ -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: '.' }));

View file

@ -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