diff --git a/src/interfaces/IManifest.ts b/src/interfaces/IManifest.ts new file mode 100644 index 0000000..20794dc --- /dev/null +++ b/src/interfaces/IManifest.ts @@ -0,0 +1,16 @@ +/** A patch manifest, containing a list of releases, how to patch them, and which the current release is. */ +export default interface IManifest { + /** Current release. */ + current: number; + /** List of releases. */ + releases: { + [s: string]: { + /** SHA1 hash of this release. */ + sha1: string; + /** List of releases from where we can patch to this release. */ + from: number[]; + /** List of releases that this release can be patched to. */ + to: number[]; + }; +}; +} diff --git a/src/ssn/getPatchmanifest.ts b/src/ssn/getPatchmanifest.ts index f338a86..6d012df 100644 --- a/src/ssn/getPatchmanifest.ts +++ b/src/ssn/getPatchmanifest.ts @@ -1,6 +1,7 @@ import { TextDecoder } from 'util'; import * as xmlJs from 'xml-js'; import getUrlContents from '../cdn/getUrlContents'; +import IManifest from '../interfaces/IManifest'; import { Product } from '../interfaces/ISettings'; import parsePatchmanifest from '../ssn/parsePatchmanifest'; import verifyPatchmanifest from '../ssn/verifyPatchmanifest'; @@ -10,7 +11,7 @@ import readSsnFile from './readSsnFile'; const Decoder = new TextDecoder('utf-8'); -export default async function getPatchmanifest(product: Product): Promise { +export default async function getPatchmanifest(product: Product): Promise { //Verify function arguments if (!verifyProductName(product)) { throw new Error(`"${product}" is not a valid product.`); diff --git a/src/ssn/parsePatchmanifest.ts b/src/ssn/parsePatchmanifest.ts index baef51b..8088a30 100644 --- a/src/ssn/parsePatchmanifest.ts +++ b/src/ssn/parsePatchmanifest.ts @@ -1,7 +1,8 @@ +import IManifest from '../interfaces/IManifest'; /** Receives a JSON-converted version of the manifest.xml file, and returns an easier to read JSON file */ -export default function parsePatchManifest(manifestFile: any): any { - const out: any = {}; +export default function parsePatchManifest(manifestFile: any): IManifest { + const out: IManifest = { current: -1, releases: {} }; const PatchManifest = manifestFile.elements[0]; @@ -11,21 +12,22 @@ export default function parsePatchManifest(manifestFile: any): any { //053678f8057e52896a8145dca5c188ab3f24fa55f const Releases = PatchManifest.elements[7]; - out.releases = {}; Releases.elements.forEach((Release: any) => { const id = Release.elements[0].elements[0].text; const sha1 = Release.elements[1].elements[0].text; out.releases[id] = { sha1, from: [], to: [] }; }); + //287288... { const from = ReleaseUpdatePath.elements[0].elements[0].text; const to = ReleaseUpdatePath.elements[1].elements[0].text; + //Release -1 does not exist but is a valid "from", e.g. for -1to0 if (from !== '-1') { - out.releases[from].to.push(to); + out.releases[from].to.push(Number(to)); } - out.releases[to].from.push(from); + out.releases[to].from.push(Number(from)); }); return out;