From 0ebeffac32f08fed74eb610a5d78dca3e04e188d Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sun, 17 Oct 2021 15:13:42 +0800 Subject: [PATCH] feat: improve error message for AccessDeniedException. Mentioned in #1114. --- .../main/java/org/jackhuang/hmcl/game/LauncherHelper.java | 3 +++ HMCL/src/main/resources/assets/lang/I18N.properties | 5 ++++- HMCL/src/main/resources/assets/lang/I18N_zh.properties | 5 ++++- HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties | 5 ++++- 4 files changed, 15 insertions(+), 3 deletions(-) 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 707fa1972..778460ae3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -59,6 +59,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.SocketTimeoutException; import java.net.URL; +import java.nio.file.AccessDeniedException; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -299,6 +300,8 @@ public final class LauncherHelper { ); return; + } else if (ex instanceof AccessDeniedException) { + message = i18n("exception.access_denied", ((AccessDeniedException) ex).getFile()); } else { message = StringUtils.getStackTrace(ex); } diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 5a4ba7df6..6d57dab03 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -289,6 +289,10 @@ download.javafx.notes=Downloading necessary components for HMCL through network. download.javafx.component=Downloading the module %s download.javafx.prepare=Ready to download +exception.access_denied=It's denied by operating system to access file %s. Maybe we don't have permission to access this file, or this file has already been opened by other program.\n\ + Please check if current operating system user has permission to access that file.\n\ + For Windows users, you can also try the Resource Monitor, find if some programs is holding the file, try to close related program, or restart your computer. + extension.bat=Windows Bat file extension.mod=Mod file extension.png=Image file @@ -401,7 +405,6 @@ install.change_version=Change version install.change_version.confirm=Are you sure you want to update %s from verison %s to %s? install.failed=Version failed to install install.failed.downloading=Failed to install due to some files not downloaded successfully -install.failed.downloading.access_denied=Failed to download file: %1$s. Because it's denied by operating system to access file %2$s. Maybe we don't have permission to access this file, or this file has already been opened by other program. You can try to close related program, or restart your computer. install.failed.downloading.detail=Failed to download file: %s install.failed.downloading.timeout=Timed out while downloading the file: %s install.failed.install_online=Unable to recognize the provided installer file. If you are installing a mod, go to "Mods" page. diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 84e425f23..155f79d5d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -289,6 +289,10 @@ download.javafx.notes=正在通過網絡下載 HMCL 必要的運行時組件。\ download.javafx.component=正在下載模塊 %s download.javafx.prepare=準備開始下載 +exception.access_denied=因為無法訪問文件 %s,HMCL 沒有對該文件的訪問權限,或者該文件被其他程序打開。\n\ + 請你檢查當前操作系統帳戶是否能訪問該文件,比如非管理員用戶可能不能訪問其他帳戶的個人文件夾內的文件。\n\ + 對於 Windows 用戶,你還可以嘗試通過資源監視器查看是否有程序占用了該文件,如果是,你可以關閉占用此文件相關程序,或者重啟電腦再試。 + extension.bat=Windows 指令碼 extension.mod=模組檔案 extension.png=圖片檔案 @@ -401,7 +405,6 @@ install.change_version=變更版本 install.change_version.confirm=你確定要 %s 從 %s 更新到 %s 嗎? install.failed=安裝失敗 install.failed.downloading=安裝失敗,部分檔案未能完成下載 -install.failed.downloading.access_denied=未能下載文件:%1$s。因為無法訪問文件 %2$s,HMCL 沒有對該文件的訪問權限,或者該文件被其他程序打開。你可以嘗試關閉相關程序,或者重啟電腦再試。 install.failed.downloading.detail=未能下載檔案: %s install.failed.downloading.timeout=下載逾時: %s install.failed.install_online=無法識別要安裝的軟體。如果你要安裝 Mod,你需要在模組管理頁面安裝模組。 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 c743fa36f..8659dfd85 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -289,6 +289,10 @@ download.javafx.notes=正在通过网络下载 HMCL 必要的运行时组件。\ download.javafx.component=正在下载模块 %s download.javafx.prepare=准备开始下载 +exception.access_denied=因为无法访问文件 %s,HMCL 没有对该文件的访问权限,或者该文件被其他程序打开。\n\ + 请你检查当前操作系统帐户是否能访问该文件,比如非管理员用户可能不能访问其他帐户的个人文件夹内的文件。\n\ + 对于 Windows 用户,你还可以尝试通过资源监视器查看是否有程序占用了该文件,如果是,你可以关闭占用此文件相关程序,或者重启电脑再试。 + extension.bat=Windows 脚本 extension.mod=模组文件 extension.png=图片文件 @@ -401,7 +405,6 @@ install.change_version=更换版本 install.change_version.confirm=你确定要将 %s 从 %s 更新到 %s 吗? install.failed=安装失败 install.failed.downloading=安装失败,部分文件未能完成下载 -install.failed.downloading.access_denied=未能下载文件:%1$s。因为无法访问文件 %2$s,HMCL 没有对该文件的访问权限,或者该文件被其他程序打开。你可以尝试关闭相关程序,或者重启电脑再试。 install.failed.downloading.detail=未能下载文件:%s install.failed.downloading.timeout=下载超时:%s install.failed.install_online=无法识别要安装的软件。如果你要安装 Mod,你需要在模组管理页面安装模组。