修复 AdditionalInstallersPage (#2731)

This commit is contained in:
Glavo 2024-02-03 04:33:17 +08:00 committed by GitHub
parent 7f7068a556
commit dd2a09399e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}