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.
51 lines (50 loc) • 2.07 kB
JavaScript
import path from "node:path";
import { ProgressBarSymbol } from "../console/progressBar.js";
import IgirHeader from "../models/dats/igirHeader.js";
import LogiqxDAT from "../models/dats/logiqx/logiqxDat.js";
import FsUtil from "../utils/fsUtil.js";
import Module from "./module.js";
class FixdatCreator extends Module {
options;
constructor(options, progressBar) {
super(progressBar, FixdatCreator.name);
this.options = options;
}
/**
* Create & write a fixdat.
*/
async create(originalDat, candidates) {
if (!this.options.shouldFixdat()) {
return void 0;
}
this.prefixedLogger.trace(`${originalDat.getName()}: generating a fixdat`);
this.progressBar.setSymbol(ProgressBarSymbol.WRITING);
this.progressBar.resetProgress(1);
const writtenRomHashCodes = new Set(
candidates.flatMap((candidate) => candidate.getRomsWithFiles()).map((romWithFiles) => romWithFiles.getRom()).map((rom) => rom.hashCode())
);
const gamesWithMissingRoms = originalDat.getGames().filter((game) => game.getRoms().some((rom) => !writtenRomHashCodes.has(rom.hashCode())));
if (gamesWithMissingRoms.length === 0) {
this.prefixedLogger.debug(
`${originalDat.getName()}: not creating a fixdat, all games were found`
);
return void 0;
}
const fixdatDir = this.options.getFixdatOutput();
if (!await FsUtil.exists(fixdatDir)) {
await FsUtil.mkdir(fixdatDir, { recursive: true });
}
const header = new IgirHeader("fixdat", originalDat, this.options);
const fixdat = new LogiqxDAT({ header, games: gamesWithMissingRoms });
const fixdatContents = fixdat.toXmlDat();
const fixdatPath = path.join(fixdatDir, fixdat.getFilename());
this.prefixedLogger.info(`${originalDat.getName()}: writing fixdat to '${fixdatPath}'`);
await FsUtil.writeFile(fixdatPath, fixdatContents);
this.prefixedLogger.trace(`${originalDat.getName()}: done generating a fixdat`);
return fixdatPath;
}
}
export {
FixdatCreator as default
};
//# sourceMappingURL=fixdatCreator.js.map