From d843ce1200ebea04e8bc923b3f15097d6428f727 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Wed, 4 Jul 2018 19:25:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Minor=20code=20quality=20improve?= =?UTF-8?q?ments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- src/installPatch.ts | 14 ++++++-------- src/ssn/extractFile.ts | 6 +++--- src/ssn/getPatch.ts | 9 +++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c576464..0cf76f1 100644 --- a/README.md +++ b/README.md @@ -83,15 +83,15 @@ For each file, the extra field contains the following information: ## Manifests (`.patchmanifest`) -TODO: A .patchmanifest SSN file contains a single file `manifest.xml` which includes a list of releases and patches, and specifies which manifest is the current one. +A .patchmanifest SSN file contains a single file `manifest.xml` which includes a list of releases and patches, and specifies which manifest is the current one. ## Patches (`.solidpkg`) -TODO: A .solidpkg file contains a single file `metafile.solid`, which is in Bencode format (similar to .torrent files) and includes the names, sizes and hashes of all files with the patch data (.zip, .z01, .z02 etc.). +A .solidpkg file contains a single file `metafile.solid`, which is in Bencode format (similar to .torrent files) and includes the names, sizes and hashes of all files with the patch data (.zip, .z01, .z02 etc.). ## Version files (`.version`) -TODO: Once a patch is installed, you can look into the .version file to figure out which release it is, and use the hashes to verify that the installation is correct. +Once a patch is installed, you can look into the .version file to figure out which release it is, and use the hashes to verify that the installation is correct. # File download and CDN diff --git a/src/installPatch.ts b/src/installPatch.ts index 7e7a41a..9fa9bba 100644 --- a/src/installPatch.ts +++ b/src/installPatch.ts @@ -1,14 +1,12 @@ +import getPatch from './ssn/getPatch'; import getPatchmanifest from './ssn/getPatchmanifest'; -import getSolidpkg from './ssn/getSolidpkg'; (async () => { //----- PATCHMANIFEST ----- - //.patchmanifest files contain a single XML file called "manifest.xml" - const patchmanifestJson = await getPatchmanifest('assets_swtor_de_de'); - console.log(patchmanifestJson); + //const patchmanifestJson = await getPatchmanifest('assets_swtor_de_de'); + //console.log(patchmanifestJson); - //----- SOLIDPKG ----- - //.solidpkg files contain a single Bencode file called "metafile.solid" - const solidFile = await getSolidpkg('assets_swtor_de_de', -1, 0); - console.log(solidFile); + //----- PATCH ----- + const patch = await getPatch('assets_swtor_de_de', -1, 0); + console.log(patch); })(); diff --git a/src/ssn/extractFile.ts b/src/ssn/extractFile.ts index 58b20d4..7a38c00 100644 --- a/src/ssn/extractFile.ts +++ b/src/ssn/extractFile.ts @@ -29,8 +29,8 @@ export default async function extractFile(file: ISsnFileEntry, dvArray: DataView dvFinal = decryptFile(dvFinal, file.comprSize, file.decryptionKeys); } - //Uncompress file - const uncompressedBuffer: Buffer = await new Promise((resolve, reject) => { + //Decompress file + const decompressedBuffer: Buffer = await new Promise((resolve, reject) => { console.log(new Uint8Array(dvFinal.buffer)); zlib.inflateRaw(dvFinal, (error, result) => { if (error !== null) { @@ -39,5 +39,5 @@ export default async function extractFile(file: ISsnFileEntry, dvArray: DataView resolve(result); }); }) as Buffer; - return uncompressedBuffer.buffer as ArrayBuffer; + return decompressedBuffer.buffer as ArrayBuffer; } diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 442b69e..88fefc0 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -6,14 +6,15 @@ import getSolidpkg from './getSolidpkg'; import readSsnFile from './reader/readSsnFile'; export default async function getPatch(product: Product, from: number, to: number) { - const solidPkg = await getSolidpkg(product, from, to); - console.debug(solidPkg.files); + const solidpkg = await getSolidpkg(product, from, to); + console.debug(solidpkg.files); - 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 downloadPromises = solidpkg.files.map((file) => getUrlContents({ host: 'cdn-patch.swtor.com', path: `/patch/${product}/${product}_${from}to${to}/${file.name}` })); + const bufferArray = await Promise.all(downloadPromises); const zipFile = bufferArray[bufferArray.length - 1]; const dvArray = bufferArray.map((buffer) => new DataView(buffer)); - //TODO: Verify that downloaded files match the hash in `solidPkg.pieces` + //TODO: Verify that downloaded files match the hash in `solidpkg.pieces` const fileEntries = readSsnFile(zipFile); console.debug(fileEntries);