Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 53 additions & 43 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,51 +191,57 @@ public void changed(ObservableValue<? extends String> 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());
}
}
Comment thread
CiiLu marked this conversation as resolved.

/// Creates the portable path for the current location according to the relative-path toggle.
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ profile.name=名稱
profile.new=建立新目錄
profile.title=遊戲目錄
profile.selected=已選取
profile.root=使用磁碟根目錄作為遊戲資料夾可能會導致無法啟動遊戲,並會在磁碟根目錄下建立多個檔案和資料夾。\n\n確定要繼續嗎?
profile.use_relative_path=如可行,則對於遊戲目錄使用相對路徑

repositories.custom=自訂 Maven 儲存庫 (%s)
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ profile.name=名称
profile.new=添加游戏文件夹
profile.title=游戏文件夹
profile.selected=已选中
profile.root=使用磁盘根目录作为游戏文件夹可能会导致无法启动游戏,并会在磁盘根目录下创建多个文件(夹)。\n\n确定要继续吗?
profile.use_relative_path=若可能,游戏文件夹使用相对路径

repositories.custom=自定义 Maven 仓库 (%s)
Expand Down