🐛 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) {
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) {
//<ExtraDataItem>
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.');
}
//<Key>MetafileUrl</Key>
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.`);
}
//<Value>http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg</Value>
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) {
//<ExtraDataItem>
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.');
}
//<Key>MetafileUrl</Key>
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.`);
}
//<Value>http://cdn-patch.swtor.com/patch/assets_swtor_de_de/assets_swtor_de_de_289to285.solidpkg</Value>
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
}
}
}
}