use of jack.rm.files.ScanResult in project rom-manager by Jakz.
the class ClonesDialog method activate.
public void activate(GameSet set, Set<ScanResult> clones) {
this.set = set;
this.keep.clear();
this.clones.clear();
// TODO: probably requires to be rewritten almost totally to manage multiple roms per game
Set<Rom> romClones = clones.stream().map(c -> c.rom).collect(Collectors.toSet());
this.clones = new ArrayList<>(clones);
this.clones.addAll(set.stream().flatMap(g -> g.stream()).filter(r -> romClones.contains(r)).map(r -> new ScanResult(r, r.handle())).collect(Collectors.toList()));
Collections.sort(this.clones);
this.keep = this.clones.stream().collect(Collectors.toMap(c -> c, c -> false));
this.colors = romClones.stream().collect(Collectors.toMap(c -> c, c -> colorGenerator.getColor()));
updateStatus();
model.fireChanges();
this.setLocationRelativeTo(null);
this.setVisible(true);
Dialogs.showWarning("Clones Found", colors.size() + " clones have been found,\nplease specify which entries you want to keep", this);
}
use of jack.rm.files.ScanResult in project rom-manager by Jakz.
the class ClonesDialog method autoChoose.
public void autoChoose(ClonePolicy policy, ClonePriority priority) {
if (policy == ClonePolicy.AUTO_SELECT_ALL)
this.keep = this.clones.stream().collect(Collectors.toMap(c -> c, c -> false));
List<List<ScanResult>> results = new ArrayList<>();
LinkedList<ScanResult> current = null;
/* create a list for each rom with clones */
boolean alreadySet = false;
for (ScanResult result : this.clones) {
if (current == null || !current.peekLast().rom.equals(result.rom)) {
if (current != null && !alreadySet)
results.add(current);
alreadySet = false;
current = new LinkedList<>();
}
current.add(result);
alreadySet |= keep.get(result);
}
if (current != null && !alreadySet)
results.add(current);
for (List<ScanResult> list : results) {
ScanResult result = chooseBestClone(list, policy, priority);
keep.put(result, true);
}
model.fireChanges();
updateStatus();
}
use of jack.rm.files.ScanResult in project rom-manager by Jakz.
the class ClonesDialog method chooseBestClone.
public ScanResult chooseBestClone(List<ScanResult> results, ClonePolicy policy, ClonePriority priority) {
if (priority != ClonePriority.ANY) {
List<ScanResult> filtered = results.stream().filter(r -> r.handle.getClass() == priority.type).collect(Collectors.toList());
if (!filtered.isEmpty())
results = filtered;
}
boolean hasRenamer = setManager.settings(set).getRenamer() != null;
boolean hasMover = setManager.settings(set).getFolderOrganizer() != null;
Predicate<ScanResult> predicateAny = e -> true;
Predicate<ScanResult> predicateCorrectFolder = e -> !hasMover || setManager.settings(set).romsPath.resolve(e.rom.game().getCorrectFolder()).equals(e.handle.path().getParent());
Predicate<ScanResult> predicateCorrectName = e -> !hasRenamer || e.rom.game().getCorrectName().equals(e.handle.path().getFileName().toString());
Predicate<ScanResult> predicateCorrectNameAndFolder = predicateCorrectName.and(predicateCorrectFolder);
List<Predicate<ScanResult>> predicates = Arrays.asList(predicateCorrectNameAndFolder, predicateCorrectName, predicateCorrectFolder, predicateAny);
Optional<ScanResult> optional = Optional.empty();
for (Predicate<ScanResult> predicate : predicates) if ((optional = results.stream().filter(predicate).findFirst()).isPresent())
break;
ScanResult chosen = optional.get();
return chosen;
}
Aggregations