From 620cb8bb1d620cc6e28e93e4c2d3c5de8e0f5653 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Fri, 22 Jun 2018 18:16:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20release=20path=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ssn/releasePaths.ts | 94 +++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/src/ssn/releasePaths.ts b/src/ssn/releasePaths.ts index 587d0e2..530a578 100644 --- a/src/ssn/releasePaths.ts +++ b/src/ssn/releasePaths.ts @@ -2,51 +2,73 @@ function getFroms({ product, to: releaseTo}: {product: string, to: number}) { //The launcher (patcher, patcher2014, patcher2017) is always installing from -1, never from a previous version if (product.startsWith('patcher')) { - return [-1]; + return [-1]; } else { - const froms: number[] = []; + const froms: number[] = []; - //Always X-1toX - froms.push(releaseTo - 1); + //Always X-1toX + froms.push(releaseTo - 1); - //Also 0toX, unless X is 0. And no need to add 0to1 a second time. - if (releaseTo >= 2) { froms.push(0); } + //Also 0toX, unless X is 0. And no need to add 0to1 a second time. + if (releaseTo >= 2) { froms.push(0); } - if ((releaseTo % 5) === 0) { - //Also X-5toX if X % 5 - if (releaseTo >= 10) { froms.push(releaseTo - 5); } - //Also X-20toX if X % 5 - if (releaseTo >= 25) { froms.push(releaseTo - 20); } - //Also downgrade from the following four releases - froms.push(releaseTo + 1); - froms.push(releaseTo + 2); - froms.push(releaseTo + 3); - froms.push(releaseTo + 4); - } else { //For some of the older releases, an update from _5 or _0 is possible - /* - e.g. in asset_swtor_main: - 5to7, 5to8, 5to9, - 10to12, 10to13, 10to14, - 15to17, 15to18, 15to19, - 20to22, 20to23, 20to24, - 25to27, 25to28, 25to29, - 30to32, 30to33, 30to34, - 35to37, etc. , 85to87 - */ - if (releaseTo >= 7 && (releaseTo % 5) > 1) { froms.push(releaseTo - (releaseTo % 5)); } - } + if ((releaseTo % 5) === 0) { + //Also X-5toX if X % 5 + if (releaseTo >= 10) { froms.push(releaseTo - 5); } + //Also X-20toX if X % 5 + if (releaseTo >= 25) { froms.push(releaseTo - 20); } + //Also downgrade from the following four releases + froms.push(releaseTo + 1); + froms.push(releaseTo + 2); + froms.push(releaseTo + 3); + froms.push(releaseTo + 4); + } else { //For some of the older releases, an update from _5 or _0 is possible + /* + e.g. in asset_swtor_main: + 5to7, 5to8, 5to9, + 10to12, 10to13, 10to14, + 15to17, 15to18, 15to19, + 20to22, 20to23, 20to24, + 25to27, 25to28, 25to29, + 30to32, 30to33, 30to34, + 35to37, etc. , 85to87 + */ + 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 * 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}) { - //TODO: need to recursively get froms until path is found - //TODO: need to ignore patches that we know are bugged (i.e. missing from CDN) - return getFroms({ product, to }).includes(from); - //TODO: we also need to return the release path, e.g. [[3, 4], [4, 5], [5, 6]] +export default function findReleasePath({ product, from, to}: {product: string, from: number, to: number}): Array<[number, number]> { + //We assume that "from < to" is true for all patches + + const froms = getFroms({ product, to }); + + //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 []; }