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.
68 lines (67 loc) • 3.03 kB
JavaScript
import { ProgressBarSymbol } from "../../console/progressBar.js";
import { MergeMode } from "../../models/options.js";
import ArrayUtil from "../../utils/arrayUtil.js";
import Module from "../module.js";
class CandidateMergeSplitValidator extends Module {
options;
constructor(options, progressBar) {
super(progressBar, CandidateMergeSplitValidator.name);
this.options = options;
}
/**
* Validate the {@link WriteCandidate}s.
*/
validate(dat, candidates) {
if (candidates.length === 0) {
this.prefixedLogger.trace(
`${dat.getName()}: no candidates to validate merged & split ROM sets for`
);
return [];
}
this.prefixedLogger.trace(`${dat.getName()}: validating merged & split ROM sets`);
this.progressBar.setSymbol(ProgressBarSymbol.CANDIDATE_VALIDATING);
this.progressBar.resetProgress(candidates.length);
const datGamesIndexed = dat.getGames().reduce((map, game) => {
map.set(game.getName(), game);
return map;
}, /* @__PURE__ */ new Map());
const candidatesIndexed = candidates.filter((candidate) => candidate.getRomsWithFiles().length > 0).reduce((map, candidate) => {
map.set(candidate.getGame().getName(), candidate);
return map;
}, /* @__PURE__ */ new Map());
const missingGames = candidates.filter((candidate) => candidate.getRomsWithFiles().length > 0).map((candidate) => candidate.getGame()).reduce(ArrayUtil.reduceUnique(), []).flatMap((game) => {
const missingDependencies = [];
const cloneOf = game.getCloneOf();
if (this.options.getMergeRoms() === MergeMode.SPLIT && cloneOf !== void 0 && !candidatesIndexed.has(cloneOf)) {
missingDependencies.push(cloneOf);
}
if (this.options.getMergeRoms() !== MergeMode.FULLNONMERGED) {
const missingDeviceGames = game.getDeviceRefs().map((deviceRef) => datGamesIndexed.get(deviceRef.getName())).filter(
(deviceGame) => deviceGame !== void 0 && // Dependent device has ROM files
deviceGame.getRoms().length > 0
).map((deviceGame) => {
const deviceCandidate = candidatesIndexed.get(deviceGame.getName());
if (deviceCandidate) {
return void 0;
}
return deviceGame.getName();
}).filter((deviceGameName) => deviceGameName !== void 0).toSorted((a, b) => a.localeCompare(b));
for (const missingDeviceGame of missingDeviceGames) {
missingDependencies.push(missingDeviceGame);
}
}
if (missingDependencies.length > 0) {
this.prefixedLogger.warn(
`${dat.getName()}: ${game.getName()}: missing dependent ROM set${missingDependencies.length === 1 ? "" : "s"}: ${missingDependencies.join(", ")}`
);
}
return missingDependencies;
});
this.prefixedLogger.trace(`${dat.getName()}: done validating merged & split ROM sets`);
return missingGames;
}
}
export {
CandidateMergeSplitValidator as default
};
//# sourceMappingURL=candidateMergeSplitValidator.js.map