From 3ee23f6445de2dfa4da4bc06a4cc5ce74db9f770 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sat, 23 Jun 2018 22:14:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Add=20preliminary=20patch=20down?= =?UTF-8?q?loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/{heartbeat.ts => heartbeatDns.ts} | 0 src/interfaces/ISolidSimple.ts | 18 ++++++++++++++++++ src/ssn/getPatch.ts | 21 +++++++++++++++++++++ src/ssn/getSolidpkg.ts | 3 ++- 4 files changed, 41 insertions(+), 1 deletion(-) rename src/cdn/{heartbeat.ts => heartbeatDns.ts} (100%) create mode 100644 src/interfaces/ISolidSimple.ts create mode 100644 src/ssn/getPatch.ts diff --git a/src/cdn/heartbeat.ts b/src/cdn/heartbeatDns.ts similarity index 100% rename from src/cdn/heartbeat.ts rename to src/cdn/heartbeatDns.ts diff --git a/src/interfaces/ISolidSimple.ts b/src/interfaces/ISolidSimple.ts new file mode 100644 index 0000000..2b32dc2 --- /dev/null +++ b/src/interfaces/ISolidSimple.ts @@ -0,0 +1,18 @@ +interface ISolidSimpleFile { + /** Name of this file, e.g. `assets_swtor_de_de_-1to0.z01`. */ + name: string; + /** Length of this file in bytes. */ + length: number; +} + +/** Simplified format of the Bencoded metafile.solid file */ +export default interface ISolidSimple { + /** Date and time when this patch was created. */ + created: Date; + /** List of files included with this patch (.zip, .z01, etc.) */ + files: ISolidSimpleFile[]; + /** Length of one piece in bytes, e.g. 4194304 for 4 MiB. */ + pieceLength: number; + ///** Concatenated hashes of all pieces. */ + //pieces: string; +} diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts new file mode 100644 index 0000000..29ba3ff --- /dev/null +++ b/src/ssn/getPatch.ts @@ -0,0 +1,21 @@ +import getUrlContents from '../cdn/getUrlContents'; +import { Product } from '../interfaces/ISettings'; +import extractFile from './extractFile'; +import getSolidpkg from './getSolidpkg'; +import readSsnFile from './readSsnFile'; + +export default async function getPatch(product: Product, from: number, to: number) { + const solidPkg = await getSolidpkg(product, from, to); + + const bufferArray = await Promise.all(solidPkg.files.map((file) => getUrlContents({ host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${file.name}` }))); + const zipFile = bufferArray[bufferArray.length - 1]; + + const fileEntries = readSsnFile(zipFile); + + //TODO: verify file entries + + const dvArray = bufferArray.map((buffer) => new DataView(buffer)); + fileEntries.map((entry) => extractFile(entry, dvArray) ); + + return fileEntries; +} diff --git a/src/ssn/getSolidpkg.ts b/src/ssn/getSolidpkg.ts index 5aa4781..a4917d4 100644 --- a/src/ssn/getSolidpkg.ts +++ b/src/ssn/getSolidpkg.ts @@ -1,13 +1,14 @@ import getUrlContents from '../cdn/getUrlContents'; import { Product } from '../interfaces/ISettings'; import ISolid from '../interfaces/ISolidFile'; +import ISolidSimple from '../interfaces/ISolidSimple'; import verifyProductName from '../ssn/verifyProductName'; import parseBencode from './bencodeParser'; import extractFile from './extractFile'; import readSsnFile from './readSsnFile'; import verifySolidpkg from './verifySolidpkg'; -export default async function getSolidpkg(product: Product, from: number, to: number): Promise { +export default async function getSolidpkg(product: Product, from: number, to: number): Promise { //Verify function arguments if (!verifyProductName(product)) { throw new Error(`"${product}" is not a valid product.`);