[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;
@LauncherNetworkAPI
public boolean isPreset;
@Deprecated
public transient Set<OptionalFile> dependenciesCount;
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.optional.actions.OptionalAction;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class OptionalView {
public Set<OptionalFile> enabled = new HashSet<>();
public Map<OptionalFile, Set<OptionalFile>> dependenciesCountMap = new HashMap<>();
public Set<OptionalFile> all;
@SuppressWarnings("unchecked")
@ -64,8 +67,8 @@ public void enable(OptionalFile file)
file.watchEvent(true);
if (file.dependencies != null) {
for (OptionalFile dep : file.dependencies) {
if (dep.dependenciesCount == null) dep.dependenciesCount = new HashSet<>();
dep.dependenciesCount.add(file);
Set<OptionalFile> dependenciesCount = dependenciesCountMap.computeIfAbsent(dep, k -> new HashSet<>());
dependenciesCount.add(file);
enable(dep);
}
}
@ -79,22 +82,22 @@ public void disable(OptionalFile file)
{
if(!enabled.remove(file)) return;
file.watchEvent(false);
if (file.dependenciesCount != null) {
for (OptionalFile f : file.dependenciesCount) {
Set<OptionalFile> dependenciesCount = dependenciesCountMap.get(file);
if (dependenciesCount != null) {
for (OptionalFile f : dependenciesCount) {
if (f.isPreset) continue;
disable(f);
}
file.dependenciesCount.clear();
file.dependenciesCount = null;
dependenciesCount.clear();
}
if (file.dependencies != null) {
for (OptionalFile f : file.dependencies) {
if (!enabled.contains(f)) continue;
if (f.dependenciesCount == null) {
dependenciesCount = dependenciesCountMap.get(f);
if (dependenciesCount == null) {
disable(f);
} else if (f.dependenciesCount.size() <= 1) {
f.dependenciesCount.clear();
f.dependenciesCount = null;
} else if (dependenciesCount.size() <= 1) {
dependenciesCount.clear();
disable(f);
}
}