Skip to content

Commit 433845e

Browse files
committed
Fixed incorrect behavior, not all duplicated mods were removed from the standard mods dir (while still accounting for exception mods) + small optimization
1 parent 07cfff2 commit 433845e

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

loader/core/src/main/java/pl/skidam/automodpack_loader_core/client/ModpackUpdater.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -455,44 +455,45 @@ private boolean applyModpack() throws Exception {
455455
// Copy files to running directory
456456
boolean needsRestart1 = ModpackUtils.correctFilesLocations(modpackDir, modpackContent, filesNotToCopy);
457457

458-
// Check if the conflicting mods still exits, they might have been deleted by methods above
459-
conflictingNestedMods = conflictingNestedMods.stream()
460-
.filter(conflictingMod -> {
461-
Path standardModsDir = MODS_DIR.resolve(conflictingMod.modPath().getFileName());
462-
return Files.exists(standardModsDir);
463-
})
464-
.toList();
465-
466-
if (!conflictingNestedMods.isEmpty()) {
467-
LOGGER.warn("Found conflicting nested mods: {}", conflictingNestedMods);
468-
}
469-
470-
final List<Path> modpackMods;
471-
final Collection<FileInspection.Mod> modpackModList;
472-
final List<Path> standardMods;
473-
final Collection<FileInspection.Mod> standardModList;
474-
458+
Set<Path> modpackMods = new HashSet<>();
459+
Collection<FileInspection.Mod> modpackModList = new ArrayList<>();
475460
Path modpackModsDir = modpackDir.resolve("mods");
476461
if (Files.exists(modpackModsDir)) {
477-
try (Stream<Path> modpackModsStream = Files.list(modpackModsDir)) {
478-
modpackMods = modpackModsStream.toList();
479-
modpackModList = modpackMods.stream().map(FileInspection::getMod).filter(Objects::nonNull).toList();
462+
try (Stream<Path> stream = Files.list(modpackModsDir)) {
463+
stream.forEach(path -> {
464+
modpackMods.add(path);
465+
FileInspection.Mod mod = FileInspection.getMod(path);
466+
if (mod != null) {
467+
modpackModList.add(mod);
468+
}
469+
});
480470
}
481-
} else {
482-
modpackModList = List.of();
483471
}
484472

485-
if (Files.exists(MODS_DIR)) {
486-
try (Stream<Path> standardModsStream = Files.list(MODS_DIR)) {
487-
standardMods = standardModsStream.toList();
488-
standardModList = new ArrayList<>(standardMods.stream().map(FileInspection::getMod).filter(Objects::nonNull).toList());
473+
Collection<FileInspection.Mod> standardModList = new ArrayList<>();
474+
Path standardModsDir = MODS_DIR;
475+
if (Files.exists(standardModsDir)) {
476+
try (Stream<Path> stream = Files.list(standardModsDir)) {
477+
stream.forEach(path -> {
478+
FileInspection.Mod mod = FileInspection.getMod(path);
479+
if (mod != null) {
480+
standardModList.add(mod);
481+
}
482+
});
489483
}
490-
} else {
491-
standardModList = new ArrayList<>();
484+
}
485+
486+
// Check if the conflicting mods still exits, they might have been deleted by methods above
487+
conflictingNestedMods = conflictingNestedMods.stream()
488+
.filter(conflictingMod -> modpackMods.contains(conflictingMod.modPath()))
489+
.toList();
490+
491+
if (!conflictingNestedMods.isEmpty()) {
492+
LOGGER.warn("Found conflicting nested mods: {}", conflictingNestedMods);
492493
}
493494

494495
boolean needsRestart2 = ModpackUtils.fixNestedMods(conflictingNestedMods, standardModList);
495-
Set<String> ignoredFiles = ModpackUtils.getIgnoredWithNested(conflictingNestedMods, filesNotToCopy);
496+
Set<String> ignoredFiles = ModpackUtils.getWorkaroundsWithNested(conflictingNestedMods, workaroundMods);
496497

497498
// Remove duplicate mods
498499
boolean needsRestart3 = ModpackUtils.removeDupeMods(modpackDir, standardModList, modpackModList, ignoredFiles, workaroundMods);

loader/core/src/main/java/pl/skidam/automodpack_loader_core/client/ModpackUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ public static boolean fixNestedMods(List<FileInspection.Mod> conflictingNestedMo
161161
return needsRestart;
162162
}
163163

164-
// Returns new ignored files list, accounting for conflicting nested mods
165-
public static Set<String> getIgnoredWithNested(List<FileInspection.Mod> conflictingNestedMods, Set<String> ignoredFiles) {
166-
Set<String> newIgnoredFiles = new HashSet<>(ignoredFiles);
164+
// Returns ignored files list, which is workarounds set + conflicting nested mods
165+
public static Set<String> getWorkaroundsWithNested(List<FileInspection.Mod> conflictingNestedMods, Set<String> workarounds) {
166+
Set<String> newIgnoredFiles = new HashSet<>(workarounds);
167167

168168
for (FileInspection.Mod mod : conflictingNestedMods) {
169169
newIgnoredFiles.add(CustomFileUtils.formatPath(mod.modPath(), modpacksDir));
@@ -200,7 +200,9 @@ public static boolean removeDupeMods(Path modpackDir, Collection<FileInspection.
200200

201201
var dupeMods = ModpackUtils.getDupeMods(modpackDir, ignoredMods, standardModList, modpackModList);
202202

203-
if (dupeMods.isEmpty()) return false;
203+
if (dupeMods.isEmpty()) {
204+
return false;
205+
}
204206

205207
Set<FileInspection.Mod> modsToKeep = new HashSet<>();
206208

0 commit comments

Comments
 (0)