From dd2a09399eb2ac059aa4522a01046879d69c9f55 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 3 Feb 2024 04:33:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20AdditionalInstallersPage?= =?UTF-8?q?=20(#2731)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/download/AdditionalInstallersPage.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) 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); }