diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java index b27675e7a01..152f04bcb9a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.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; @@ -187,51 +191,57 @@ public void changed(ObservableValue observable, String oldValu } private void onSave() { - if (profile != null) { - LocalizedText name = LocalizedText.plain(txtProfileName.getText()); - PortablePath path = StringUtils.isNotBlank(getLocation()) ? createPortableLocation() : profile.getPath(); - if (!Profiles.canUpdateProfile(profile, path)) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - Profiles.forceOverwriteProfileFiles(profile, path); - Profiles.updateProfile(profile, name, path); - fireEvent(new PageCloseEvent()); - }); - return; - } + if (Objects.equals(Path.of(getLocation()).getRoot(), Path.of(getLocation()))) { + Platform.runLater(() -> Controllers.confirm(i18n("profile.root"), i18n("message.warning"), MessageDialogPane.MessageType.WARNING, + () -> { + if (profile != null) { + LocalizedText name = LocalizedText.plain(txtProfileName.getText()); + PortablePath path = StringUtils.isNotBlank(getLocation()) ? createPortableLocation() : profile.getPath(); + if (!Profiles.canUpdateProfile(profile, path)) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + Profiles.forceOverwriteProfileFiles(profile, path); + Profiles.updateProfile(profile, name, path); + fireEvent(new PageCloseEvent()); + }); + return; + } + + Profiles.updateProfile(profile, name, path); + } else { + if (StringUtils.isBlank(getLocation())) { + gameDir.fire(); + } + Profile newProfile = new Profile( + Profiles.newProfileId(), + LocalizedText.plain(txtProfileName.getText()), + createPortableLocation()); + if (newProfile.getPath().isAbsolute()) { + if (SettingsManager.isUserGameDirectoriesReadOnly()) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + SettingsManager.forceOverwriteUserGameDirectories(); + Profiles.addUserProfile(newProfile); + fireEvent(new PageCloseEvent()); + }); + return; + } + Profiles.addUserProfile(newProfile); + } else { + if (SettingsManager.isLocalGameDirectoriesReadOnly()) { + Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { + SettingsManager.forceOverwriteLocalGameDirectories(); + Profiles.addLocalProfile(newProfile); + fireEvent(new PageCloseEvent()); + }); + return; + } + Profiles.addLocalProfile(newProfile); + } + } - Profiles.updateProfile(profile, name, path); - } else { - if (StringUtils.isBlank(getLocation())) { - gameDir.fire(); - } - Profile newProfile = new Profile( - Profiles.newProfileId(), - LocalizedText.plain(txtProfileName.getText()), - createPortableLocation()); - if (newProfile.getPath().isAbsolute()) { - if (SettingsManager.isUserGameDirectoriesReadOnly()) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - SettingsManager.forceOverwriteUserGameDirectories(); - Profiles.addUserProfile(newProfile); - fireEvent(new PageCloseEvent()); - }); - return; - } - Profiles.addUserProfile(newProfile); - } else { - if (SettingsManager.isLocalGameDirectoriesReadOnly()) { - Controllers.confirmBackupAndOverwrite(i18n("settings.game_directories.read_only"), () -> { - SettingsManager.forceOverwriteLocalGameDirectories(); - Profiles.addLocalProfile(newProfile); fireEvent(new PageCloseEvent()); - }); - return; - } - Profiles.addLocalProfile(newProfile); - } - } + }, 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 aec693366e8..3f18119a2e8 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1261,6 +1261,7 @@ profile.name=Name profile.new=New Directory profile.title=Game Directories profile.selected=Selected +profile.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? profile.use_relative_path=Use a relative path for the game directory if possible repositories.custom=Custom Maven Repository (%s) diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 2e4be895ed2..63324cda5ac 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -1058,6 +1058,7 @@ profile.name=名稱 profile.new=建立新目錄 profile.title=遊戲目錄 profile.selected=已選取 +profile.root=使用磁碟根目錄作為遊戲資料夾可能會導致無法啟動遊戲,並會在磁碟根目錄下建立多個檔案和資料夾。\n\n確定要繼續嗎? profile.use_relative_path=如可行,則對於遊戲目錄使用相對路徑 repositories.custom=自訂 Maven 儲存庫 (%s) 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 272e2f06fe3..b7d6f3ee7b2 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -1063,6 +1063,7 @@ profile.name=名称 profile.new=添加游戏文件夹 profile.title=游戏文件夹 profile.selected=已选中 +profile.root=使用磁盘根目录作为游戏文件夹可能会导致无法启动游戏,并会在磁盘根目录下创建多个文件(夹)。\n\n确定要继续吗? profile.use_relative_path=若可能,游戏文件夹使用相对路径 repositories.custom=自定义 Maven 仓库 (%s)