💡 Improve comments and code quality
This commit is contained in:
parent
b87236a435
commit
57d45b942b
2 changed files with 13 additions and 9 deletions
|
@ -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<ArrayBuffer> {
|
||||
//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');
|
||||
}
|
||||
//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);
|
||||
});
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue