🎨 Minor code quality improvements

This commit is contained in:
C-3PO 2018-07-04 19:25:22 +02:00
parent 08b5a37c17
commit d843ce1200
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
4 changed files with 17 additions and 18 deletions

View file

@ -83,15 +83,15 @@ For each file, the extra field contains the following information:
## Manifests (`.patchmanifest`) ## 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`) ## 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`) ## 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 # File download and CDN

View file

@ -1,14 +1,12 @@
import getPatch from './ssn/getPatch';
import getPatchmanifest from './ssn/getPatchmanifest'; import getPatchmanifest from './ssn/getPatchmanifest';
import getSolidpkg from './ssn/getSolidpkg';
(async () => { (async () => {
//----- PATCHMANIFEST ----- //----- PATCHMANIFEST -----
//.patchmanifest files contain a single XML file called "manifest.xml" //const patchmanifestJson = await getPatchmanifest('assets_swtor_de_de');
const patchmanifestJson = await getPatchmanifest('assets_swtor_de_de'); //console.log(patchmanifestJson);
console.log(patchmanifestJson);
//----- SOLIDPKG ----- //----- PATCH -----
//.solidpkg files contain a single Bencode file called "metafile.solid" const patch = await getPatch('assets_swtor_de_de', -1, 0);
const solidFile = await getSolidpkg('assets_swtor_de_de', -1, 0); console.log(patch);
console.log(solidFile);
})(); })();

View file

@ -29,8 +29,8 @@ export default async function extractFile(file: ISsnFileEntry, dvArray: DataView
dvFinal = decryptFile(dvFinal, file.comprSize, file.decryptionKeys); dvFinal = decryptFile(dvFinal, file.comprSize, file.decryptionKeys);
} }
//Uncompress file //Decompress file
const uncompressedBuffer: Buffer = await new Promise((resolve, reject) => { const decompressedBuffer: Buffer = await new Promise((resolve, reject) => {
console.log(new Uint8Array(dvFinal.buffer)); console.log(new Uint8Array(dvFinal.buffer));
zlib.inflateRaw(dvFinal, (error, result) => { zlib.inflateRaw(dvFinal, (error, result) => {
if (error !== null) { if (error !== null) {
@ -39,5 +39,5 @@ export default async function extractFile(file: ISsnFileEntry, dvArray: DataView
resolve(result); resolve(result);
}); });
}) as Buffer; }) as Buffer;
return uncompressedBuffer.buffer as ArrayBuffer; return decompressedBuffer.buffer as ArrayBuffer;
} }

View file

@ -6,14 +6,15 @@ import getSolidpkg from './getSolidpkg';
import readSsnFile from './reader/readSsnFile'; import readSsnFile from './reader/readSsnFile';
export default async function getPatch(product: Product, from: number, to: number) { export default async function getPatch(product: Product, from: number, to: number) {
const solidPkg = await getSolidpkg(product, from, to); const solidpkg = await getSolidpkg(product, from, to);
console.debug(solidPkg.files); 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 zipFile = bufferArray[bufferArray.length - 1];
const dvArray = bufferArray.map((buffer) => new DataView(buffer)); 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); const fileEntries = readSsnFile(zipFile);
console.debug(fileEntries); console.debug(fileEntries);