Skip to content

Commit

Permalink
Refactor: don't filter or write for DATs with no candidates (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Sep 23, 2022
1 parent eff589a commit 696d50e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/console/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chalk from 'chalk';

import LogLevel from './logLevel.js';

// https://www.toptal.com/designers/htmlarrows/symbols/
export const Symbols: { [key: string]: string } = {
WAITING: chalk.grey('⋯'),
SEARCHING: chalk.magenta('↻'),
Expand Down
13 changes: 7 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ function scanUpPathForFile(filePath: string, fileName: string): string | undefin
export default class Constants {
static readonly COMMAND_NAME = 'igir';

static readonly COMMAND_VERSION = JSON.parse(
fs.readFileSync(scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'package.json',
) as string).toString(),
).version;
static readonly COMMAND_VERSION = process.env.npm_package_version
|| JSON.parse(
fs.readFileSync(scanUpPathForFile(
url.fileURLToPath(new URL('.', import.meta.url)),
'package.json',
) as string).toString(),
).version;

static readonly GLOBAL_TEMP_DIR = globalTempDir + path.sep;

Expand Down
2 changes: 1 addition & 1 deletion src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class ArgumentsParser {
group: groupInputOutputPaths,
alias: 'i',
// TODO(cemmer): add a warning when input and output directories are the same, but also
// have a "yes" flag
// have a "yes" flag
description: 'Path(s) to ROM files or archives, these files will not be modified',
demandOption: true,
type: 'array',
Expand Down
7 changes: 6 additions & 1 deletion src/modules/candidateFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export default class CandidateFilter {
return output;
}

// TODO(cemmer): return early if there are no candidates to filter
// Return early if there aren't any candidates
const totalReleaseCandidates = [...parentsToCandidates.values()]
.reduce((sum, rcs) => sum + rcs.length, 0);
if (!totalReleaseCandidates) {
return output;
}

await this.progressBar.setSymbol(Symbols.FILTERING);
await this.progressBar.reset(parentsToCandidates.size);
Expand Down
19 changes: 9 additions & 10 deletions src/modules/romWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export default class ROMWriter {
return output;
}

// TODO(cemmer): different symbol if shouldn't write?
// Return early if we shouldn't write (are only reporting)
if (!this.options.shouldWrite()) {
return new Map(
[...parentsToCandidates.entries()]
.map(([parent]) => [parent, []]),
);
}

await this.progressBar.setSymbol(Symbols.WRITING);
await this.progressBar.reset(parentsToCandidates.size);

Expand All @@ -55,8 +62,6 @@ export default class ROMWriter {
[, [parent, releaseCandidates]],
callback: AsyncResultCallback<[Parent, File[]], Error>,
) => {
// TODO(cemmer): this tends to lock so one DAT processes at a time, makes DATS with no true
// candidates look like they're queued for real writes
await ROMWriter.semaphore.runExclusive(async () => {
await this.progressBar.increment();

Expand All @@ -80,11 +85,6 @@ export default class ROMWriter {
dat: DAT,
releaseCandidate: ReleaseCandidate,
): Promise<File[]> {
if (!this.options.shouldWrite()) {
await this.progressBar.logDebug(`${dat.getName()} | ${releaseCandidate.getName()}: not writing`);
return [];
}

const inputToOutput = await this.buildInputToOutput(dat, releaseCandidate);

// Determine if a write is needed based on the output not equaling the input
Expand Down Expand Up @@ -258,8 +258,7 @@ export default class ROMWriter {

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

0 comments on commit 696d50e

Please sign in to comment.