From aed383b1fb8838ebaf7f80f79402bd8f65d5f9b5 Mon Sep 17 00:00:00 2001 From: Sevastjan Date: Wed, 12 Jul 2023 01:48:16 +0300 Subject: [PATCH] [FIX] Bug with missing forgotten dependency/conflict --- .../launcher/profiles/ClientProfile.java | 7 +++-- .../profiles/optional/OptionalView.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java index 36a707cd..f1d2506b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java @@ -375,9 +375,10 @@ public void verify() { if (s == null) throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.dependenciesFile", f.name)); } - if(f.xorConflictFile != null) for (OptionalDepend s : f.xorConflictFile) { - if (s == null) - throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.xorConflictFile", f.name)); + if(f.xorConflictFile != null) + for (OptionalDepend s : f.xorConflictFile) { + if (s == null) + throw new IllegalArgumentException(String.format("Found null entry in updateOptional.%s.xorConflictFile", f.name)); } if (f.triggersList != null) { for (OptionalTrigger trigger : f.triggersList) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java index 26859c2a..33362f03 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java @@ -9,6 +9,7 @@ import java.util.Set; import java.util.Arrays; import java.util.function.BiConsumer; +import java.util.stream.Collectors; public class OptionalView { public Set enabled = new HashSet<>(); @@ -26,6 +27,7 @@ public OptionalView(OptionalView view) { this.enabled = new HashSet<>(view.enabled); this.installInfo = new HashMap<>(view.installInfo); this.all = view.all; + fixDependencies(); } public OptionalView(ClientProfile profile, OptionalView old) { @@ -41,6 +43,7 @@ public OptionalView(ClientProfile profile, OptionalView old) { disable(newFile, (file, status) -> {}); } } + fixDependencies(); } @SuppressWarnings("unchecked") @@ -81,6 +84,33 @@ public Set getEnabledActions() { return results; } + //Needed if dependency/conflict was added after mod declaring it and clients have their profiles with this mod enabled + public void fixDependencies() { + Set disabled = all.stream().filter(t -> !isEnabled(t)).collect(Collectors.toSet()); + for (OptionalFile file : disabled) { + if (file.xorConflict != null && Arrays.stream(file.xorConflict).noneMatch(this::isEnabled)) { + enable(file.xorConflict[0], false, null); + } + } + for (OptionalFile file : enabled) { + if (file.dependencies != null) { + for (OptionalFile dep : file.dependencies) { + enable(dep, false, null); + } + } + if (file.conflict != null) { + for (OptionalFile conflict : file.conflict) { + disable(conflict, null); + } + } + if (file.xorConflict != null) { + for (OptionalFile xorConflict : file.xorConflict) { + disable(xorConflict, null); + } + } + } + } + public Set getDisabledActions() { Set results = new HashSet<>(); for (OptionalFile e : all) {