✨ Improve manifest verification
This commit is contained in:
parent
7b027e9c69
commit
625b2af601
1 changed files with 37 additions and 6 deletions
|
@ -124,22 +124,30 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
}
|
||||
//<From>289</From>
|
||||
const From = ReleaseUpdatePath.elements[0];
|
||||
if (From.type !== 'element' || From.name !== 'From' || From.attributes !== undefined || From.elements === undefined || From.elements.length !== 1 || From.elements[0].type !== 'text' || typeof From.elements[0].text !== 'string' || String(From.elements[0].text).match(/^(-1|0|[1-9][0-9]*)$/) === null) {
|
||||
if (From.type !== 'element' || From.name !== 'From' || From.attributes !== undefined || From.elements === undefined || From.elements.length !== 1 || From.elements[0].type !== 'text' || typeof From.elements[0].text !== 'string') {
|
||||
throw new Error('Expected From element.');
|
||||
}
|
||||
const fromNum = From.elements[0].text;
|
||||
if (String(fromNum).match(/^(-1|0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error(`Expected From element to be a number but it was ${fromNum}.`);
|
||||
}
|
||||
//<To>285</To>
|
||||
const To = ReleaseUpdatePath.elements[1];
|
||||
if (To.type !== 'element' || To.name !== 'To' || To.attributes !== undefined || To.elements === undefined || To.elements.length !== 1 || To.elements[0].type !== 'text' || typeof To.elements[0].text !== 'string' || String(To.elements[0].text).match(/^(0|[1-9][0-9]*)$/) === null) {
|
||||
if (To.type !== 'element' || To.name !== 'To' || To.attributes !== undefined || To.elements === undefined || To.elements.length !== 1 || To.elements[0].type !== 'text' || typeof To.elements[0].text !== 'string') {
|
||||
throw new Error('Expected To element.');
|
||||
}
|
||||
const toNum = To.elements[0].text;
|
||||
if (String(toNum).match(/^(0|[1-9][0-9]*)$/) === null) {
|
||||
throw new Error(`Expected To element to be a number but it was ${toNum}.`);
|
||||
}
|
||||
//TODO: check if From and To are valid relations
|
||||
//<ExtraData>
|
||||
const ExtraData = ReleaseUpdatePath.elements[2];
|
||||
if (ExtraData.type !== 'element' || ExtraData.name !== 'ExtraData') {
|
||||
throw new Error(`Expected ExtraData element in patch ${From.elements[0].text}to${To.elements[0].text}.`);
|
||||
if (ExtraData.type !== 'element' || ExtraData.name !== 'ExtraData' || ExtraData.attributes !== undefined) {
|
||||
throw new Error(`Expected ExtraData element in patch ${fromNum}to${toNum}.`);
|
||||
}
|
||||
if (ExtraData.attributes !== undefined || ExtraData.elements === undefined) {
|
||||
throw new Error(`Expected ExtraData element with no attributes but some children in patch ${From.elements[0].text}to${To.elements[0].text}.`);
|
||||
if (ExtraData.elements === undefined || (product === 'assets_swtor_fr_fr' && fromNum === '132' && toNum === '130')) {
|
||||
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>
|
||||
|
@ -152,12 +160,35 @@ export default function verifyPatchmanifest(manifestFile: xmlJs.Element, product
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue