From 60c84a7c96e827b7d96265a7f18e73a09edf2f6e Mon Sep 17 00:00:00 2001 From: Sheikah45 Date: Sat, 6 Apr 2024 17:35:02 -0400 Subject: [PATCH] Closes #3158 Make directory text fields read only and check empty path --- .../preferences/tasks/MoveDirectoryTask.java | 14 +++++++++++++- src/main/resources/i18n/messages.properties | 1 + src/main/resources/theme/settings/settings.fxml | 9 ++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/faforever/client/preferences/tasks/MoveDirectoryTask.java b/src/main/java/com/faforever/client/preferences/tasks/MoveDirectoryTask.java index e7812f4f9c..0e2bd8281a 100644 --- a/src/main/java/com/faforever/client/preferences/tasks/MoveDirectoryTask.java +++ b/src/main/java/com/faforever/client/preferences/tasks/MoveDirectoryTask.java @@ -12,8 +12,10 @@ import org.springframework.util.FileSystemUtils; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; +import java.util.stream.Stream; @Component @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) @@ -43,6 +45,16 @@ public MoveDirectoryTask(I18n i18n, NotificationService notificationService) { protected Void call() throws Exception { Objects.requireNonNull(oldDirectory, "Old directory has not been set"); Objects.requireNonNull(newDirectory, "New directory has not been set"); + + if (Files.exists(newDirectory)) { + try (Stream files = Files.list(newDirectory)) { + if (files.findAny().isPresent()) { + notificationService.addImmediateWarnNotification("directory.move.notempty", newDirectory); + return null; + } + } + } + updateTitle(i18n.get("directory.move", oldDirectory, newDirectory)); try { @@ -56,7 +68,7 @@ protected Void call() throws Exception { afterCopyAction.run(); - if (!preserveOldDirectory) { + if (!preserveOldDirectory && !newDirectory.startsWith(oldDirectory)) { updateTitle(i18n.get("directory.delete", oldDirectory)); try { FileSystemUtils.deleteRecursively(oldDirectory); diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index de44d41418..a75c47ad83 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -1199,6 +1199,7 @@ settings.data.dataLocation.error = Could not copy files to new data location at settings.data.dataLocation.description = Folder where the client will store data like featured mods, replays, game files etc directory.move = Copying contents of {0} to {1} directory.delete = Deleting {0} +directory.move.notempty=Directory {0} is not empty directory.move.failed = Failed moving contents of {0} to {1} please check file permissions and see error below for more details directory.delete.failed = Failed deleting contents in {0} please check file permissions and see error below for more details game.create.passwordNotAscii = Password must contain only ASCII characters diff --git a/src/main/resources/theme/settings/settings.fxml b/src/main/resources/theme/settings/settings.fxml index 9259eee52e..95b15b14e2 100644 --- a/src/main/resources/theme/settings/settings.fxml +++ b/src/main/resources/theme/settings/settings.fxml @@ -640,7 +640,8 @@