[FEATURE][EXPERIMENTAL] Потенциальная проблема с зависимостями в опциональных модах

This commit is contained in:
Gravit 2020-09-12 16:34:09 +07:00
parent 72a8325a15
commit 8b8ef665ef
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
2 changed files with 14 additions and 10 deletions

View file

@ -47,6 +47,7 @@ public class OptionalFile {
public int subTreeLevel = 1; public int subTreeLevel = 1;
@LauncherNetworkAPI @LauncherNetworkAPI
public boolean isPreset; public boolean isPreset;
@Deprecated
public transient Set<OptionalFile> dependenciesCount; public transient Set<OptionalFile> dependenciesCount;
private volatile transient Collection<BiConsumer<OptionalFile, Boolean>> watchList = null; private volatile transient Collection<BiConsumer<OptionalFile, Boolean>> watchList = null;

View file

@ -3,11 +3,14 @@
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
public class OptionalView { public class OptionalView {
public Set<OptionalFile> enabled = new HashSet<>(); public Set<OptionalFile> enabled = new HashSet<>();
public Map<OptionalFile, Set<OptionalFile>> dependenciesCountMap = new HashMap<>();
public Set<OptionalFile> all; public Set<OptionalFile> all;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -64,8 +67,8 @@ public void enable(OptionalFile file)
file.watchEvent(true); file.watchEvent(true);
if (file.dependencies != null) { if (file.dependencies != null) {
for (OptionalFile dep : file.dependencies) { for (OptionalFile dep : file.dependencies) {
if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>(); Set<OptionalFile> dependenciesCount = dependenciesCountMap.computeIfAbsent(dep, k -> new HashSet<>());
dep.dependenciesCount.add(file); dependenciesCount.add(file);
enable(dep); enable(dep);
} }
} }
@ -79,22 +82,22 @@ public void disable(OptionalFile file)
{ {
if(!enabled.remove(file)) return; if(!enabled.remove(file)) return;
file.watchEvent(false); file.watchEvent(false);
if (file.dependenciesCount != null) { Set<OptionalFile> dependenciesCount = dependenciesCountMap.get(file);
for (OptionalFile f : file.dependenciesCount) { if (dependenciesCount != null) {
for (OptionalFile f : dependenciesCount) {
if (f.isPreset) continue; if (f.isPreset) continue;
disable(f); disable(f);
} }
file.dependenciesCount.clear(); dependenciesCount.clear();
file.dependenciesCount = null;
} }
if (file.dependencies != null) { if (file.dependencies != null) {
for (OptionalFile f : file.dependencies) { for (OptionalFile f : file.dependencies) {
if (!enabled.contains(f)) continue; if (!enabled.contains(f)) continue;
if (f.dependenciesCount == null) { dependenciesCount = dependenciesCountMap.get(f);
if (dependenciesCount == null) {
disable(f); disable(f);
} else if (f.dependenciesCount.size() <= 1) { } else if (dependenciesCount.size() <= 1) {
f.dependenciesCount.clear(); dependenciesCount.clear();
f.dependenciesCount = null;
disable(f); disable(f);
} }
} }