Unable to launch dialog

This commit is contained in:
huangyuhui 2018-02-02 10:46:27 +08:00
parent cec8249b24
commit 7ea2b57ece
8 changed files with 57 additions and 21 deletions

View File

@ -98,9 +98,9 @@ public final class LauncherHelper {
}))
.then(variables -> {
if (scriptFile == null) {
return variables.<DefaultLauncher>get("launcher").launchAsync().setName("version.launch");
return variables.<DefaultLauncher>get("launcher").launchAsync().setName(Main.i18n("version.launch"));
} else {
return variables.<DefaultLauncher>get("launcher").makeLaunchScriptAsync(scriptFile).setName("version.launch");
return variables.<DefaultLauncher>get("launcher").makeLaunchScriptAsync(scriptFile).setName(Main.i18n("version.launch"));
}
})
.then(Task.of(variables -> {
@ -128,7 +128,9 @@ public final class LauncherHelper {
@Override
public void onTerminate() {
Controllers.closeDialog();
Platform.runLater(() -> {
Controllers.dialog(StringUtils.getStackTrace(executor.getLastException()), Main.i18n("launch.failed"), MessageBox.ERROR_MESSAGE, Controllers::closeDialog);
});
}
});

View File

@ -24,7 +24,7 @@ public enum LoadingState {
MODS("launch.state.modpack"),
LOGGING_IN("launch.state.logging_in"),
LAUNCHING("launch.state.waiting_launching"),
DONE("");
DONE("launch.state.done");
private final String key;

View File

@ -144,7 +144,7 @@ launch.advice.newer_java=Java 8 is suggested, which can make game run more fluen
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.circular_dependency_versions=Found circular dependency versions, please check if your client has been modified.
launch.failed=Failed to launch.
launch.failed=Unable to launch
launch.failed.cannot_create_jvm=We find that it cannot create java virutal machine. The Java argements may have problems. You can enable the no args mode in the settings.
launch.failed.decompressing_natives=Did not finish decompressing native libraries, continue launching game?
launch.failed.downloading_libraries=Did not finish downloading libraries, continue launching game?
@ -153,6 +153,7 @@ launch.failed.packing_jar=Failed to pack the jar.
launch.failed.sh_permission=Failed to add permission to the launch script.
launch.failed_creating_process=Failed to create process, maybe your java path is wrong, please modify your java path.
launch.state.dependencies=Decompressing natives
launch.state.done=Done
launch.state.logging_in=Logging In
launch.state.modpack=Preparing for modpack
launch.state.waiting_launching=Waiting for game launching

View File

@ -153,6 +153,7 @@ launch.failed.packing_jar=在打包jar时发生错误
launch.failed.sh_permission=为启动文件添加权限时发生错误
launch.failed_creating_process=启动失败在创建新进程时发生错误可能是Java路径错误。
launch.state.dependencies=正在处理游戏依赖
launch.state.done=启动完成
launch.state.logging_in=登录中
launch.state.modpack=正在下载必要文件
launch.state.waiting_launching=等待游戏启动

View File

@ -53,10 +53,12 @@ final class CoupleTask<P extends Task> extends Task {
this.failIfDependentsFail = failIfDependentsFail;
setSignificance(TaskSignificance.MODERATE);
setName(succ.toString());
}
@Override
public void execute() throws Exception {
setName(succ.toString());
Task task = succ.apply(getVariables());
if (task != null)
dependencies.add(task);

View File

@ -29,18 +29,16 @@ class SimpleTask extends Task {
private final ExceptionalConsumer<AutoTypingMap<String>, ?> consumer;
private final Scheduler scheduler;
public SimpleTask(String name, ExceptionalConsumer<AutoTypingMap<String>, ?> consumer) {
this(name, consumer, Schedulers.defaultScheduler());
}
public SimpleTask(String name, ExceptionalConsumer<AutoTypingMap<String>, ?> consumer, Scheduler scheduler) {
this.consumer = consumer;
this.scheduler = scheduler;
if (name == null)
if (name == null) {
setSignificance(TaskSignificance.MINOR);
else
setName(consumer.toString());
} else {
setName(name);
}
}
@Override

View File

@ -233,7 +233,7 @@ public abstract class Task {
}
public final TaskExecutor subscribe(Scheduler scheduler, ExceptionalRunnable<?> closure) {
return subscribe(of(scheduler, i -> closure.run()));
return subscribe(of(scheduler, ExceptionalConsumer.fromRunnable(closure)));
}
public final TaskExecutor subscribe(ExceptionalConsumer<AutoTypingMap<String>, ?> closure) {
@ -245,7 +245,7 @@ public abstract class Task {
}
public final Task then(Task b) {
return then(s -> b);
return then(convert(b));
}
public final Task then(ExceptionalFunction<AutoTypingMap<String>, Task, ?> b) {
@ -253,15 +253,15 @@ public abstract class Task {
}
public final Task with(Task b) {
return with(s -> b);
return with(convert(b));
}
public final Task with(ExceptionalFunction<AutoTypingMap<String>, Task, ?> b) {
public final <E extends Exception> Task with(ExceptionalFunction<AutoTypingMap<String>, Task, E> b) {
return new CoupleTask<>(this, b, false, false);
}
public final Task finalized(Task b) {
return finalized(s -> b);
return finalized(convert(b));
}
public final Task finalized(ExceptionalFunction<AutoTypingMap<String>, Task, ?> b) {
@ -269,16 +269,15 @@ public abstract class Task {
}
public static Task empty() {
return of(s -> {
});
return of(ExceptionalConsumer.empty());
}
public static Task of(String name, ExceptionalRunnable<?> runnable) {
return of(name, s -> runnable.run());
return of(name, ExceptionalConsumer.fromRunnable(runnable));
}
public static Task of(ExceptionalRunnable<?> runnable) {
return of(s -> runnable.run());
return of(ExceptionalConsumer.fromRunnable(runnable));
}
public static Task of(String name, ExceptionalConsumer<AutoTypingMap<String>, ?> closure) {
@ -298,7 +297,7 @@ public abstract class Task {
}
public static Task of(String name, Scheduler scheduler, ExceptionalRunnable<?> closure) {
return new SimpleTask(name, i -> closure.run(), scheduler);
return new SimpleTask(name, ExceptionalConsumer.fromRunnable(closure), scheduler);
}
public static Task of(Scheduler scheduler, ExceptionalRunnable<?> closure) {
@ -313,6 +312,20 @@ public abstract class Task {
return new TaskCallable2<>(id, closure);
}
private static ExceptionalFunction<AutoTypingMap<String>, Task, ?> convert(Task t) {
return new ExceptionalFunction<AutoTypingMap<String>, Task, Exception>() {
@Override
public Task apply(AutoTypingMap<String> autoTypingMap) {
return t;
}
@Override
public String toString() {
return t.getName();
}
};
}
public enum TaskSignificance {
MAJOR,
MODERATE,

View File

@ -22,4 +22,23 @@ package org.jackhuang.hmcl.util;
*/
public interface ExceptionalConsumer<T, E extends Exception> {
void accept(T t) throws E;
static <T, E extends Exception> ExceptionalConsumer<T, E> fromRunnable(ExceptionalRunnable<E> runnable) {
return new ExceptionalConsumer<T, E>() {
@Override
public void accept(T o) throws E {
runnable.run();
}
@Override
public String toString() {
return runnable.toString();
}
};
}
static <T> ExceptionalConsumer<T, ?> empty() {
return s -> {
};
}
}