From 9c7795687fd16b3d953ea6691736174f35f8e51e Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sun, 25 Nov 2018 17:00:12 +0800 Subject: [PATCH] Show installation succeeded when Curse modpack not finished completion --- .../ModpackInstallWizardProvider.java | 26 +++++++++++--- .../VanillaInstallWizardProvider.java | 16 +++++++-- .../TaskExecutorDialogWizardDisplayer.java | 4 ++- .../hmcl/ui/wizard/WizardProvider.java | 4 +++ .../resources/assets/lang/I18N.properties | 2 ++ .../resources/assets/lang/I18N_zh.properties | 2 ++ .../assets/lang/I18N_zh_CN.properties | 2 ++ .../hmcl/task/DownloadException.java | 36 +++++++++++++++++++ .../jackhuang/hmcl/task/FileDownloadTask.java | 5 +-- .../java/org/jackhuang/hmcl/task/GetTask.java | 3 +- 10 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/task/DownloadException.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java index c907252ee..c4ee265e7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java @@ -1,18 +1,21 @@ package org.jackhuang.hmcl.ui.download; -import javafx.application.Platform; import javafx.scene.Node; -import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.game.ModpackHelper; +import org.jackhuang.hmcl.mod.CurseCompletionException; import org.jackhuang.hmcl.mod.Modpack; import org.jackhuang.hmcl.setting.Profile; -import org.jackhuang.hmcl.setting.Profiles; +import org.jackhuang.hmcl.task.DownloadException; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; +import org.jackhuang.hmcl.ui.Controllers; +import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardProvider; +import org.jackhuang.hmcl.util.StringUtils; import java.io.File; +import java.io.FileNotFoundException; import java.util.Map; import static org.jackhuang.hmcl.util.Lang.tryCast; @@ -54,7 +57,22 @@ public class ModpackInstallWizardProvider implements WizardProvider { @Override public Object finish(Map settings) { settings.put("success_message", i18n("install.success")); - settings.put("failure_message", i18n("install.failed")); + settings.put("failure_callback", new FailureCallback() { + @Override + public void onFail(Map settings, Exception exception, Runnable next) { + if (exception instanceof CurseCompletionException) { + if (exception.getCause() instanceof FileNotFoundException) { + Controllers.dialog(i18n("modpack.type.curse.not_found"), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); + } else { + Controllers.dialog(i18n("modpack.type.curse.tolerable_error"), i18n("install.success"), MessageBox.INFORMATION_MESSAGE, next); + } + } else if (exception instanceof DownloadException) { + Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); + } else { + Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); + } + } + }); return finishModpackInstallingAsync(settings); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VanillaInstallWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VanillaInstallWizardProvider.java index f82fb61d1..9cf394af8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VanillaInstallWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VanillaInstallWizardProvider.java @@ -22,11 +22,14 @@ import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.GameBuilder; import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.setting.Profile; -import org.jackhuang.hmcl.setting.Profiles; +import org.jackhuang.hmcl.task.DownloadException; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; +import org.jackhuang.hmcl.ui.Controllers; +import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardProvider; +import org.jackhuang.hmcl.util.StringUtils; import java.util.Map; @@ -67,7 +70,16 @@ public final class VanillaInstallWizardProvider implements WizardProvider { @Override public Object finish(Map settings) { settings.put("success_message", i18n("install.success")); - settings.put("failure_message", i18n("install.failed")); + settings.put("failure_callback", new FailureCallback() { + @Override + public void onFail(Map settings, Exception exception, Runnable next) { + if (exception instanceof DownloadException) { + Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); + } else { + Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); + } + } + }); return finishVersionDownloadingAsync(settings); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java index 9eb6f717d..1b89f647d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java @@ -74,7 +74,9 @@ public interface TaskExecutorDialogWizardDisplayer extends AbstractWizardDisplay if (executor.getLastException() == null) return; String appendix = StringUtils.getStackTrace(executor.getLastException()); - if (settings.containsKey("failure_message") && settings.get("failure_message") instanceof String) + if (settings.get("failure_callback") instanceof WizardProvider.FailureCallback) + ((WizardProvider.FailureCallback)settings.get("failure_callback")).onFail(settings, executor.getLastException(), () -> onEnd()); + else if (settings.get("failure_message") instanceof String) Controllers.dialog(appendix, (String) settings.get("failure_message"), MessageBox.ERROR_MESSAGE, () -> onEnd()); else if (!settings.containsKey("forbid_failure_message")) Controllers.dialog(appendix, i18n("wizard.failed"), MessageBox.ERROR_MESSAGE, () -> onEnd()); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/WizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/WizardProvider.java index 58b23b6ba..7c45a2957 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/WizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/WizardProvider.java @@ -26,4 +26,8 @@ public interface WizardProvider { Object finish(Map settings); Node createPage(WizardController controller, int step, Map settings); boolean cancel(); + + interface FailureCallback { + void onFail(Map settings, Exception exception, Runnable next); + } } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 16a8b621b..eb0007dd4 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -120,6 +120,7 @@ input.url=Must be a valid URL. install=Install New Game install.failed=Failed to install +install.failed.downloading=Failed to install due to some files not downloaded successfully install.installer.choose=Choose a %s version install.installer.forge=Forge install.installer.game=Game @@ -223,6 +224,7 @@ modpack.task.install.error=This modpack file cannot be recognized. Only Curse, M modpack.task.install.will=Install the modpack: modpack.type.curse=Curse modpack.type.curse.completion=Install relative files to Curse modpack +modpack.type.curse.tolerable_error=But we cannot complete downloading all files of this Curse modpack. You can retry downloading when launching corresponding game version. You may retry for a couple of times due to network problems. modpack.type.curse.error=Unable to complete this Curse modpack. Please retry. modpack.type.curse.not_found=Some of required resources are deleted and cannot be downloaded. Please consider the latest version or other modpacks. modpack.type.hmcl=HMCL diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 8892bb495..1002bd4ed 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -120,6 +120,7 @@ input.url=必須為有效連結 install=新增遊戲 install.failed=安裝失敗 +install.failed.downloading=安裝失敗,部分文件未能完成下載 install.installer.choose=選擇 %s 版本 install.installer.forge=Forge install.installer.game=遊戲 @@ -223,6 +224,7 @@ modpack.task.install.error=無法識別該整合包,目前僅支持導入 Curs modpack.task.install.will=將會安裝整合包: modpack.type.curse=Curse modpack.type.curse.completion=下載 Curse 整合包相關檔案 +modpack.type.curse.tolerable_error=但未能完成 Curse 整合包文件的下載,您可以在啟動該遊戲版本時繼續 Curse 整合包文件的下載。由於網路問題,您可能需要重試多次。 modpack.type.curse.error=無法完成 Curse 整合包的下載,請多次重試或設定代理 modpack.type.curse.not_found=部分必需檔案已經從網路中被刪除並且再也無法下載,請嘗試該整合包的最新版本或者安裝其他整合包。 modpack.type.hmcl=HMCL 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 b51f5bc23..14d6cf727 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -120,6 +120,7 @@ input.url=必须是合法的链接 install=添加游戏 install.failed=安装失败 +install.failed.downloading=安装失败,部分文件未能完成下载 install.installer.choose=选择 %s 版本 install.installer.forge=Forge install.installer.game=游戏 @@ -223,6 +224,7 @@ modpack.task.install.error=无法识别该整合包,目前仅支持导入 Curs modpack.task.install.will=将会安装整合包: modpack.type.curse=Curse modpack.type.curse.completion=下载 Curse 整合包相关文件 +modpack.type.curse.tolerable_error=但未能完成 Curse 整合包文件的下载,您可以在启动该游戏版本时继续 Curse 整合包文件的下载。由于网络问题,您可能需要重试多次。 modpack.type.curse.error=未能完成 Curse 整合包的下载,请多次重试或设置代理 modpack.type.curse.not_found=部分必需文件已经在网络中被删除并且再也无法下载,请尝试该整合包的最新版本或者安装其他整合包。 modpack.type.hmcl=HMCL diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/DownloadException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/DownloadException.java new file mode 100644 index 000000000..53bc9140c --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/DownloadException.java @@ -0,0 +1,36 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2018 huangyuhui + * + * 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 {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.task; + +import java.io.IOException; +import java.net.URL; + +public class DownloadException extends IOException { + + private final URL url; + + public DownloadException(URL url, Throwable cause) { + super("Unable to download " + url + ", " + cause.getMessage(), cause); + + this.url = url; + } + + public URL getUrl() { + return url; + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java index eaec71491..39f0c123f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java @@ -19,7 +19,8 @@ package org.jackhuang.hmcl.task; import org.jackhuang.hmcl.event.EventManager; import org.jackhuang.hmcl.event.FailedEvent; -import org.jackhuang.hmcl.util.*; +import org.jackhuang.hmcl.util.CacheRepository; +import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.io.ChecksumMismatchException; import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.IOUtils; @@ -328,7 +329,7 @@ public class FileDownloadTask extends Task { } if (exception != null) - throw new IOException("Unable to download file " + currentURL + ". " + exception.getMessage(), exception); + throw new DownloadException(currentURL, exception); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/GetTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/GetTask.java index 14920b760..83bf0159f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/GetTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/GetTask.java @@ -29,7 +29,6 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; -import java.nio.file.Files; import java.nio.file.Path; import java.util.logging.Level; @@ -141,7 +140,7 @@ public final class GetTask extends TaskResult { } } if (exception != null) - throw exception; + throw new DownloadException(url, exception); } /**