Skip to content

Commit 0e433c5

Browse files
authored
启动时检测 Wine 环境并进行警告 (#5518)
1 parent a28509d commit 0e433c5

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jackhuang.hmcl.util.io.JarUtils;
2626
import org.jackhuang.hmcl.util.platform.OperatingSystem;
2727

28+
import javax.swing.JOptionPane;
2829
import java.io.IOException;
2930
import java.lang.invoke.MethodHandle;
3031
import java.lang.invoke.MethodHandles;
@@ -49,6 +50,8 @@ public static void main(String[] args) {
4950
createHMCLDirectories();
5051
LOG.start(Metadata.HMCL_CURRENT_DIRECTORY.resolve("logs"));
5152

53+
checkWine();
54+
5255
setupJavaFXVMOptions();
5356

5457
if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
@@ -220,6 +223,20 @@ private static void verifyJavaFX() {
220223
}
221224
}
222225

226+
private static void checkWine() {
227+
if (OperatingSystem.isRunningUnderWine()) {
228+
SwingUtils.initLookAndFeel();
229+
LOG.warning("HMCL is running under Wine or its distributions!");
230+
231+
int result = JOptionPane.showOptionDialog(null, i18n("fatal.wine_warning"), i18n("message.warning"), JOptionPane.OK_CANCEL_OPTION,
232+
JOptionPane.WARNING_MESSAGE, null, null, null);
233+
234+
if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
235+
exit(1);
236+
}
237+
}
238+
}
239+
223240
private static void addEnableNativeAccess() {
224241
if (JavaRuntime.CURRENT_VERSION > 21) {
225242
try {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ fatal.unsupported_platform.windows_arm64=Hello Minecraft! Launcher has provided
458458
\n\
459459
If you are using the <b>Qualcomm</b> platform, you may need to install the <a href="ms-windows-store://pdp/?productid=9NQPSL29BFFF">OpenGL Compatibility Pack</a> before playing games.\n\
460460
Click the link to navigate to the Microsoft Store and install the compatibility pack.
461+
# When translating the following string into non-Latin languages, please retain the English translation
462+
fatal.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.
461463

462464
file=File
463465

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ fatal.unsupported_platform=Minecraft 尚未對您的平臺提供完善支援,
421421
fatal.unsupported_platform.loongarch=Hello Minecraft! Launcher 已為龍芯提供支援。\n如果遇到問題,你可以點擊右上角幫助按鈕進行求助。
422422
fatal.unsupported_platform.macos_arm64=Hello Minecraft! Launcher 已為 Apple Silicon 平臺提供支援。使用 ARM 原生 Java 啟動遊戲以獲得更流暢的遊戲體驗。\n如果你在遊戲中遭遇問題,使用 x86-64 架構的 Java 啟動遊戲可能有更好的相容性。
423423
fatal.unsupported_platform.windows_arm64=Hello Minecraft! Launcher 已為 Windows on Arm 平臺提供原生支援。如果你在遊戲中遭遇問題,請嘗試使用 x86 架構的 Java 啟動遊戲。\n\n如果你正在使用<b>高通</b>平臺,你可能需要安裝 <a href="ms-windows-store://pdp/?productid=9NQPSL29BFFF">OpenGL 相容包</a>後才能進行遊戲。點擊連結前往 Microsoft Store 安裝相容包。
424+
# When translating the following string into non-Latin languages, please retain the English translation
425+
fatal.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按下「確定」以繼續,但請注意,此操作可能會引發一些問題。
424426

425427
file=檔案
426428

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ fatal.unsupported_platform=Minecraft 尚未对你的平台提供完善支持,
425425
fatal.unsupported_platform.loongarch=Hello Minecraft! Launcher 已为龙芯提供支持。\n如果遇到问题,你可以点击右上角帮助按钮进行求助。
426426
fatal.unsupported_platform.macos_arm64=Hello Minecraft! Launcher 已为 Apple Silicon 平台提供支持。使用 ARM 原生 Java 启动游戏以获得更流畅的游戏体验。\n如果你在游戏中遇到问题,使用 x86-64 架构的 Java 启动游戏可能有更好的兼容性。\n如遇到问题,你可以点击右上角帮助按钮进行求助。
427427
fatal.unsupported_platform.windows_arm64=Hello Minecraft! Launcher 已为 Windows on Arm 平台提供原生支持。如果你在游戏中遇到问题,请尝试使用 x86 架构的 Java 启动游戏。\n如果你正在使用 <b>高通</b> 平台,你可能需要安装 <a href="ms-windows-store://pdp/?productid=9NQPSL29BFFF">OpenGL 兼容包</a> 后才能进行游戏。点击链接前往 Microsoft Store 安装兼容包。\n如遇到问题,你可以点击右上角帮助按钮进行求助。
428+
# When translating the following string into non-Latin languages, please retain the English translation
429+
fatal.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按下“确定”以继续,但请注意,此操作可能会引发一些问题。
428430

429431
file=文件
430432

HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,25 @@ public static boolean isWindows7OrLater() {
282282
return SYSTEM_VERSION.isAtLeast(OSVersion.WINDOWS_7);
283283
}
284284

285+
public static boolean isRunningUnderWine() {
286+
if (OperatingSystem.CURRENT_OS != OperatingSystem.WINDOWS) {
287+
return false;
288+
}
289+
290+
String[] wineEnvVars = {
291+
"WINEPREFIX",
292+
"WINELOADER",
293+
"WINEDLLPATH"
294+
};
295+
296+
for (String var : wineEnvVars) {
297+
if (System.getenv(var) != null) {
298+
return true;
299+
}
300+
}
301+
return false;
302+
}
303+
285304
public static Path getWorkingDirectory(String folder) {
286305
String home = System.getProperty("user.home", ".");
287306
switch (OperatingSystem.CURRENT_OS) {

0 commit comments

Comments
 (0)