Skip to content
Merged
19 changes: 19 additions & 0 deletions HMCLBoot/src/main/java/org/jackhuang/hmcl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jackhuang.hmcl;

import org.jackhuang.hmcl.util.SwingUtils;
import org.jackhuang.hmcl.util.WineDetector;

import javax.swing.*;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -125,6 +126,23 @@ private static void checkDirectoryPath() {
}
}

private static void checkWine() {
if (WineDetector.isRunningUnderWine()) {
SwingUtils.initLookAndFeel();
ResourceBundle resourceBundle = BootProperties.getResourceBundle();
String warningTitle = resourceBundle.getString("boot.message.warning");
String warningMessage = resourceBundle.getString("boot.wine_warning");
System.err.println("HMCL is running under Wine or its distributions! It's not recommended!");

int result = JOptionPane.showOptionDialog(null, warningMessage, warningTitle, JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE, null, null, null);

if (result == JOptionPane.CANCEL_OPTION) {
System.exit(1);
}
}
}

private static String getThisJarPath() {
ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
if (protectionDomain == null)
Expand All @@ -143,6 +161,7 @@ private static String getThisJarPath() {

public static void main(String[] args) throws Throwable {
checkDirectoryPath();
checkWine();
if (getJavaFeatureVersion(System.getProperty("java.version")) >= MINIMUM_JAVA_VERSION) {
EntryPoint.main(args);
} else {
Expand Down
57 changes: 57 additions & 0 deletions HMCLBoot/src/main/java/org/jackhuang/hmcl/util/WineDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> 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 <https://www.gnu.org/licenses/>.
*/

package org.jackhuang.hmcl.util;

public final class WineDetector {
public static boolean isRunningUnderWine() {
String osName = System.getProperty("os.name", "");
if (!osName.toLowerCase(java.util.Locale.ROOT).contains("win")) {
return false;
}

return checkWineRegistryKey() && checkWineEnv();
}

private static boolean checkWineRegistryKey() {
Process process = null;
try {
process = Runtime.getRuntime().exec(
new String[]{"reg", "query", "HKLM\\Software\\Wine", "/reg:64"}
);
if (!process.waitFor(800, java.util.concurrent.TimeUnit.MILLISECONDS)) {
process.destroyForcibly();
return false;
}
return process.exitValue() == 0;
} catch (Exception e) {
return false;
} finally {
if (process != null && process.isAlive()) {
process.destroy();
}
}
}

private static boolean checkWineEnv() {
return System.getenv("WINEPREFIX") != null;
}

private WineDetector() {
}
}
4 changes: 3 additions & 1 deletion HMCLBoot/src/main/resources/assets/lang/boot.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@

boot.unsupported_java_version=HMCL requires Java 17 or later to run, but still supports launching games with Java 6~16. Please install the latest version of Java and try opening HMCL again.\nYou can keep your old version of Java. HMCL can detect and manage multiple Java installations, and will automatically select the appropriate Java version for your game.
boot.manual_update=HMCL cannot complete automatic updates in the current environment. Please download the latest version of HMCL manually.\nWould you like to go to the download page?
boot.wine_warning=HMCL is running under Wine or one of its distributions.\nAs a cross-platform application, HMCL is best experienced natively on your host OS.\nPress “OK” to continue, but please note that some issues may arise.
Comment thread
WhatDamon marked this conversation as resolved.
Outdated

boot.message.error=Error
boot.message.error=Error
boot.message.warning=Warning
4 changes: 3 additions & 1 deletion HMCLBoot/src/main/resources/assets/lang/boot_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@

boot.unsupported_java_version=HMCL 需要 Java 17 或更高版本才能运行,但依然支持使用 Java 6~16 启动游戏。请安装最新版本的 Java 再尝试启动 HMCL。\n你可以继续保留旧版本 Java。HMCL 能够识别与管理多个 Java,并会自动根据游戏版本为你选择合适的 Java。\n你可以访问 https://docs.hmcl.net/help.html 页面寻求帮助。
boot.manual_update=HMCL 在当前环境无法完成自动更新,请手动下载最新版本的 HMCL。\n是否前往下载页面?
boot.wine_warning=HMCL is running under Wine or one of its distributions.\nAs a cross-platform application, HMCL is best experienced natively on your host OS.\nPress “OK” to continue, but please note that some issues may arise.\n\n您目前正在使用 Wine 或其发行版运行 HMCL。\nHMCL 是跨平台的,我们建议您直接在宿主系统上运行。\n按下 “确定” 以继续,但它可能会遇到一些问题。
Comment thread
WhatDamon marked this conversation as resolved.
Outdated

boot.message.error=错误
boot.message.error=错误
boot.message.warning=警告
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@

boot.unsupported_java_version=HMCL 需要 Java 17 或更高版本才能執行,但依然支援使用 Java 6~16 啟動遊戲。請安裝最新版本的 Java 再嘗試開啟 HMCL。\n你可以繼續保留舊版本 Java。HMCL 能夠識別與管理多個 Java,並會自動根據遊戲版本為你選取合適的 Java。
boot.manual_update=HMCL 在當前環境無法完成自動更新,請手動下載最新版本的 HMCL。\n是否前往下載頁面?
boot.wine_warning=HMCL is running under Wine or one of its distributions.\nAs a cross-platform application, HMCL is best experienced natively on your host OS.\nPress “OK” to continue, but please note that some issues may arise.\n\n您目前正在使用 Wine 或其衍生版本執行 HMCL。\nHMCL 是跨平臺的,我們建議您直接在主機系統上執行。\n按下 “確定” 以繼續,但它可能會遇到一些問題。
Comment thread
WhatDamon marked this conversation as resolved.
Outdated

boot.message.error=錯誤
boot.message.warning=警告