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.

60 lines • 2.85 kB
import { ProgressBarSymbol } from '../console/progressBar.js'; import DriveSemaphore from '../driveSemaphore.js'; import { ChecksumBitmask } from '../types/files/fileChecksums.js'; import PatchFactory from '../types/patches/patchFactory.js'; import Scanner from './scanner.js'; /** * Scan for {@link Patch}es and parse them into the correct supported type. */ export default class PatchScanner extends Scanner { constructor(options, progressBar, fileFactory) { super(options, progressBar, fileFactory, PatchScanner.name); } /** * Scan & process {@link Patch}es. */ async scan() { this.progressBar.logTrace('scanning patch files'); this.progressBar.setSymbol(ProgressBarSymbol.FILE_SCANNING); this.progressBar.reset(0); const patchFilePaths = await this.options.scanPatchFilesWithoutExclusions((increment) => { this.progressBar.incrementTotal(increment); }); this.progressBar.logTrace(`found ${patchFilePaths.length.toLocaleString()} patch file${patchFilePaths.length === 1 ? '' : 's'}`); this.progressBar.reset(patchFilePaths.length); const patchFiles = await this.getUniqueFilesFromPaths(patchFilePaths, this.options.getReaderThreads(), ChecksumBitmask.CRC32); this.progressBar.reset(patchFiles.length); const patches = (await new DriveSemaphore(this.options.getReaderThreads()).map(patchFiles, async (file) => { this.progressBar.incrementProgress(); const waitingMessage = `${file.toString()} ...`; this.progressBar.addWaitingMessage(waitingMessage); try { return await this.patchFromFile(file); } catch (error) { this.progressBar.logWarn(`${file.toString()}: failed to parse patch: ${error}`); return undefined; } finally { this.progressBar.incrementDone(); this.progressBar.removeWaitingMessage(waitingMessage); } })).filter((patch) => patch !== undefined); this.progressBar.logTrace('done scanning patch files'); return patches; } async patchFromFile(file) { const patchForFilename = await PatchFactory.patchFromFilename(file); if (patchForFilename) { this.progressBar.logTrace(`${file.toString()}: found patch by extension: ${typeof patchForFilename}`); return patchForFilename; } const patchForFileContents = await PatchFactory.patchFromFileContents(file); if (patchForFileContents) { this.progressBar.logTrace(`${file.toString()}: found patch by contents: ${typeof patchForFileContents}`); return patchForFileContents; } return undefined; } } //# sourceMappingURL=patchScanner.js.map