Fix #2861: MaintainTask 中不应调用 getGameVersion (#2863)

* Fix #2861: MaintainTask 中不应调用 getGameVersion

* update

* fix checkstyle
This commit is contained in:
Glavo 2024-02-29 00:06:50 +08:00 committed by GitHub
parent 030fba4630
commit 08a3850dcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 14 deletions

View File

@ -282,7 +282,7 @@ public class HMCLGameRepository extends DefaultGameRepository {
}
if (LibraryAnalyzer.isModded(this, version)) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, getGameVersion(version).orElse(null));
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, null);
if (libraryAnalyzer.has(LibraryAnalyzer.LibraryType.FABRIC))
return VersionIconType.FABRIC.getIcon();
else if (libraryAnalyzer.has(LibraryAnalyzer.LibraryType.FORGE))

View File

@ -93,7 +93,7 @@ public final class HMCLModpackInstallTask extends Task<Void> {
public void execute() throws Exception {
String json = CompressingUtils.readTextZipEntry(zipFile, "minecraft/pack.json");
Version originalVersion = JsonUtils.GSON.fromJson(json, Version.class).setId(name).setJar(null);
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(originalVersion, repository.getGameVersion(originalVersion).orElse(null));
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(originalVersion, null);
Task<Version> libraryTask = Task.supplyAsync(() -> originalVersion);
// reinstall libraries
// libraries of Forge and OptiFine should be obtained by installation.

View File

@ -27,8 +27,6 @@ import javafx.scene.control.Control;
import javafx.scene.control.Skin;
import javafx.scene.image.Image;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.mod.ModpackConfiguration;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.util.i18n.I18n;
@ -61,12 +59,10 @@ public class GameItem extends Control {
this.version = id;
// GameVersion.minecraftVersion() is a time-costing job (up to ~200 ms)
CompletableFuture.supplyAsync(() -> profile.getRepository().getGameVersion(id).orElse(i18n("message.unknown")), POOL_VERSION_RESOLVE)
CompletableFuture.supplyAsync(() -> profile.getRepository().getGameVersion(id), POOL_VERSION_RESOLVE)
.thenAcceptAsync(game -> {
StringBuilder libraries = new StringBuilder(game);
HMCLGameRepository repository = profile.getRepository();
Version resolved = repository.getResolvedPreservingPatchesVersion(id);
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(resolved, repository.getGameVersion(resolved).orElse(null));
StringBuilder libraries = new StringBuilder(game.orElse(i18n("message.unknown")));
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(profile.getRepository().getResolvedPreservingPatchesVersion(id), game.orElse(null));
for (LibraryAnalyzer.LibraryMark mark : analyzer) {
String libraryId = mark.getLibraryId();
String libraryVersion = mark.getLibraryVersion();

View File

@ -106,7 +106,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
Version original = repository.getVersion(version.getId());
Version resolved = original.resolvePreservingPatches(repository);
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(resolved, repository.getGameVersion(resolved).orElse(null));
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(resolved, gameVersion);
for (LibraryAnalyzer.LibraryType type : LibraryAnalyzer.LibraryType.values()) {
if (!analyzer.has(type))
continue;

View File

@ -98,7 +98,7 @@ public class MaintainTask extends Task<Version> {
}
private static Version maintainGameWithLaunchWrapper(GameRepository repository, Version version, boolean reorderTweakClass) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, repository.getGameVersion(version).orElse(null));
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, null);
VersionLibraryBuilder builder = new VersionLibraryBuilder(version);
String mainClass = null;
@ -147,7 +147,7 @@ public class MaintainTask extends Task<Version> {
}
private static Version maintainGameWithCpwModLauncher(GameRepository repository, Version version) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, repository.getGameVersion(version).orElse(null));
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, null);
VersionLibraryBuilder builder = new VersionLibraryBuilder(version);
if (!libraryAnalyzer.has(FORGE)) return version;
@ -205,7 +205,7 @@ public class MaintainTask extends Task<Version> {
// Fix wrong configurations when launching 1.17+ with Forge.
private static Version maintainGameWithCpwBoostrapLauncher(GameRepository repository, Version version) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, repository.getGameVersion(version).orElse(null));
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, null);
VersionLibraryBuilder builder = new VersionLibraryBuilder(version);
if (!libraryAnalyzer.has(FORGE) && !libraryAnalyzer.has(NEO_FORGE)) return version;
@ -247,7 +247,7 @@ public class MaintainTask extends Task<Version> {
}
private static Version maintainOptiFineLibrary(GameRepository repository, Version version, boolean remove) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, repository.getGameVersion(version).orElse(null));
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version, null);
List<Library> libraries = new ArrayList<>(version.getLibraries());
if (libraryAnalyzer.has(OPTIFINE)) {