mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-18 08:16:58 -04:00
Warns user before launching
This commit is contained in:
parent
b707388134
commit
ccb1ff7f0e
@ -31,10 +31,7 @@ import org.jackhuang.hmcl.setting.LauncherVisibility;
|
|||||||
import org.jackhuang.hmcl.setting.Profile;
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
import org.jackhuang.hmcl.setting.Settings;
|
import org.jackhuang.hmcl.setting.Settings;
|
||||||
import org.jackhuang.hmcl.setting.VersionSetting;
|
import org.jackhuang.hmcl.setting.VersionSetting;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.*;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
|
||||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
|
||||||
import org.jackhuang.hmcl.task.TaskListener;
|
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.ui.DialogController;
|
import org.jackhuang.hmcl.ui.DialogController;
|
||||||
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
|
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
|
||||||
@ -58,7 +55,6 @@ public final class LauncherHelper {
|
|||||||
public void launch(String selectedVersion, File scriptFile) {
|
public void launch(String selectedVersion, File scriptFile) {
|
||||||
Profile profile = Settings.INSTANCE.getSelectedProfile();
|
Profile profile = Settings.INSTANCE.getSelectedProfile();
|
||||||
GameRepository repository = profile.getRepository();
|
GameRepository repository = profile.getRepository();
|
||||||
DefaultDependencyManager dependencyManager = profile.getDependency();
|
|
||||||
Account account = Settings.INSTANCE.getSelectedAccount();
|
Account account = Settings.INSTANCE.getSelectedAccount();
|
||||||
if (account == null)
|
if (account == null)
|
||||||
throw new IllegalStateException("No account");
|
throw new IllegalStateException("No account");
|
||||||
@ -66,8 +62,22 @@ public final class LauncherHelper {
|
|||||||
Version version = repository.getVersion(selectedVersion);
|
Version version = repository.getVersion(selectedVersion);
|
||||||
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
VersionSetting setting = profile.getVersionSetting(selectedVersion);
|
||||||
|
|
||||||
Controllers.dialog(launchingStepsPane);
|
try {
|
||||||
executor = Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.DEPENDENCIES))
|
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(dependencyManager.checkGameCompletionAsync(version))
|
||||||
.then(Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.MODS)))
|
.then(Task.of(Schedulers.javafx(), () -> emitStatus(LoadingState.MODS)))
|
||||||
.then(new CurseCompletionTask(dependencyManager, selectedVersion))
|
.then(new CurseCompletionTask(dependencyManager, selectedVersion))
|
||||||
@ -125,32 +135,45 @@ public final class LauncherHelper {
|
|||||||
executor.start();
|
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();
|
JavaVersion java = setting.getJavaVersion();
|
||||||
if (java == null) {
|
if (java == null) {
|
||||||
// TODO
|
Controllers.dialog(Main.i18n("launch.wrong_javadir"), Main.i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept);
|
||||||
return;
|
setting.setJava(null);
|
||||||
|
java = JavaVersion.fromCurrentEnvironment();
|
||||||
|
flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (java.getParsedVersion() < JavaVersion.JAVA_8) {
|
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 &&
|
if (java.getPlatform() == org.jackhuang.hmcl.util.Platform.BIT_32 &&
|
||||||
org.jackhuang.hmcl.util.Platform.IS_64_BIT) {
|
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 &&
|
if (java.getPlatform() == org.jackhuang.hmcl.util.Platform.BIT_32 &&
|
||||||
setting.getMaxMemory() > 1.5 * 1024) {
|
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()) {
|
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() {
|
public static void stopManagedProcesses() {
|
||||||
|
@ -154,6 +154,11 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
rightClickedVersion = version;
|
rightClickedVersion = version;
|
||||||
versionList.getSelectionModel().select(-1);
|
versionList.getSelectionModel().select(-1);
|
||||||
versionPopup.show(item, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY());
|
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);
|
File iconFile = profile.getRepository().getVersionIcon(version);
|
||||||
|
@ -139,6 +139,7 @@ lang=English
|
|||||||
lang.default=Belong to OS language.
|
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.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.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.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.
|
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.
|
||||||
|
@ -139,6 +139,7 @@ lang=简体中文
|
|||||||
lang.default=跟随系统语言
|
lang.default=跟随系统语言
|
||||||
|
|
||||||
launch.advice.different_platform=您的系统是64位的但是Java是32位的,推荐您安装64位Java.
|
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.newer_java=检测到您未使用Java 8及更新版本,Java 8能使游戏更流畅而且Minecraft 1.12及更新版本和很多Mod强制需要需要Java 8。
|
||||||
launch.advice.not_enough_space=您设置的内存大小过大,由于超过了系统内存大小%dMB,所以可能影响游戏体验或无法启动游戏,启动器仍会尝试启动。
|
launch.advice.not_enough_space=您设置的内存大小过大,由于超过了系统内存大小%dMB,所以可能影响游戏体验或无法启动游戏,启动器仍会尝试启动。
|
||||||
launch.advice.too_large_memory_for_32bit=您设置的内存大小过大,由于可能超过了32位Java的内存分配限制,所以可能无法启动游戏,请将内存调至1024MB或更小,启动器仍会尝试启动。
|
launch.advice.too_large_memory_for_32bit=您设置的内存大小过大,由于可能超过了32位Java的内存分配限制,所以可能无法启动游戏,请将内存调至1024MB或更小,启动器仍会尝试启动。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user