diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index 7a4d87fec..98bd128c8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -31,10 +31,7 @@ import org.jackhuang.hmcl.setting.LauncherVisibility; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Settings; import org.jackhuang.hmcl.setting.VersionSetting; -import org.jackhuang.hmcl.task.Schedulers; -import org.jackhuang.hmcl.task.Task; -import org.jackhuang.hmcl.task.TaskExecutor; -import org.jackhuang.hmcl.task.TaskListener; +import org.jackhuang.hmcl.task.*; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.DialogController; import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane; @@ -58,7 +55,6 @@ public final class LauncherHelper { public void launch(String selectedVersion, File scriptFile) { Profile profile = Settings.INSTANCE.getSelectedProfile(); GameRepository repository = profile.getRepository(); - DefaultDependencyManager dependencyManager = profile.getDependency(); Account account = Settings.INSTANCE.getSelectedAccount(); if (account == null) throw new IllegalStateException("No account"); @@ -66,8 +62,22 @@ public final class LauncherHelper { Version version = repository.getVersion(selectedVersion); VersionSetting setting = profile.getVersionSetting(selectedVersion); - Controllers.dialog(launchingStepsPane); - executor = Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.DEPENDENCIES)) + try { + checkGameState(profile, setting, version, () -> launch0(selectedVersion, scriptFile)); + } catch (InterruptedException ignore) { + } + } + + private void launch0(String selectedVersion, File scriptFile) { + Profile profile = Settings.INSTANCE.getSelectedProfile(); + GameRepository repository = profile.getRepository(); + DefaultDependencyManager dependencyManager = profile.getDependency(); + Version version = repository.getVersion(selectedVersion); + Account account = Settings.INSTANCE.getSelectedAccount(); + VersionSetting setting = profile.getVersionSetting(selectedVersion); + + executor = Task.of(Schedulers.javafx(), () -> Controllers.dialog(launchingStepsPane)) + .then(Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.DEPENDENCIES))) .then(dependencyManager.checkGameCompletionAsync(version)) .then(Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.MODS))) .then(new CurseCompletionTask(dependencyManager, selectedVersion)) @@ -125,32 +135,45 @@ public final class LauncherHelper { executor.start(); } - private void checkGameState(VersionSetting setting) throws InterruptedException { + private static void checkGameState(Profile profile, VersionSetting setting, Version version, Runnable onAccept) throws InterruptedException { + boolean flag = false; + + VersionNumber gameVersion = VersionNumber.asVersion(GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version))); JavaVersion java = setting.getJavaVersion(); if (java == null) { - // TODO - return; + Controllers.dialog(Main.i18n("launch.wrong_javadir"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + setting.setJava(null); + java = JavaVersion.fromCurrentEnvironment(); + flag = true; } if (java.getParsedVersion() < JavaVersion.JAVA_8) { - MessageBox.show(Main.i18n("launch.advice.newer_java")); + Controllers.dialog(Main.i18n("launch.advice.newer_java"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + flag = true; } - if (java.getParsedVersion() >= JavaVersion.JAVA_9) { - + if (java.getParsedVersion() >= JavaVersion.JAVA_9 && gameVersion.compareTo(VersionNumber.asVersion("1.12.5")) < 0 && version.getMainClass().contains("launchwrapper")) { + Controllers.dialog(Main.i18n("launch.advice.java9"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, null); + flag = true; } if (java.getPlatform() == org.jackhuang.hmcl.util.Platform.BIT_32 && org.jackhuang.hmcl.util.Platform.IS_64_BIT) { - MessageBox.show(Main.i18n("launch.advice.different_platform")); + Controllers.dialog(Main.i18n("launch.advice.different_platform"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + flag = true; } if (java.getPlatform() == org.jackhuang.hmcl.util.Platform.BIT_32 && setting.getMaxMemory() > 1.5 * 1024) { - MessageBox.show(Main.i18n("launch.advice.too_large_memory_for_32bit")); + Controllers.dialog(Main.i18n("launch.advice.too_large_memory_for_32bit"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + flag = true; } if (OperatingSystem.TOTAL_MEMORY > 0 && OperatingSystem.TOTAL_MEMORY < setting.getMaxMemory()) { - MessageBox.show(Main.i18n("launch.advice.not_enough_space")); + Controllers.dialog(Main.i18n("launch.advice.not_enough_space", OperatingSystem.TOTAL_MEMORY), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + flag = true; } + + if (!flag) + onAccept.run(); } public static void stopManagedProcesses() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java index 35ddac36a..32e4c39f8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java @@ -154,6 +154,11 @@ public final class MainPage extends StackPane implements DecoratorPage { rightClickedVersion = version; versionList.getSelectionModel().select(-1); versionPopup.show(item, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); + } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { + if (Settings.INSTANCE.getSelectedAccount() == null) + Controllers.dialog(Main.i18n("login.empty_username")); + else + LauncherHelper.INSTANCE.launch(version, null); } }); File iconFile = profile.getRepository().getVersionIcon(version); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 47ec2c658..d547fa960 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -139,6 +139,7 @@ lang=English lang.default=Belong to OS language. launch.advice.different_platform=Your OS is 64-Bit but your Java is 32-Bit. The 64-Bit Java is recommended. +launch.advice.java9=You cannot launch Minecraft until game version is higher than 1.13 with Java 9 or newer Java version. launch.advice.newer_java=Java 8 is suggested, which can make game run more fluently. And many mods and Minecraft 1.12 and newer versions requires Java 8. launch.advice.not_enough_space=You have allocated too much memory, because the physical memory size is %dMB, your game probably crash. The launcher will try to launch it. launch.advice.too_large_memory_for_32bit=You have allocated too much memory, because of your 32-Bit Java Runtime Environment, your game probably crash. The maximum memory is 1024MB. The launcher will try to launch it. 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 9931601da..029aaf64b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -139,6 +139,7 @@ lang=简体中文 lang.default=跟随系统语言 launch.advice.different_platform=您的系统是64位的但是Java是32位的,推荐您安装64位Java. +launch.advice.java9=不高于1.13的Minecraft不支持Java 9或更高版本,请使用Java 8. launch.advice.newer_java=检测到您未使用Java 8及更新版本,Java 8能使游戏更流畅而且Minecraft 1.12及更新版本和很多Mod强制需要需要Java 8。 launch.advice.not_enough_space=您设置的内存大小过大,由于超过了系统内存大小%dMB,所以可能影响游戏体验或无法启动游戏,启动器仍会尝试启动。 launch.advice.too_large_memory_for_32bit=您设置的内存大小过大,由于可能超过了32位Java的内存分配限制,所以可能无法启动游戏,请将内存调至1024MB或更小,启动器仍会尝试启动。