Skip to content

Commit

Permalink
Improve dlc duplicate handling
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Nov 20, 2024
1 parent d600c6c commit a6e02fe
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static enum DlcInfoStorageType {

@Override
public List<GameDlc> loadDlcs(Path directory) throws IOException {
var dlcs = loadDlcsFromDirectory(getDlcPath(directory));
dlcs.addAll(loadDlcsFromDirectory(directory.resolve("builtin_dlc")));
// Prefer builtin_dlcs in case of duplicates
var dlcs = new ArrayList<GameDlc>();
loadDlcsFromDirectory(directory.resolve("builtin_dlc"), dlcs);
loadDlcsFromDirectory(getDlcPath(directory), dlcs);
return dlcs;
}

Expand Down Expand Up @@ -759,25 +761,29 @@ default Path getDlcPath(Path p) {
}

default List<GameDlc> loadDlcs(Path p) throws IOException {
return loadDlcsFromDirectory(getDlcPath(p));
var dlcs = new ArrayList<GameDlc>();
loadDlcsFromDirectory(getDlcPath(p), dlcs);
return dlcs;
}

default List<GameDlc> loadDlcsFromDirectory(Path directory) throws IOException {
var dlcs = new ArrayList<GameDlc>();
default void loadDlcsFromDirectory(Path directory, List<GameDlc> existing) throws IOException {
if (!Files.isDirectory(directory)) {
return dlcs;
return;
}

try (var s = Files.list(directory)) {
s.forEach(f -> {
try {
GameDlc.fromDirectory(f).ifPresent(dlcs::add);
GameDlc.fromDirectory(f)
// Add duplicate check, in case DLC updates were messed up by Steam
.filter(gameDlc -> existing.stream()
.noneMatch(other -> other.getName().equals(gameDlc.getName())))
.ifPresent(existing::add);
} catch (Exception e) {
ErrorHandler.handleException(e);
}
});
}
return dlcs;
}

default String getModLauncherId(GameInstallation installation, GameMod mod) {
Expand Down

0 comments on commit a6e02fe

Please sign in to comment.