From 516975688f106b39275376cc3c951bac886471c7 Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 21 Oct 2021 22:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=8F=91=E7=8E=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=AE=9E=E7=8E=B0=E5=87=BA=E9=94=99=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E7=94=A8=E6=88=B7=20(#1040)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: The implementation of 'Files.isWritable' is incorrect * Report Samba problems to users * Rollback FileUtils --- .../java/org/jackhuang/hmcl/Launcher.java | 3 +++ .../jackhuang/hmcl/setting/ConfigHolder.java | 20 ++++++++++++------- .../hmcl/setting/SambaException.java | 18 +++++++++++++++++ .../resources/assets/lang/I18N.properties | 1 + .../resources/assets/lang/I18N_zh.properties | 1 + .../assets/lang/I18N_zh_CN.properties | 1 + 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/setting/SambaException.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java index 9b90c7485..8ba1ff570 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java @@ -21,6 +21,7 @@ import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; import org.jackhuang.hmcl.setting.ConfigHolder; +import org.jackhuang.hmcl.setting.SambaException; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.AsyncTaskExecutor; import org.jackhuang.hmcl.ui.AwtUtils; @@ -62,6 +63,8 @@ public final class Launcher extends Application { try { try { ConfigHolder.init(); + } catch (SambaException ignored) { + Main.showWarningAndContinue(i18n("fatal.samba")); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed to load config", e); Main.showErrorAndExit(i18n("fatal.config_loading_failure", Paths.get("").toAbsolutePath().normalize())); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java index 656ea8eb7..792bbe3d0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/ConfigHolder.java @@ -26,9 +26,7 @@ import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.platform.OperatingSystem; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; import java.util.Map; import java.util.logging.Level; @@ -37,7 +35,8 @@ import static org.jackhuang.hmcl.util.Logging.LOG; public final class ConfigHolder { - private ConfigHolder() {} + private ConfigHolder() { + } public static final String CONFIG_FILENAME = "hmcl.json"; public static final String CONFIG_FILENAME_LINUX = ".hmcl.json"; @@ -97,9 +96,16 @@ public final class ConfigHolder { } if (!Files.isWritable(configLocation)) { - // the config cannot be saved - // throw up the error now to prevent further data loss - throw new IOException("Config at " + configLocation + " is not writable"); + if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS + && configLocation.getFileSystem() == FileSystems.getDefault() + && configLocation.toFile().canWrite()) { + // There are some serious problems with the implementation of Samba or OpenJDK + throw new SambaException(); + } else { + // the config cannot be saved + // throw up the error now to prevent further data loss + throw new IOException("Config at " + configLocation + " is not writable"); + } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/SambaException.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/SambaException.java new file mode 100644 index 000000000..d128bfae1 --- /dev/null +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/SambaException.java @@ -0,0 +1,18 @@ +package org.jackhuang.hmcl.setting; + +public final class SambaException extends RuntimeException { + public SambaException() { + } + + public SambaException(String message) { + super(message); + } + + public SambaException(String message, Throwable cause) { + super(message, cause); + } + + public SambaException(Throwable cause) { + super(cause); + } +} diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 00d34c26b..30ee4735b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -306,6 +306,7 @@ fatal.missing_dst_root_ca_x3=The DST Root CA X3 certificate is missing on the cu fatal.config_loading_failure=The configuration is not accessible.\nPlease ensure Hello Minecraft! Launcher has read and write access to "%s" and the files in it. fatal.migration_requires_manual_reboot=The update is complete. Please reopen Hello Minecraft! Launcher. fatal.apply_update_failure=We're sorry, Hello Minecraft! Launcher couldn't finish the update because something went wrong.\nBut you can still manually finish the update by downloading Hello Minecraft! Launcher from %s.\nPlease consider reporting this issue to us. +fatal.samba=If you are trying to run HMCL in a shared folder by Samba, HMCL may not working, please try updating your Java or running HMCL in a local folder. feedback=Feedback feedback.add=Add Feedback diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index f41c581ab..eaefadc01 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -306,6 +306,7 @@ fatal.missing_dst_root_ca_x3=目前的 Java 平台缺少 DST Root CA X3 憑證 fatal.config_loading_failure=Hello Minecraft! Launcher 無法載入設定檔案。\n請確保 Hello Minecraft! Launcher 對 "%s" 目錄及該目錄下的檔案擁有讀寫權限。 fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即將升級完成,請重新開啟 Hello Minecraft! Launcher。 fatal.apply_update_failure=我們很抱歉 Hello Minecraft! Launcher 無法自動完成升級程式,因為出現了一些問題。\n但你依然可以從 %s 處手動下載 Hello Minecraft! Launcher 來完成升級。\n請考慮向我們回報該問題。 +fatal.samba=如果您正在通過 Samba 共亯的資料夾中運行 HMCL,HMCL 可能無法正常工作,請嘗試更新您的 Java 或在本地資料夾內運行 HMCL。 feedback=回饋 feedback.add=新增回饋 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 ea9e41e12..31c7a5e4d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -306,6 +306,7 @@ fatal.missing_dst_root_ca_x3=当前 Java 平台缺少 DST Root CA X3 证书。\n fatal.config_loading_failure=Hello Minecraft! Launcher 无法加载配置文件。\n请确保 Hello Minecraft! Launcher 对 "%s" 目录及该目录下的文件拥有读写权限。 fatal.migration_requires_manual_reboot=Hello Minecraft! Launcher 即将完成升级,请重新打开 Hello Minecraft! Launcher。 fatal.apply_update_failure=我们很抱歉 Hello Minecraft! Launcher 无法自动完成升级,因为出现了一些问题。\n但你依然可以从 %s 处手动下载 Hello Minecraft! Launcher 来完成升级。\n请考虑向我们反馈该问题。 +fatal.samba=如果您正在通过 Samba 共享的文件夹中运行 HMCL,HMCL 可能无法正常工作,请尝试更新您的 Java 或在本地文件夹内运行 HMCL。 feedback=反馈 feedback.add=新增反馈