diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java index 374f6a5ce..dd84d1840 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java @@ -86,36 +86,27 @@ class AdditionalInstallersPage extends InstallersPage { protected void reload() { LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version.resolvePreservingPatches(repository)); String game = analyzer.getVersion(MINECRAFT).orElse(null); - String forge = analyzer.getVersion(FORGE).orElse(null); - String neoForge = analyzer.getVersion(NEO_FORGE).orElse(null); - String liteLoader = analyzer.getVersion(LITELOADER).orElse(null); - String optiFine = analyzer.getVersion(OPTIFINE).orElse(null); - String fabric = analyzer.getVersion(FABRIC).orElse(null); - String fabricApi = analyzer.getVersion(FABRIC_API).orElse(null); - String quilt = analyzer.getVersion(QUILT).orElse(null); - String quiltApi = analyzer.getVersion(QUILT_API).orElse(null); - - InstallerItem[] libraries = group.getLibraries(); - String[] versions = new String[]{game, forge, neoForge, liteLoader, optiFine, fabric, fabricApi, quilt, quiltApi}; - String currentGameVersion = Lang.nonNull(getVersion("game"), game); boolean compatible = true; - for (int i = 0; i < libraries.length; ++i) { - String libraryId = libraries[i].getLibraryId(); - String libraryVersion = Lang.nonNull(getVersion(libraryId), versions[i]); - boolean alreadyInstalled = versions[i] != null && !(controller.getSettings().get(libraryId) instanceof UpdateInstallerWizardProvider.RemoveVersionAction); + + for (InstallerItem library : group.getLibraries()) { + String libraryId = library.getLibraryId(); + String version = analyzer.getVersion(libraryId).orElse(null); + String libraryVersion = Lang.requireNonNullElse(getVersion(libraryId), version); + boolean alreadyInstalled = version != null && !(controller.getSettings().get(libraryId) instanceof UpdateInstallerWizardProvider.RemoveVersionAction); if (!"game".equals(libraryId) && currentGameVersion != null && !currentGameVersion.equals(game) && getVersion(libraryId) == null && alreadyInstalled) { // For third-party libraries, if game version is being changed, and the library is not being reinstalled, // warns the user that we should update the library. - libraries[i].setState(libraryVersion, /* incompatibleWithGame */ true, /* removable */ true); + library.setState(libraryVersion, /* incompatibleWithGame */ true, /* removable */ true); compatible = false; } else if (alreadyInstalled || getVersion(libraryId) != null) { - libraries[i].setState(libraryVersion, /* incompatibleWithGame */ false, /* removable */ true); + library.setState(libraryVersion, /* incompatibleWithGame */ false, /* removable */ true); } else { - libraries[i].setState(/* libraryVersion */ null, /* incompatibleWithGame */ false, /* removable */ false); + library.setState(/* libraryVersion */ null, /* incompatibleWithGame */ false, /* removable */ false); } } + this.compatible.set(compatible); }