From e934d6c983079093ec513a28e61069787bb856c2 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sun, 3 Oct 2021 22:04:55 +0800 Subject: [PATCH] feat(install): Optifine 1.17 compatible with Forge now. --- .../UpdateInstallerWizardProvider.java | 14 ++++--- .../resources/assets/lang/I18N.properties | 1 + .../resources/assets/lang/I18N_zh.properties | 1 + .../assets/lang/I18N_zh_CN.properties | 1 + .../jackhuang/hmcl/download/MaintainTask.java | 2 +- .../UnsupportedInstallationException.java | 39 +++++++++++++++++++ .../download/fabric/FabricInstallTask.java | 8 ++-- .../hmcl/download/forge/ForgeInstallTask.java | 11 ++---- .../optifine/OptiFineInstallTask.java | 26 ++++++++++--- 9 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/UnsupportedInstallationException.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/UpdateInstallerWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/UpdateInstallerWizardProvider.java index 5b32ba239..41808d424 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/UpdateInstallerWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/UpdateInstallerWizardProvider.java @@ -19,10 +19,8 @@ package org.jackhuang.hmcl.ui.download; import javafx.scene.Node; import org.jackhuang.hmcl.download.*; -import org.jackhuang.hmcl.download.fabric.FabricInstallTask; import org.jackhuang.hmcl.download.game.GameAssetIndexDownloadTask; import org.jackhuang.hmcl.download.game.LibraryDownloadException; -import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask; import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.setting.DownloadProviders; import org.jackhuang.hmcl.setting.Profile; @@ -157,9 +155,15 @@ public final class UpdateInstallerWizardProvider implements WizardProvider { } else { Controllers.dialog(i18n("install.failed.downloading.detail", url) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageDialogPane.MessageType.ERROR, next); } - } else if (exception instanceof OptiFineInstallTask.UnsupportedOptiFineInstallationException || - exception instanceof FabricInstallTask.UnsupportedFabricInstallationException) { - Controllers.dialog(i18n("install.failed.optifine_conflict"), i18n("install.failed"), MessageDialogPane.MessageType.ERROR, next); + } else if (exception instanceof UnsupportedInstallationException) { + switch (((UnsupportedInstallationException) exception).getReason()) { + case UnsupportedInstallationException.FORGE_1_17_OPTIFINE_H1_PRE2: + Controllers.dialog(i18n("install.failed.optifine_forge_1.17"), i18n("install.failed"), MessageDialogPane.MessageType.ERROR, next); + break; + default: + Controllers.dialog(i18n("install.failed.optifine_conflict"), i18n("install.failed"), MessageDialogPane.MessageType.ERROR, next); + break; + } } else if (exception instanceof DefaultDependencyManager.UnsupportedLibraryInstallerException) { Controllers.dialog(i18n("install.failed.install_online"), i18n("install.failed"), MessageDialogPane.MessageType.ERROR, next); } else if (exception instanceof ArtifactMalformedException || exception instanceof ZipException) { diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 9b987afc5..250ea99cd 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -384,6 +384,7 @@ install.failed.downloading.timeout=Timed out while downloading the file: %s install.failed.install_online=Unable to recognize the provided installer file. If you are installing a mod, go to "Mods" page. install.failed.malformed=The files just downloaded a moment ago is malformed. You may switch to other download provider to resolve this problem. install.failed.optifine_conflict=Fabric, OptiFine and Forge are installed simultaneously on Minecraft 1.13 +install.failed.optifine_forge_1.17=For Minecraft 1.17.1, Only OptiFine H1 Pre2 and above versions are compatible with Forge, you can install them in snapshot versions. install.failed.version_mismatch=The library requires the game version %s, but the actual version is %s. install.installer.change_version=%s, this version is not compatible with current game version. Click here to choose another one. install.installer.choose=Choose a %s version diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index c06bbe6d0..51d8121f1 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -384,6 +384,7 @@ install.failed.downloading.timeout=下載逾時: %s install.failed.install_online=無法識別要安裝的軟體。如果你要安裝 Mod,你需要在模組管理頁面安裝模組。 install.failed.malformed=剛才下載的檔案格式損壞。您可以切換到其他下載來源以解決此問題。 install.failed.optifine_conflict=暫不支援 OptiFine 與 Forge 同時安裝在 Minecraft 1.13 上 +install.failed.optifine_forge_1.17=Minecraft 1.17.1 下,僅 OptiFine H1 Pre2 及以上版本能相容 Forge。你可以從 OptiFine 測試版中選擇最新版本。 install.failed.version_mismatch=該軟體需要的遊戲版本為 %s,但實際的遊戲版本為 %s。 install.installer.change_version=%s,該版本與當前遊戲不相容,您需要點擊此處更換版本或刪除 install.installer.choose=選擇 %s 版本 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 225627a39..c8c8c3bb0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -384,6 +384,7 @@ install.failed.downloading.timeout=下载超时:%s install.failed.install_online=无法识别要安装的软件。如果你要安装 Mod,你需要在模组管理页面安装模组。 install.failed.malformed=下载的文件格式损坏。您可以切换到其他下载源来解决此问题。 install.failed.optifine_conflict=暂不支持 OptiFine, Fabric 与 Forge 同时安装在 Minecraft 1.13 及以上版本 +install.failed.optifine_forge_1.17=Minecraft 1.17.1 下,仅 OptiFine H1 Pre2 及以上版本能兼容 Forge。你可以从 OptiFine 测试版中选择最新版本。 install.failed.version_mismatch=该软件需要的游戏版本为 %s,但实际的游戏版本为 %s。 install.installer.change_version=%s,该版本与当前游戏不兼容,您需要点击此处更换版本或删除 install.installer.choose=选择 %s 版本 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MaintainTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MaintainTask.java index 09f24da4f..f51439b7b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MaintainTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MaintainTask.java @@ -1,6 +1,6 @@ /* * Hello Minecraft! Launcher - * Copyright (C) 2020 huangyuhui and contributors + * Copyright (C) 2021 huangyuhui and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/UnsupportedInstallationException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/UnsupportedInstallationException.java new file mode 100644 index 000000000..d056513b3 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/UnsupportedInstallationException.java @@ -0,0 +1,39 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download; + +public class UnsupportedInstallationException extends Exception { + + private final int reason; + + public UnsupportedInstallationException(int reason) { + this.reason = reason; + } + + public int getReason() { + return reason; + } + + // e.g. Forge is not compatible with fabric. + public static final int UNSUPPORTED_LAUNCH_WRAPPER = 1; + + // 1.17: OptiFine>=H1 Pre2 is compatible with Forge. + public static final int FORGE_1_17_OPTIFINE_H1_PRE2 = 2; + + public static final int FABRIC_NOT_COMPATIBLE_WITH_FORGE = 3; +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricInstallTask.java index e577896a5..0ec185af9 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricInstallTask.java @@ -21,6 +21,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.download.LibraryAnalyzer; +import org.jackhuang.hmcl.download.UnsupportedInstallationException; import org.jackhuang.hmcl.game.Arguments; import org.jackhuang.hmcl.game.Artifact; import org.jackhuang.hmcl.game.Library; @@ -31,6 +32,8 @@ import org.jackhuang.hmcl.util.gson.JsonUtils; import java.util.*; +import static org.jackhuang.hmcl.download.UnsupportedInstallationException.FABRIC_NOT_COMPATIBLE_WITH_FORGE; + /** * Note: Fabric should be installed first. * @@ -61,7 +64,7 @@ public final class FabricInstallTask extends Task { @Override public void preExecute() throws Exception { if (!Objects.equals("net.minecraft.client.main.Main", version.resolve(dependencyManager.getGameRepository()).getMainClass())) - throw new UnsupportedFabricInstallationException(); + throw new UnsupportedInstallationException(FABRIC_NOT_COMPATIBLE_WITH_FORGE); } @Override @@ -202,7 +205,4 @@ public final class FabricInstallTask extends Task { return stable; } } - - public static class UnsupportedFabricInstallationException extends Exception { - } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeInstallTask.java index 860cf34ec..4449ed1fb 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeInstallTask.java @@ -17,11 +17,7 @@ */ package org.jackhuang.hmcl.download.forge; -import org.jackhuang.hmcl.download.DefaultDependencyManager; -import org.jackhuang.hmcl.download.DependencyManager; -import org.jackhuang.hmcl.download.LibraryAnalyzer; -import org.jackhuang.hmcl.download.VersionMismatchException; -import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask; +import org.jackhuang.hmcl.download.*; import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.task.FileDownloadTask; import org.jackhuang.hmcl.task.Task; @@ -39,6 +35,7 @@ import java.util.Collections; import java.util.Map; import java.util.Optional; +import static org.jackhuang.hmcl.download.UnsupportedInstallationException.UNSUPPORTED_LAUNCH_WRAPPER; import static org.jackhuang.hmcl.util.StringUtils.removePrefix; import static org.jackhuang.hmcl.util.StringUtils.removeSuffix; @@ -101,12 +98,12 @@ public final class ForgeInstallTask extends Task { } @Override - public void execute() throws IOException, VersionMismatchException, OptiFineInstallTask.UnsupportedOptiFineInstallationException { + public void execute() throws IOException, VersionMismatchException, UnsupportedInstallationException { String originalMainClass = version.resolve(dependencyManager.getGameRepository()).getMainClass(); if (VersionNumber.VERSION_COMPARATOR.compare("1.13", remote.getGameVersion()) <= 0) { // Forge 1.13 is not compatible with fabric. if (!LibraryAnalyzer.VANILLA_MAIN.equals(originalMainClass) && !LibraryAnalyzer.MOD_LAUNCHER_MAIN.equals(originalMainClass) && !LibraryAnalyzer.LAUNCH_WRAPPER_MAIN.equals(originalMainClass)) - throw new OptiFineInstallTask.UnsupportedOptiFineInstallationException(); + throw new UnsupportedInstallationException(UNSUPPORTED_LAUNCH_WRAPPER); } else { // Forge 1.12 and older versions is compatible with vanilla and launchwrapper. // if (!"net.minecraft.client.main.Main".equals(originalMainClass) && !"net.minecraft.launchwrapper.Launch".equals(originalMainClass)) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java index 72c4afaa3..cf8e712c1 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineInstallTask.java @@ -19,6 +19,7 @@ package org.jackhuang.hmcl.download.optifine; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.download.LibraryAnalyzer; +import org.jackhuang.hmcl.download.UnsupportedInstallationException; import org.jackhuang.hmcl.download.VersionMismatchException; import org.jackhuang.hmcl.game.*; import org.jackhuang.hmcl.task.FileDownloadTask; @@ -28,6 +29,7 @@ import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.platform.CommandBuilder; import org.jackhuang.hmcl.util.platform.JavaVersion; import org.jackhuang.hmcl.util.platform.SystemUtils; +import org.jackhuang.hmcl.util.versioning.VersionNumber; import org.jenkinsci.constant_pool_scanner.ConstantPool; import org.jenkinsci.constant_pool_scanner.ConstantPoolScanner; import org.jenkinsci.constant_pool_scanner.ConstantType; @@ -39,6 +41,7 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; + import static org.jackhuang.hmcl.util.Lang.getOrDefault; /** @@ -122,8 +125,11 @@ public final class OptiFineInstallTask extends Task { @Override public void execute() throws Exception { String originalMainClass = version.resolve(dependencyManager.getGameRepository()).getMainClass(); - if (!LibraryAnalyzer.VANILLA_MAIN.equals(originalMainClass) && !LibraryAnalyzer.LAUNCH_WRAPPER_MAIN.equals(originalMainClass) && !LibraryAnalyzer.MOD_LAUNCHER_MAIN.equals(originalMainClass)) - throw new OptiFineInstallTask.UnsupportedOptiFineInstallationException(); + if (!LibraryAnalyzer.VANILLA_MAIN.equals(originalMainClass) && + !LibraryAnalyzer.LAUNCH_WRAPPER_MAIN.equals(originalMainClass) && + !LibraryAnalyzer.MOD_LAUNCHER_MAIN.equals(originalMainClass) && + !LibraryAnalyzer.BOOTSTRAP_LAUNCHER_MAIN.equals(originalMainClass)) + throw new UnsupportedInstallationException(UnsupportedInstallationException.UNSUPPORTED_LAUNCH_WRAPPER); List libraries = new LinkedList<>(); libraries.add(optiFineLibrary); @@ -176,6 +182,19 @@ public final class OptiFineInstallTask extends Task { libraries.add(launchWrapper); } } + + Path buildofText = fs.getPath("buildof.txt"); + if (Files.exists(buildofText)) { + String buildof = FileUtils.readText(buildofText).trim(); + VersionNumber buildofVer = VersionNumber.asVersion(buildof); + + if (LibraryAnalyzer.BOOTSTRAP_LAUNCHER_MAIN.equals(originalMainClass)) { + // OptiFine H1 Pre2+ is compatible with Forge 1.17 + if (buildofVer.compareTo(VersionNumber.asVersion("20210924-190833")) < 0) { + throw new UnsupportedInstallationException(UnsupportedInstallationException.FORGE_1_17_OPTIFINE_H1_PRE2); + } + } + } } if (!hasLaunchWrapper) { @@ -194,9 +213,6 @@ public final class OptiFineInstallTask extends Task { dependencies.add(dependencyManager.checkLibraryCompletionAsync(getResult(), true)); } - public static class UnsupportedOptiFineInstallationException extends Exception { - } - /** * Install OptiFine library from existing local file. *