UNPKG

igir

Version:

🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.

70 lines (69 loc) • 2.44 kB
import { ProgressBarSymbol } from "../../console/progressBar.js"; import OutputFactory from "../../modules/candidates/utils/outputFactory.js"; import Module from "../module.js"; class CandidatePostProcessor extends Module { options; constructor(options, progressBar) { super(progressBar, CandidatePostProcessor.name); this.options = options; } /** * Post-process the candidates. */ process(dat, candidates) { if (candidates.length === 0) { this.prefixedLogger.trace(`${dat.getName()}: no candidates to post-process`); return candidates; } this.prefixedLogger.trace(`${dat.getName()}: processing candidates`); this.progressBar.setSymbol(ProgressBarSymbol.CANDIDATE_GENERATING); this.progressBar.resetProgress(candidates.length); const outputFileBasenames = candidates.flatMap( (candidate) => candidate.getRomsWithFiles().map((romWithFiles) => { const outputPathParsed = OutputFactory.getPath( this.options, dat, candidate.getGame(), romWithFiles.getRom(), romWithFiles.getInputFile() ); return outputPathParsed.name + outputPathParsed.ext; }) ); const processedCandidates = candidates.map( (candidate) => this.postProcessCandidate(dat, candidate, outputFileBasenames) ); this.prefixedLogger.trace(`${dat.getName()}: done processing candidates`); return processedCandidates; } postProcessCandidate(dat, candidate, outputFileBasenames) { const newRomsWithFiles = this.mapRomsWithFiles( dat, candidate, candidate.getRomsWithFiles(), outputFileBasenames ); return candidate.withRomsWithFiles(newRomsWithFiles); } mapRomsWithFiles(dat, candidate, romsWithFiles, outputFileBasenames) { return romsWithFiles.map((romWithFiles) => { const newOutputPath = OutputFactory.getPath( this.options, dat, candidate.getGame(), romWithFiles.getRom(), romWithFiles.getInputFile(), outputFileBasenames ).format(); if (newOutputPath === romWithFiles.getOutputFile().getFilePath()) { return romWithFiles; } const newOutputFile = romWithFiles.getOutputFile().withFilePath(newOutputPath); return romWithFiles.withOutputFile(newOutputFile); }); } } export { CandidatePostProcessor as default }; //# sourceMappingURL=candidatePostProcessor.js.map