Skip to content

Commit

Permalink
Fix: ROMWriter filesize logging & consistency (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Jun 13, 2023
1 parent 15ab442 commit 0584304
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/modules/romWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,27 @@ export default class ROMWriter extends Module {
const uniqueInputToOutputEntries = inputToOutputEntries
.filter((_, idx) => outputRomFiles.indexOf(outputRomFiles[idx]) === idx);

const totalBytes = [...uniqueInputToOutputEntries.values()]
.flatMap((files) => files)
const totalBytes = uniqueInputToOutputEntries
.flatMap(([, outputFile]) => outputFile)
.reduce((sum, file) => sum + file.getSize(), 0);
await this.progressBar.logTrace(`${dat.getNameShort()}: ${releaseCandidate.getName()}: writing ${fsPoly.sizeReadable(totalBytes)} of ${uniqueInputToOutputEntries.length.toLocaleString()} file${uniqueInputToOutputEntries.length !== 1 ? 's' : ''}`);

/* eslint-disable no-await-in-loop */
for (let i = 0; i < uniqueInputToOutputEntries.length; i += 1) {
const [inputRomFile, outputRomFile] = uniqueInputToOutputEntries[i];
await this.writeRawSingle(dat, inputRomFile, outputRomFile);
await this.writeRawSingle(dat, releaseCandidate, inputRomFile, outputRomFile);
}
}

private async writeRawSingle(dat: DAT, inputRomFile: File, outputRomFile: File): Promise<void> {
private async writeRawSingle(
dat: DAT,
releaseCandidate: ReleaseCandidate,
inputRomFile: File,
outputRomFile: File,
): Promise<void> {
// Input and output are the exact same, do nothing
if (outputRomFile.equals(inputRomFile)) {
await this.progressBar.logTrace(`${dat.getNameShort()}: ${outputRomFile}: same file, skipping`);
await this.progressBar.logTrace(`${dat.getNameShort()}: ${releaseCandidate.getName()}: same file, skipping: ${outputRomFile}`);
return;
}

Expand All @@ -306,14 +311,14 @@ export default class ROMWriter extends Module {
// If the output file already exists, see if we need to do anything
if (!this.options.getOverwrite() && await fsPoly.exists(outputFilePath)) {
if (!this.options.getOverwrite() && !this.options.getOverwriteInvalid()) {
await this.progressBar.logTrace(`${dat.getNameShort()}: ${outputFilePath}: not overwriting existing file`);
await this.progressBar.logTrace(`${dat.getNameShort()}: ${releaseCandidate.getName()}: not overwriting existing file: ${outputFilePath}`);
return;
}

if (this.options.getOverwriteInvalid()) {
const existingTest = await this.testWrittenRaw(dat, outputFilePath, outputRomFile);
if (!existingTest) {
await this.progressBar.logTrace(`${dat.getNameShort()}: ${outputFilePath}: not overwriting existing file, existing file is what was expected`);
await this.progressBar.logTrace(`${dat.getNameShort()}: ${releaseCandidate.getName()}: not overwriting existing file, existing file is what was expected: ${outputFilePath}`);
return;
}
}
Expand All @@ -326,7 +331,7 @@ export default class ROMWriter extends Module {
if (this.options.shouldTest()) {
const writtenTest = await this.testWrittenRaw(dat, outputFilePath, outputRomFile);
if (writtenTest) {
await this.progressBar.logError(`${dat.getNameShort()}: ${outputFilePath}: written file ${writtenTest}`);
await this.progressBar.logError(`${dat.getNameShort()}: ${releaseCandidate.getName()}: written file ${writtenTest}: ${outputFilePath}`);
}
}
this.enqueueFileDeletion(inputRomFile);
Expand Down

0 comments on commit 0584304

Please sign in to comment.