From 0b5348e81962dffbce3637dfa41b2720b7baa844 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 16:07:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Speed=20up=20development=20by=20?= =?UTF-8?q?caching=20downloaded=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/installPatch.ts | 2 +- src/ssn/getPatchTest.ts | 60 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/ssn/getPatchTest.ts diff --git a/src/installPatch.ts b/src/installPatch.ts index dcc4ef3..b4ac023 100644 --- a/src/installPatch.ts +++ b/src/installPatch.ts @@ -1,5 +1,5 @@ import getManifest from './ssn/getManifest'; -import getPatch from './ssn/getPatch'; +import getPatch from './ssn/getPatchTest'; (async () => { //----- PATCHMANIFEST ----- diff --git a/src/ssn/getPatchTest.ts b/src/ssn/getPatchTest.ts new file mode 100644 index 0000000..cd3c270 --- /dev/null +++ b/src/ssn/getPatchTest.ts @@ -0,0 +1,60 @@ +import downloadUrlContents from '../cdn/downloadUrlContents'; +import getUrlContents from '../cdn/getUrlContents'; +import { Product } from '../interfaces/ISettings'; +import { SsnDiffType } from '../interfaces/ISsnFileEntry'; +import extractFileStream from './extractFileStream'; +import getSolidpkg from './getSolidpkg'; +import readSsnFile from './reader/readSsnFile'; +import getFileFromDisks from './streams/getFileFromDisks'; +import streamToArrayBuffer from './streams/streamToArrayBuffer'; +import verifyPatch from './verify/verifyPatch'; + +export default async function getPatch(product: Product, from: number, to: number) { + const solidpkg = await getSolidpkg(product, from, to); + console.debug(solidpkg.files); + + function createUrlObject(fileName: string) { + return { host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${fileName}` }; + } + + //start download, making sure that .zip file downloads first + const indexOfLastFile = solidpkg.files.length - 1; + const zipFile = getUrlContents(createUrlObject(solidpkg.files[indexOfLastFile].name)); + //const diskFiles = solidpkg.files.slice(0, indexOfLastFile).map((file) => downloadUrlContents(createUrlObject(file.name))); + + //we can parse the file entries as soon as the .zip file is downloaded + const fileEntries = readSsnFile(await zipFile); + console.debug(fileEntries); + + //Verify file entries + verifyPatch(fileEntries, product, from); + + //Then we need to wait for disks to finish download before we can extract individual files + //TODO: we can optimize this to already extract some files as soon as their relevant parts are downloaded + //const diskFilenames = await Promise.all(diskFiles); + const diskFilenames = ['../assets_swtor_main_-1to0.z01']; + //const dvArray = bufferArray.map((buffer) => new DataView(buffer)); + + //TODO: Verify that downloaded files match the hash in `solidpkg.pieces` + + //Extract newly added files + fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile && file.diskNumberStart === 0).forEach(async (file) => { + const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); + const fileContents = extractFileStream(file, fileStream); + console.debug(await streamToArrayBuffer(fileContents)); + //TODO: need to write to disk + }); + + //Extract changed files + fileEntries.filter((file) => file.diffType === SsnDiffType.Changed && file.diskNumberStart === 0).forEach(async (file) => { + const fileStream = await getFileFromDisks(diskFilenames, { diskStart: file.diskNumberStart, offset: file.offset, storedSize: file.compressedSize }); + const fileContents = extractFileStream(file, fileStream); + console.debug(await streamToArrayBuffer(fileContents)); + //TODO: need to apply diffing, then write to disk + }); + + //Need to delete deleted files + fileEntries.filter((file) => file.diffType === SsnDiffType.Deleted).forEach((file) => { + //TODO: need to delete file + }); +}