Add release path module

This commit is contained in:
C-3PO 2018-06-22 18:16:59 +02:00
parent ee3fd0a60f
commit 620cb8bb1d
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -2,51 +2,73 @@
function getFroms({ product, to: releaseTo}: {product: string, to: number}) { function getFroms({ product, to: releaseTo}: {product: string, to: number}) {
//The launcher (patcher, patcher2014, patcher2017) is always installing from -1, never from a previous version //The launcher (patcher, patcher2014, patcher2017) is always installing from -1, never from a previous version
if (product.startsWith('patcher')) { if (product.startsWith('patcher')) {
return [-1]; return [-1];
} else { } else {
const froms: number[] = []; const froms: number[] = [];
//Always X-1toX //Always X-1toX
froms.push(releaseTo - 1); froms.push(releaseTo - 1);
//Also 0toX, unless X is 0. And no need to add 0to1 a second time. //Also 0toX, unless X is 0. And no need to add 0to1 a second time.
if (releaseTo >= 2) { froms.push(0); } if (releaseTo >= 2) { froms.push(0); }
if ((releaseTo % 5) === 0) { if ((releaseTo % 5) === 0) {
//Also X-5toX if X % 5 //Also X-5toX if X % 5
if (releaseTo >= 10) { froms.push(releaseTo - 5); } if (releaseTo >= 10) { froms.push(releaseTo - 5); }
//Also X-20toX if X % 5 //Also X-20toX if X % 5
if (releaseTo >= 25) { froms.push(releaseTo - 20); } if (releaseTo >= 25) { froms.push(releaseTo - 20); }
//Also downgrade from the following four releases //Also downgrade from the following four releases
froms.push(releaseTo + 1); froms.push(releaseTo + 1);
froms.push(releaseTo + 2); froms.push(releaseTo + 2);
froms.push(releaseTo + 3); froms.push(releaseTo + 3);
froms.push(releaseTo + 4); froms.push(releaseTo + 4);
} else { //For some of the older releases, an update from _5 or _0 is possible } else { //For some of the older releases, an update from _5 or _0 is possible
/* /*
e.g. in asset_swtor_main: e.g. in asset_swtor_main:
5to7, 5to8, 5to9, 5to7, 5to8, 5to9,
10to12, 10to13, 10to14, 10to12, 10to13, 10to14,
15to17, 15to18, 15to19, 15to17, 15to18, 15to19,
20to22, 20to23, 20to24, 20to22, 20to23, 20to24,
25to27, 25to28, 25to29, 25to27, 25to28, 25to29,
30to32, 30to33, 30to34, 30to32, 30to33, 30to34,
35to37, etc. , 85to87 35to37, etc. , 85to87
*/ */
if (releaseTo >= 7 && (releaseTo % 5) > 1) { froms.push(releaseTo - (releaseTo % 5)); } if (releaseTo >= 7 && (releaseTo % 5) > 1) { froms.push(releaseTo - (releaseTo % 5)); }
} }
return froms; return froms;
} }
} }
/** Checks whether there is a valid path between our current release and the release we want to update to, and returns true or false. /**
* Checks whether there is a valid path between our current release and the release we want to update to, and returns an array with
* the release path, or an empty array if no path exists.
* E.g. for `{ from: 21, to: 24 }`, it returns [[21, 22], [22, 23], [23, 24]].
* Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing * Does not actually look at the manifest.xml file but theorizes on possible patches based on the usually created patches, allowing
* us to find release pathes for products that have not been released yet. * us to find release pathes for products that have not been released yet.
*/ */
export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}) { export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}): Array<[number, number]> {
//TODO: need to recursively get froms until path is found //We assume that "from < to" is true for all patches
//TODO: need to ignore patches that we know are bugged (i.e. missing from CDN)
return getFroms({ product, to }).includes(from); const froms = getFroms({ product, to });
//TODO: we also need to return the release path, e.g. [[3, 4], [4, 5], [5, 6]]
//If we can patch, return immediately
if (froms.includes(from)) {
return [[from, to]];
}
//Otherwise, check all froms recursively, by checking interim releases
const smallerFroms = froms.filter((num) => num > from);
//Always prefer shortest release paths (e.g. 1->3 vs. 1->2->3) by ensuring we check smallest froms first
smallerFroms.sort();
for (let i = 0, il = smallerFroms.length; i < il; i += 1) {
const interim = smallerFroms[i];
const releasePath = findReleasePath({ product, from, to: interim} );
if (releasePath.length > 0) {
return [...releasePath, [interim, to]];
}
}
return [];
} }