diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java index 913614d35..cd1510d37 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java @@ -34,6 +34,8 @@ import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.util.StringUtils; +import org.jackhuang.hmcl.util.i18n.I18n; +import org.jackhuang.hmcl.util.io.ResponseCodeException; import java.net.SocketTimeoutException; import java.util.Map; @@ -128,6 +130,13 @@ public final class InstallerWizardProvider implements WizardProvider { } else if (exception instanceof DownloadException) { if (exception.getCause() instanceof SocketTimeoutException) { Controllers.dialog(i18n("install.failed.downloading.timeout", ((DownloadException) exception).getUrl()), i18n("install.failed.downloading"), MessageType.ERROR, next); + } else if (exception.getCause() instanceof ResponseCodeException) { + ResponseCodeException responseCodeException = (ResponseCodeException) exception.getCause(); + if (I18n.hasKey("download.code." + responseCodeException.getResponseCode())) { + Controllers.dialog(i18n("download.code." + responseCodeException.getResponseCode()) + ", " + ((DownloadException) exception).getUrl() + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next); + } else { + Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next); + } } else { Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java index 47440a561..dc26351c6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/I18n.java @@ -57,4 +57,12 @@ public final class I18n { } } + public static boolean hasKey(String key) { + try { + getResourceBundle().getString(key); + return true; + } catch (MissingResourceException e) { + return false; + } + } } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 2f21821d3..4b27c5192 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -91,6 +91,7 @@ crash.NoClassDefFound=Please check "HMCL" software is complete. crash.user_fault=Your OS or Java environment may not be properly installed resulting in crashing of this software, please check your Java Environment or your computer! download=Download +download.code.404=File does not found in remote server download.failed=Failed to download download.failed.empty=No candidates. Click here to return. download.failed.refresh=Unable to load version list. Click here to retry. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index ce2333b36..5e0bbd84c 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -90,6 +90,7 @@ crash.NoClassDefFound=請確認 HMCL 本體是否完整,或更新您的 Java crash.user_fault=您的系統或 Java 環境可能安裝不當導致本軟體崩潰,請檢查您的 Java 環境或您的電腦!可以嘗試重新安裝 Java。 download=下載 +download.code.404=遠程伺服器不包含需要下載的文件 download.failed=下載失敗 download.failed.empty=沒有可供安裝的版本,點擊此處返回。 download.failed.refresh=載入版本列表失敗,點擊此處重試。 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 196b1925e..c9ad476cb 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -90,6 +90,7 @@ crash.NoClassDefFound=请确认 HMCL 本体是否完整,或更新您的 Java crash.user_fault=您的系统或 Java 环境可能安装不当导致本软件崩溃,请检查您的 Java 环境或您的电脑!可以尝试重新安装 Java。 download=下载 +download.code.404=远程服务器不包含需要下载的文件 download.failed=下载失败 download.failed.empty=没有可供安装的版本,点击此处返回。 download.failed.refresh=加载版本列表失败,点击此处重试。 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 7829d02b0..7f4f91ec8 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java @@ -21,10 +21,7 @@ import org.jackhuang.hmcl.event.EventManager; import org.jackhuang.hmcl.event.FailedEvent; 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; -import org.jackhuang.hmcl.util.io.NetworkUtils; +import org.jackhuang.hmcl.util.io.*; import java.io.File; import java.io.IOException; @@ -233,7 +230,7 @@ public class FileDownloadTask extends Task { repository.removeRemoteEntry(con); } } else if (con.getResponseCode() / 100 != 2) { - throw new IOException("Server error, response code: " + con.getResponseCode()); + throw new ResponseCodeException(currentURL, con.getResponseCode()); } int contentLength = con.getContentLength(); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/ResponseCodeException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/ResponseCodeException.java new file mode 100644 index 000000000..fba0c27e5 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/ResponseCodeException.java @@ -0,0 +1,41 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2019 huangyuhui and contributors + * + * 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 . + */ +package org.jackhuang.hmcl.util.io; + +import java.io.IOException; +import java.net.URL; + +public class ResponseCodeException extends IOException { + + private final URL url; + private final int responseCode; + + public ResponseCodeException(URL url, int responseCode) { + super("Unable to request url " + url + ", response code: " + responseCode); + this.url = url; + this.responseCode = responseCode; + } + + public URL getUrl() { + return url; + } + + public int getResponseCode() { + return responseCode; + } +}