use of com.pixbits.lib.io.archive.VerifierEntry in project rom-manager by Jakz.
the class Scanner method scanForRoms.
public void scanForRoms(boolean total) throws IOException {
ignoredPaths.clear();
foundFiles.clear();
clones.clear();
if (total) {
logger.i(LogTarget.romset(set), "Scanning for roms");
set.resetStatus();
} else {
logger.i(LogTarget.romset(set), "Scanning for new roms");
set.romStream().filter(r -> r.isPresent()).map(r -> r.handle().path()).forEach(ignoredPaths::add);
}
ignoredPaths.addAll(settings.getIgnoredPaths());
Path folder = settings.romsPath;
if (!canProceedWithScan())
return;
FolderScanner folderScanner = new FolderScanner(ignoredPaths, true);
final Set<Path> pathsToScan = folderScanner.scan(folder);
List<VerifierEntry> foundEntries = Collections.synchronizedList(new ArrayList<>());
/* scanning task */
{
Operation<Path, List<VerifierEntry>> operation = path -> {
logger.d(LogTarget.file(path), "> Scanning %s", path.getFileName().toString());
try {
return scanner.scanFile(path);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (RuntimeException e) {
logger.e(LogTarget.file(path), "Exception while scanning %s", path.toString());
e.printStackTrace();
if (!SevenZip.isInitializedSuccessfully()) {
Throwable ee = SevenZip.getLastInitializationException();
ee.printStackTrace();
}
return null;
}
};
BiConsumer<Long, Float> guiProgress = (i, f) -> {
Main.progress.update(f, "Scanning " + i + " of " + pathsToScan.size() + "...");
};
Consumer<List<VerifierEntry>> callback = results -> {
foundEntries.addAll(results);
};
Runnable onComplete = () -> {
SwingUtilities.invokeLater(() -> {
Main.progress.finished();
List<VerifierEntry> transformedEntries = foundEntries.stream().collect(Collectors.toList());
HandleSet handleSet = new HandleSet(transformedEntries);
HandleSet.Stats stats = handleSet.stats();
logger.i(LogTarget.romset(set), "Found %d potential matches (%d binary, %d inside archives, %d nested inside %d archives).", stats.totalHandles, stats.binaryCount, stats.archivedCount, stats.nestedArchiveInnerCount, stats.nestedArchiveCount);
transformedEntries.forEach(h -> logger.d(LogTarget.romset(set), "> %s", h.toString()));
Runnable verifyTask = verifyTask(transformedEntries, total);
verifyTask.run();
});
};
AsyncGuiPoolWorker<Path, List<VerifierEntry>> worker = new AsyncGuiPoolWorker<>(operation, guiProgress, 1);
SwingUtilities.invokeLater(() -> {
Main.progress.show(Main.mainFrame, "Scanning " + pathsToScan.size() + " files", () -> worker.cancel());
});
worker.compute(pathsToScan, callback, onComplete);
}
}
Aggregations