diff --git a/src/ssn/releasePaths.ts b/src/ssn/releasePaths.ts index 530a578..f24b6f3 100644 --- a/src/ssn/releasePaths.ts +++ b/src/ssn/releasePaths.ts @@ -1,5 +1,8 @@ +import { Product } from '../interfaces/ISettings'; +import verifyProductName from '../ssn/verifyProductName'; + /** For the given release in the given product, returns from which releases we can patch to this release. */ -function getFroms({ product, to: releaseTo}: {product: string, to: number}) { +function getFroms({ product, to: releaseTo}: {product: Product, to: number}) { //The launcher (patcher, patcher2014, patcher2017) is always installing from -1, never from a previous version if (product.startsWith('patcher')) { return [-1]; @@ -47,8 +50,16 @@ function getFroms({ product, to: releaseTo}: {product: string, to: number}) { * 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}): Array<[number, number]> { +export default function findReleasePath({ product, from, to}: {product: Product, from: number, to: number}): Array<[number, number]> { + //Verify function arguments + if (!verifyProductName(product)) { + throw new Error(`"${product}" is not a valid product.`); + } + //We assume that "from < to" is true for all patches + if (from > to) { + throw new Error('Cannot patch backwards; to must be greater than from.'); + } const froms = getFroms({ product, to });