🐛 Fix patchmanifest verification

This commit is contained in:
C-3PO 2018-07-08 21:23:01 +02:00
parent 625b2af601
commit 5574da3189
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -146,48 +146,52 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
if (ExtraData.type !== 'element' || ExtraData.name !== 'ExtraData' || ExtraData.attributes !== undefined) { if (ExtraData.type !== 'element' || ExtraData.name !== 'ExtraData' || ExtraData.attributes !== undefined) {
throw new Error(`Expected ExtraData element in patch ${fromNum}to${toNum}.`); 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}.`); 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) { if (!isPatchWithoutExtraData) {
//<ExtraDataItem> const ExtraDataItems = ExtraData.elements as xmlJs.Element[];
const ExtraDataItem = ExtraData.elements[j]; for (let j = 0, jl = ExtraDataItems.length; j < jl; j += 1) {
if (ExtraDataItem.type !== 'element' || ExtraDataItem.name !== 'ExtraDataItem' || ExtraDataItem.attributes !== undefined || ExtraDataItem.elements === undefined || ExtraDataItem.elements.length !== 2) { //<ExtraDataItem>
throw new Error('Expected ExtraDataItem element.'); const ExtraDataItem = ExtraDataItems[j];
} if (ExtraDataItem.type !== 'element' || ExtraDataItem.name !== 'ExtraDataItem' || ExtraDataItem.attributes !== undefined || ExtraDataItem.elements === undefined || ExtraDataItem.elements.length !== 2) {
//<Key>MetafileUrl</Key> throw new Error('Expected ExtraDataItem element.');
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') { //<Key>MetafileUrl</Key>
throw new Error('Expected Key element.'); 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') {
const keyName = String(Key.elements[0].text); throw new Error('Expected Key element.');
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.`); const keyName = String(Key.elements[0].text);
} if (!['SSN_VERSION', 'MetafileUrl', 'ConfigurationUrl'].includes(keyName)) {
//<Value>http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg</Value> throw new Error(`Expected valid Key in patch ${fromNum}to${toNum} but "${keyName}" is not a valid key.`);
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') { //<Value>http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg</Value>
throw new Error('Expected Value element.'); 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') {
//TODO: parse Key and Value throw new Error('Expected Value element.');
const valueName = String(Value.elements[0].text); }
switch (keyName) { //TODO: parse Key and Value
case 'SSN_VERSION': const valueName = String(Value.elements[0].text);
if (!valueName.match(/^[0-9](\.[0-9])+$/)) { switch (keyName) {
throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`); case 'SSN_VERSION':
} if (!valueName.match(/^[0-9](\.[0-9])+$/)) {
break; throw new Error(`Expected valid Value for Key "SSN_VERSION" in patch ${fromNum}to${toNum} but it was "${valueName}".`);
case 'MetafileUrl': }
if (valueName !== `http://cdn-patch.swtor.com/patch/${product}/${product}_${fromNum}to${toNum}.solidpkg`) { break;
throw new Error(`Expected valid Value for Key "MetafileUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); case 'MetafileUrl':
} if (valueName !== `http://cdn-patch.swtor.com/patch/${product}/${product}_${fromNum}to${toNum}.solidpkg`) {
break; throw new Error(`Expected valid Value for Key "MetafileUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`);
case 'ConfigurationUrl': }
if (valueName !== '{AppContentUrl}download.solidconfig') { break;
throw new Error(`Expected valid Value for Key "ConfigurationUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`); case 'ConfigurationUrl':
} if (valueName !== '{AppContentUrl}download.solidconfig') {
break; throw new Error(`Expected valid Value for Key "ConfigurationUrl" in patch ${fromNum}to${toNum} but it was "${valueName}".`);
default: //do nothing }
break;
default: //do nothing
}
} }
} }
} }