diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/directory/GameDirectoryPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/directory/GameDirectoryPage.java index 7fb7500fa6b..4dd128f47ef 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/directory/GameDirectoryPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/directory/GameDirectoryPage.java @@ -21,8 +21,12 @@ import com.jfoenix.controls.JFXTextField; import com.jfoenix.validation.RequiredFieldValidator; import com.jfoenix.validation.base.ValidatorBase; +import javafx.application.Platform; import javafx.beans.binding.Bindings; -import javafx.beans.property.*; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; @@ -202,51 +206,57 @@ public void changed(ObservableValue observable, String oldValu /// Saves the edited game directory or adds a new entry to the appropriate game directory store. private void onSave() { - if (gameDirectory != null) { - LocalizedText name = LocalizedText.plain(txtGameDirectoryName.getText()); - PortablePath path = StringUtils.isNotBlank(getLocation()) ? createPortableLocation() : gameDirectory.getPath(); - if (!GameDirectoryManager.canUpdateGameDirectory(gameDirectory, path)) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - GameDirectoryManager.forceOverwriteGameDirectoryFiles(gameDirectory, path); - GameDirectoryManager.updateGameDirectory(gameDirectory, name, path); - fireEvent(new PageCloseEvent()); - }); - return; - } + if (Objects.equals(Path.of(getLocation()).getRoot(), Path.of(getLocation()))) { + Platform.runLater(() -> Controllers.confirm(i18n("game_directory.root"), i18n("message.warning"), MessageDialogPane.MessageType.WARNING, + () -> { + if (gameDirectory != null) { + LocalizedText name = LocalizedText.plain(txtGameDirectoryName.getText()); + PortablePath path = StringUtils.isNotBlank(getLocation()) ? createPortableLocation() : gameDirectory.getPath(); + if (!GameDirectoryManager.canUpdateGameDirectory(gameDirectory, path)) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + GameDirectoryManager.forceOverwriteGameDirectoryFiles(gameDirectory, path); + GameDirectoryManager.updateGameDirectory(gameDirectory, name, path); + fireEvent(new PageCloseEvent()); + }); + return; + } + + GameDirectoryManager.updateGameDirectory(gameDirectory, name, path); + } else { + if (StringUtils.isBlank(getLocation())) { + gameDir.fire(); + } + GameDirectory newGameDirectory = new GameDirectory( + GameDirectoryManager.newGameDirectoryId(), + LocalizedText.plain(txtGameDirectoryName.getText()), + createPortableLocation()); + if (newGameDirectory.getPath().isAbsolute()) { + if (SettingsManager.isUserGameDirectoriesReadOnly()) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + SettingsManager.forceOverwriteUserGameDirectories(); + GameDirectoryManager.addUserGameDirectory(newGameDirectory); + fireEvent(new PageCloseEvent()); + }); + return; + } + GameDirectoryManager.addUserGameDirectory(newGameDirectory); + } else { + if (SettingsManager.isLocalGameDirectoriesReadOnly()) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + SettingsManager.forceOverwriteLocalGameDirectories(); + GameDirectoryManager.addLocalGameDirectory(newGameDirectory); + fireEvent(new PageCloseEvent()); + }); + return; + } + GameDirectoryManager.addLocalGameDirectory(newGameDirectory); + } + } - GameDirectoryManager.updateGameDirectory(gameDirectory, name, path); - } else { - if (StringUtils.isBlank(getLocation())) { - gameDir.fire(); - } - GameDirectory newGameDirectory = new GameDirectory( - GameDirectoryManager.newGameDirectoryId(), - LocalizedText.plain(txtGameDirectoryName.getText()), - createPortableLocation()); - if (newGameDirectory.getPath().isAbsolute()) { - if (SettingsManager.isUserGameDirectoriesReadOnly()) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - SettingsManager.forceOverwriteUserGameDirectories(); - GameDirectoryManager.addUserGameDirectory(newGameDirectory); - fireEvent(new PageCloseEvent()); - }); - return; - } - GameDirectoryManager.addUserGameDirectory(newGameDirectory); - } else { - if (SettingsManager.isLocalGameDirectoriesReadOnly()) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - SettingsManager.forceOverwriteLocalGameDirectories(); - GameDirectoryManager.addLocalGameDirectory(newGameDirectory); fireEvent(new PageCloseEvent()); - }); - return; - } - GameDirectoryManager.addLocalGameDirectory(newGameDirectory); - } - } + }, null)); - fireEvent(new PageCloseEvent()); + } } /// Creates the portable path for the current location according to the relative-path toggle. diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 1cd10af2477..cbd4f0b9c60 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -755,6 +755,7 @@ game_directory.new=New Directory game_directory.title=Game Directories game_directory.selected=Selected game_directory.use_relative_path=Use a relative path for the game directory if possible +game_directory.root=Using the disk root directory as the game folder may cause the game to fail to launch and will create multiple files and folders in the disk root directory.\n\nAre you sure you want to continue? help=Help help.doc=Hello Minecraft! Launcher Documentation diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 1155a1cdecb..a2820dc151f 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -562,6 +562,7 @@ game_directory.new=建立新目錄 game_directory.title=遊戲目錄 game_directory.selected=已選取 game_directory.use_relative_path=如可行,則對於遊戲目錄使用相對路徑 +game_directory.root=使用磁碟根目錄作為遊戲資料夾可能會導致無法啟動遊戲,並會在磁碟根目錄下建立多個檔案和資料夾。\n\n確定要繼續嗎? help=說明 help.doc=Hello Minecraft! Launcher 說明文件 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 6472e707324..c59b7a1ea00 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -567,6 +567,7 @@ game_directory.new=添加游戏文件夹 game_directory.title=游戏文件夹 game_directory.selected=已选中 game_directory.use_relative_path=若可能,游戏文件夹使用相对路径 +game_directory.root=使用磁盘根目录作为游戏文件夹可能会导致无法启动游戏,并会在磁盘根目录下创建多个文件(夹)。\n\n确定要继续吗? help=帮助 help.doc=Hello Minecraft! Launcher 帮助文档