From 5574da31895af7a9d854c882ae3772914e2fe7b9 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 21:23:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20patchmanifest=20verificati?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/verify/verifyPatchmanifest.ts | 84 ++++++++++++++------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/ssn/verify/verifyPatchmanifest.ts b/src/ssn/verify/verifyPatchmanifest.ts index 8ef98a0..56485a8 100644 --- a/src/ssn/verify/verifyPatchmanifest.ts +++ b/src/ssn/verify/verifyPatchmanifest.ts @@ -146,48 +146,52 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product if (ExtraData.type !== 'element' || ExtraData.name !== 'ExtraData' || ExtraData.attributes !== undefined) { throw new Error(`Expected ExtraData element in patch ${fromNum}to${toNum}.`); } - if (ExtraData.elements === undefined || (product === 'assets_swtor_fr_fr' && fromNum === '132' && toNum === '130')) { + const isPatchWithoutExtraData = product === 'assets_swtor_fr_fr' && fromNum === '132' && toNum === '130'; + if (ExtraData.elements === undefined && !isPatchWithoutExtraData) { throw new Error(`Expected ExtraData element with children in patch ${fromNum}to${toNum}.`); } - for (let j = 0, jl = ExtraData.elements.length; j < jl; j += 1) { - // - const ExtraDataItem = ExtraData.elements[j]; - if (ExtraDataItem.type !== 'element' || ExtraDataItem.name !== 'ExtraDataItem' || ExtraDataItem.attributes !== undefined || ExtraDataItem.elements === undefined || ExtraDataItem.elements.length !== 2) { - throw new Error('Expected ExtraDataItem element.'); - } - //MetafileUrl - const Key = ExtraDataItem.elements[0]; - if (Key.type !== 'element' || Key.name !== 'Key' || Key.attributes !== undefined || Key.elements === undefined || Key.elements.length !== 1 || Key.elements[0].type !== 'text') { - throw new Error('Expected Key element.'); - } - const keyName = String(Key.elements[0].text); - if (!['SSN_VERSION', 'MetafileUrl', 'ConfigurationUrl'].includes(keyName)) { - throw new Error(`Expected valid Key in patch ${fromNum}to${toNum} but "${keyName}" is not a valid key.`); - } - //http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg - const Value = ExtraDataItem.elements[1]; - if (Value.type !== 'element' || Value.name !== 'Value' || Value.attributes !== undefined || Value.elements === undefined || Value.elements.length !== 1 || Value.elements[0].type !== 'text') { - throw new Error('Expected Value element.'); - } - //TODO: parse Key and Value - const valueName = String(Value.elements[0].text); - switch (keyName) { - case 'SSN_VERSION': - if (!valueName.match(/^[0-9](\.[0-9])+$/)) { - throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`); - } - break; - case 'MetafileUrl': - if (valueName !== `http://cdn-patch.swtor.com/patch/${product}/${product}_${fromNum}to${toNum}.solidpkg`) { - throw new Error(`Expected valid Value for Key "MetafileUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); - } - break; - case 'ConfigurationUrl': - if (valueName !== '{AppContentUrl}download.solidconfig') { - throw new Error(`Expected valid Value for Key "ConfigurationUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); - } - break; - default: //do nothing + if (!isPatchWithoutExtraData) { + const ExtraDataItems = ExtraData.elements as xmlJs.Element[]; + for (let j = 0, jl = ExtraDataItems.length; j < jl; j += 1) { + // + const ExtraDataItem = ExtraDataItems[j]; + if (ExtraDataItem.type !== 'element' || ExtraDataItem.name !== 'ExtraDataItem' || ExtraDataItem.attributes !== undefined || ExtraDataItem.elements === undefined || ExtraDataItem.elements.length !== 2) { + throw new Error('Expected ExtraDataItem element.'); + } + //MetafileUrl + const Key = ExtraDataItem.elements[0]; + if (Key.type !== 'element' || Key.name !== 'Key' || Key.attributes !== undefined || Key.elements === undefined || Key.elements.length !== 1 || Key.elements[0].type !== 'text') { + throw new Error('Expected Key element.'); + } + const keyName = String(Key.elements[0].text); + if (!['SSN_VERSION', 'MetafileUrl', 'ConfigurationUrl'].includes(keyName)) { + throw new Error(`Expected valid Key in patch ${fromNum}to${toNum} but "${keyName}" is not a valid key.`); + } + //http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg + const Value = ExtraDataItem.elements[1]; + if (Value.type !== 'element' || Value.name !== 'Value' || Value.attributes !== undefined || Value.elements === undefined || Value.elements.length !== 1 || Value.elements[0].type !== 'text') { + throw new Error('Expected Value element.'); + } + //TODO: parse Key and Value + const valueName = String(Value.elements[0].text); + switch (keyName) { + case 'SSN_VERSION': + if (!valueName.match(/^[0-9](\.[0-9])+$/)) { + throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`); + } + break; + case 'MetafileUrl': + if (valueName !== `http://cdn-patch.swtor.com/patch/${product}/${product}_${fromNum}to${toNum}.solidpkg`) { + throw new Error(`Expected valid Value for Key "MetafileUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); + } + break; + case 'ConfigurationUrl': + if (valueName !== '{AppContentUrl}download.solidconfig') { + throw new Error(`Expected valid Value for Key "ConfigurationUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); + } + break; + default: //do nothing + } } } }