Skip to content

Commit d492884

Browse files
authored
使用 Java 8 运行时禁止更新 (#4032)
1 parent cf4fde5 commit d492884

File tree

6 files changed

+54
-30
lines changed

6 files changed

+54
-30
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/Metadata.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
import org.jackhuang.hmcl.util.StringUtils;
2121
import org.jackhuang.hmcl.util.io.JarUtils;
22+
import org.jackhuang.hmcl.util.platform.Architecture;
2223
import org.jackhuang.hmcl.util.platform.OperatingSystem;
24+
import org.jetbrains.annotations.Nullable;
2325

2426
import java.nio.file.Path;
2527
import java.nio.file.Paths;
28+
import java.util.EnumSet;
2629

2730
/**
2831
* Stores metadata about this application.
@@ -35,6 +38,9 @@ private Metadata() {
3538
public static final String FULL_NAME = "Hello Minecraft! Launcher";
3639
public static final String VERSION = System.getProperty("hmcl.version.override", JarUtils.getManifestAttribute("Implementation-Version", "@develop@"));
3740

41+
public static final int MINIMUM_REQUIRED_JAVA_VERSION = 8;
42+
public static final int MINIMUM_SUPPORTED_JAVA_VERSION = 11;
43+
3844
public static final String TITLE = NAME + " " + VERSION;
3945
public static final String FULL_TITLE = FULL_NAME + " v" + VERSION;
4046

@@ -93,4 +99,32 @@ public static boolean isDev() {
9399
public static boolean isNightly() {
94100
return !isStable() && !isDev();
95101
}
102+
103+
public static @Nullable String getSuggestedJavaDownloadLink() {
104+
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX && Architecture.SYSTEM_ARCH == Architecture.LOONGARCH64_OW)
105+
return "https://www.loongnix.cn/zh/api/java/downloads-jdk21/index.html";
106+
else {
107+
EnumSet<Architecture> supportedArchitectures;
108+
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS)
109+
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.X86, Architecture.ARM64);
110+
else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX)
111+
supportedArchitectures = EnumSet.of(
112+
Architecture.X86_64, Architecture.X86,
113+
Architecture.ARM64, Architecture.ARM32,
114+
Architecture.RISCV64, Architecture.LOONGARCH64
115+
);
116+
else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS)
117+
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.ARM64);
118+
else
119+
supportedArchitectures = EnumSet.noneOf(Architecture.class);
120+
121+
if (supportedArchitectures.contains(Architecture.SYSTEM_ARCH))
122+
return String.format("https://docs.hmcl.net/downloads/%s/%s.html",
123+
OperatingSystem.CURRENT_OS.getCheckedName(),
124+
Architecture.SYSTEM_ARCH.getCheckedName()
125+
);
126+
else
127+
return null;
128+
}
129+
}
96130
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
import org.jackhuang.hmcl.util.platform.OperatingSystem;
6464

6565
import java.io.File;
66-
import java.util.EnumSet;
6766
import java.util.List;
6867
import java.util.concurrent.CompletableFuture;
6968

@@ -320,39 +319,13 @@ public static void initialize(Stage stage) {
320319
LOG.warning("Invalid type for shown tips key: " + JAVA_VERSION_TIP, e);
321320
}
322321

323-
if (shownTipVersion == null || shownTipVersion.intValue() < 11) {
324-
String downloadLink = null;
325-
326-
if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX && Architecture.SYSTEM_ARCH == Architecture.LOONGARCH64_OW)
327-
downloadLink = "https://www.loongnix.cn/zh/api/java/downloads-jdk21/index.html";
328-
else {
329-
330-
EnumSet<Architecture> supportedArchitectures;
331-
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS)
332-
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.X86, Architecture.ARM64);
333-
else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX)
334-
supportedArchitectures = EnumSet.of(
335-
Architecture.X86_64, Architecture.X86,
336-
Architecture.ARM64, Architecture.ARM32,
337-
Architecture.RISCV64, Architecture.LOONGARCH64
338-
);
339-
else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS)
340-
supportedArchitectures = EnumSet.of(Architecture.X86_64, Architecture.ARM64);
341-
else
342-
supportedArchitectures = EnumSet.noneOf(Architecture.class);
343-
344-
if (supportedArchitectures.contains(Architecture.SYSTEM_ARCH))
345-
downloadLink = String.format("https://docs.hmcl.net/downloads/%s/%s.html",
346-
OperatingSystem.CURRENT_OS.getCheckedName(),
347-
Architecture.SYSTEM_ARCH.getCheckedName()
348-
);
349-
}
350-
322+
if (shownTipVersion == null || shownTipVersion.intValue() < Metadata.MINIMUM_SUPPORTED_JAVA_VERSION) {
351323
MessageDialogPane.Builder builder = new MessageDialogPane.Builder(i18n("fatal.deprecated_java_version"), null, MessageType.WARNING);
324+
String downloadLink = Metadata.getSuggestedJavaDownloadLink();
352325
if (downloadLink != null)
353326
builder.addHyperLink(i18n("fatal.deprecated_java_version.download_link", 21), downloadLink);
354327
Controllers.dialog(builder
355-
.ok(() -> config().getShownTips().put(JAVA_VERSION_TIP, 11))
328+
.ok(() -> config().getShownTips().put(JAVA_VERSION_TIP, Metadata.MINIMUM_SUPPORTED_JAVA_VERSION))
356329
.build());
357330
}
358331
}

HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.jackhuang.hmcl.task.TaskExecutor;
2828
import org.jackhuang.hmcl.ui.Controllers;
2929
import org.jackhuang.hmcl.ui.UpgradeDialog;
30+
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
3031
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
3132
import org.jackhuang.hmcl.util.StringUtils;
3233
import org.jackhuang.hmcl.ui.SwingUtils;
@@ -102,6 +103,16 @@ public static void updateFrom(RemoteVersion version) {
102103
return;
103104
}
104105

106+
if (JavaRuntime.CURRENT_VERSION < Metadata.MINIMUM_SUPPORTED_JAVA_VERSION) {
107+
MessageDialogPane.Builder builder = new MessageDialogPane.Builder(i18n("fatal.deprecated_java_version.update"), i18n("message.error"), MessageType.ERROR);
108+
String downloadLink = Metadata.getSuggestedJavaDownloadLink();
109+
if (downloadLink != null)
110+
builder.addHyperLink(i18n("fatal.deprecated_java_version.download_link", 21), downloadLink);
111+
builder.ok(null);
112+
Controllers.dialog(builder.build());
113+
return;
114+
}
115+
105116
Controllers.dialog(new UpgradeDialog(version, () -> {
106117
Path downloaded;
107118
try {

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ fatal.deprecated_java_version=HMCL will require Java 11 or later to run in the f
403403
It is recommended to install the latest version of Java to ensure that HMCL works properly.\n\
404404
\n\
405405
You can continue to keep the old version of Java. HMCL can recognize and manage multiple Java versions and will automatically select the appropriate Java for you based on the game version.
406+
fatal.deprecated_java_version.update=HMCL will require Java 11 or later to run in the future. Please install the latest version of Java to ensure that HMCL can complete the upgrade.\n\
407+
\n\
408+
You can continue to keep the old version of Java.\
409+
HMCL can recognize and manage multiple Java versions and will automatically select the appropriate Java for you based on the game version.
406410
fatal.deprecated_java_version.download_link=Download Java %d
407411
fatal.samba=If you opened Hello Minecraft! Launcher from a Samba network drive, some features might not be working. Please try updating your Java or moving the launcher to another directory.
408412
fatal.illegal_char=Your user path contains an illegal character "=". You will not be able to use authlib-injector or change the skin of your offline account.

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即將升級完
381381
fatal.apply_update_failure=我們很抱歉 Hello Minecraft! Launcher 無法自動完成升級程式,因為出現了一些問題。\n但你依然可以從 %s 處手動下載 HMCL 來完成升級。
382382
fatal.apply_update_need_win7=Hello Minecraft! Launcher 無法在 Windows XP/Vista 上進行自動更新。請從 %s 處手動下載 HMCL 來完成升級。
383383
fatal.deprecated_java_version=HMCL 未來需要 Java 11 或更高版本才能執行,但依然支援使用 Java 8 啟動遊戲。建議安裝最新版本的 Java 以確保 HMCL 正常執行。\n你可以繼續保留舊版本 Java。HMCL 能夠識別與管理多個 Java,並會自動根據遊戲版本為你選取合適的 Java。
384+
fatal.deprecated_java_version.update=更高版本的 HMCL 需要 Java 11 或更高版本才能執行,請安裝最新版本的 Java 以確保 HMCL 能夠完成升級。\n你可以繼續保留舊版本 Java。HMCL 能夠識別與管理多個 Java,並會自動根據遊戲版本為你選取合適的 Java。
384385
fatal.deprecated_java_version.download_link=下載 Java %d
385386
fatal.samba=如果您正在透過 Samba 共亯的目錄中開啟 Hello Minecraft! Launcher,啟動器可能無法正常工作,請嘗試更新您的 Java 或在本機目錄內開啟 HMCL。
386387
fatal.illegal_char=由於您的使用者目錄路徑中存在無效字元『=』,您將無法使用外部登入帳戶以及離線登入更換外觀功能。

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即将完成升
390390
fatal.apply_update_failure=我们很抱歉 Hello Minecraft! Launcher 无法自动完成升级,因为出现了一些问题。\n但你依可以从 %s 手动下载 HMCL 来完成升级。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
391391
fatal.apply_update_need_win7=Hello Minecraft! Launcher 无法在 Windows XP/Vista 上进行自动更新。请从 %s 手动下载 HMCL 来完成升级。
392392
fatal.deprecated_java_version=HMCL 未来需要 Java 11 或更高版本才能运行,但依然支持使用 Java 8 启动游戏。建议安装最新版本的 Java 以确保 HMCL 能正常工作。\n你可以继续保留旧版本 Java。HMCL 能够识别与管理多个 Java,并会自动根据游戏版本为你选择合适的 Java。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
393+
fatal.deprecated_java_version.update=更高版本的 HMCL 需要 Java 11 或更高版本才能运行,请安装最新版本的 Java 以确保 HMCL 能够完成升级。\n你可以继续保留旧版本 Java。HMCL 能够识别与管理多个 Java,并会自动根据游戏版本为你选择合适的 Java。
393394
fatal.deprecated_java_version.download_link=下载 Java %d
394395
fatal.samba=如果你正在通过 Samba 共享的文件夹中运行 Hello Minecraft! Launcher,启动器可能无法正常工作。请尝试更新你的 Java 或在本地文件夹内运行 HMCL。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
395396
fatal.illegal_char=由于你的用户文件夹路径中存在非法字符“=”,你将无法使用外置登录账户以及离线登录更换皮肤功能。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。

0 commit comments

Comments
 (0)