From d15d6ea7eda641990cd7cf432e112eeb5ecd0a43 Mon Sep 17 00:00:00 2001 From: burningtnt Date: Sat, 23 Dec 2023 19:13:42 +0800 Subject: [PATCH] Show a warning message before the application startup. --- .../java/net/burningtnt/hmclprs/Hooks.java | 30 +++++++++++++++++++ .../main/java/org/jackhuang/hmcl/Main.java | 2 ++ .../resources/assets/lang/I18N.properties | 5 ++++ .../resources/assets/lang/I18N_zh.properties | 5 ++++ .../assets/lang/I18N_zh_CN.properties | 5 ++++ 5 files changed, 47 insertions(+) create mode 100644 HMCL/src/main/java/net/burningtnt/hmclprs/Hooks.java diff --git a/HMCL/src/main/java/net/burningtnt/hmclprs/Hooks.java b/HMCL/src/main/java/net/burningtnt/hmclprs/Hooks.java new file mode 100644 index 0000000000..6af69199fa --- /dev/null +++ b/HMCL/src/main/java/net/burningtnt/hmclprs/Hooks.java @@ -0,0 +1,30 @@ +package net.burningtnt.hmclprs; + +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; + +import javax.swing.*; +import java.util.Optional; + +import static org.jackhuang.hmcl.util.i18n.I18n.i18n; + +public final class Hooks { + private Hooks() { + } + + public static void onApplicationLaunch() { + try { + Optional opt = new Alert(Alert.AlertType.CONFIRMATION, i18n("prs.warning")).showAndWait(); + if (opt.isPresent() && opt.get() == ButtonType.YES) { + return; + } + } catch (Throwable ignored) { + if (JOptionPane.showConfirmDialog( + null, i18n("prs.warning"), i18n("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE + ) == JOptionPane.OK_OPTION) { + return; + } + } + System.exit(1); + } +} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java index 54fdf0aa56..281a227a60 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java @@ -55,6 +55,8 @@ private Main() { } public static void main(String[] args) { + net.burningtnt.hmclprs.Hooks.onApplicationLaunch(); + System.setProperty("java.net.useSystemProxies", "true"); System.setProperty("javafx.autoproxy.disable", "true"); System.getProperties().putIfAbsent("http.agent", "HMCL/" + Metadata.VERSION); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index b011878a41..83053a9248 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1239,3 +1239,8 @@ wizard.prev=< Prev wizard.failed=Failed wizard.finish=Finish wizard.next=Next > + +prs.warning=You are using a non-official version of HMCL, which collects many features and bug fixes from the pull requests towards HMCL GitHub Repository.\n\ + The title of this application is still HMCL because the compatibility have to be kept. But DO REMEMBER THIS IS NOT AN OFFICIAL VERSION!\n\ + If you don't know why you are using this version, please close this applicatio immediately and download the official version!\n\ + You can continue using this application only if you are clear about this fact. If you have any problem, close this application immediately and go to https://github.com/huanghongxun/HMCL/pull/2608 for more information. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index eaed02d89d..f298adbc61 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -1097,3 +1097,8 @@ wizard.prev=< 上一步 wizard.failed=失敗 wizard.finish=完成 wizard.next=下一步 > + +prs.warning=你正在使用非官方的 HMCL 版本。本版本帶有很多來自 HMCL GitHub PR 的功能和錯誤修復。 \n\ + 本應用的名稱仍然為 HMCL,這是處於兼容性的考慮。 \n\ + 如果你不知道自己在做什麼,請立刻關閉本應用,並下載官方版本。 \n\ + 請僅在你已經確保理解了本段文字的情況下繼續使用本應用。如果你有任何問題,請立刻關閉本應用,可前往 https://github.com/huanghongxun/HMCL/pull/2608 獲取更多信息。 \ No newline at end of file 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 2c49d4e09e..7163cd4e1b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -1098,3 +1098,8 @@ wizard.prev=< 上一步 wizard.failed=失败 wizard.finish=完成 wizard.next=下一步 > + +prs.warning=你正在使用非官方的 HMCL 版本。本版本带有很多来自 HMCL GitHub PR 的功能和错误修复。\n\ + 本应用的名称仍然为 HMCL,这是处于兼容性的考虑。\n\ + 如果你不知道自己在做什么,请立刻关闭本应用,并下载官方版本。\n\ + 请仅在你已经确保理解了本段文字的情况下继续使用本应用。如果你有任何问题,请立刻关闭本应用,可前往 https://github.com/huanghongxun/HMCL/pull/2608 获取更多信息。