diff --git a/src/ssn/extractFile.ts b/src/ssn/extractFile.ts index 6d56f48..021227f 100644 --- a/src/ssn/extractFile.ts +++ b/src/ssn/extractFile.ts @@ -7,29 +7,33 @@ import ByteReader from './extractFileByteReader'; * Will throw an error when end of final DataView is reached. */ export default async function extractFile(file: ISsnFileEntry, dvArray: DataView[]): Promise { - //use ByteReader for reading a uint8 and seeking forward across DataView boundaries + //Use ByteReader for reading a uint8 and seeking forward across DataView boundaries const byteReader = new ByteReader(dvArray, file.diskNumberStart, file.offset); + //Local file header signature must be 0x04034B50 if (byteReader.readByte() !== 0x50 || byteReader.readByte() !== 0x4B || byteReader.readByte() !== 0x03 || byteReader.readByte() !== 0x04) { - throw new Error('Local file header had wrong magic'); + throw new Error('Local file header had wrong magic'); } + //All fields in the local file header are copies of the central file header, so we can skip them. + //FIXME: Maybe we should actually read these fields to verify that they are identical? byteReader.seek(22); const localFilenameSize = byteReader.readByte() + (byteReader.readByte() << 8); const localExtraSize = byteReader.readByte() + (byteReader.readByte() << 8); byteReader.seek(localFilenameSize + localExtraSize); + //Extract actual file contents let dvFinal = byteReader.extractDv(file.comprSize); - //decrypt file if necessary + //Decrypt file if necessary if (file.decryptionKeys !== undefined) { dvFinal = decryptFile(dvFinal, file.comprSize, file.decryptionKeys); } - //uncompress file + //Uncompress file const uncompressedBuffer: Buffer = await new Promise((resolve, reject) => { zlib.inflateRaw(dvFinal, (error, result) => { if (error !== null) { - reject(error); + return reject(error); } resolve(result); }); diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 32c9ccb..94ee5e8 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -7,13 +7,14 @@ import readSsnFile from './readSsnFile'; export default async function getPatch(product: Product, from: number, to: number) { const solidPkg = await getSolidpkg(product, from, to); - console.log(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 zipFile = bufferArray[bufferArray.length - 1]; const dvArray = bufferArray.map((buffer) => new DataView(buffer)); const fileEntries = readSsnFile(zipFile); + console.debug(fileEntries); //Verify file entries if (from === -1) { @@ -22,19 +23,18 @@ export default async function getPatch(product: Product, from: number, to: numbe }); } //TODO: last file must always be `${product}.version` with diff type. Other files depend on diffType. - console.log(fileEntries); //Extract newly added files fileEntries.filter((file) => file.diffType === SsnDiffType.NewFile).forEach(async (file) => { const fileContents = await extractFile(file, dvArray); - console.log(fileContents); + console.debug(fileContents); //TODO }); //Extract changed files fileEntries.filter((file) => file.diffType === SsnDiffType.Changed).forEach(async (file) => { const fileContents = await extractFile(file, dvArray); - console.log(fileContents); + console.debug(fileContents); //TODO });