Skip to content

Commit

Permalink
Closes #3158 Make directory text fields read only and check empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Apr 6, 2024
1 parent 2457533 commit 60c84a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Path> files = Files.list(newDirectory)) {
if (files.findAny().isPresent()) {
notificationService.addImmediateWarnNotification("directory.move.notempty", newDirectory);
return null;
}
}
}

updateTitle(i18n.get("directory.move", oldDirectory, newDirectory));

try {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/theme/settings/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@
<Label contentDisplay="RIGHT" maxWidth="1.7976931348623157E308"
styleClass="setting-title" text="%settings.fa.gameLocation"/>
<TextField fx:id="gameLocationTextField"
promptText="%settings.useDefaultDirectory" GridPane.rowIndex="1"/>
promptText="%settings.useDefaultDirectory"
GridPane.rowIndex="1" editable="false"/>
<Button mnemonicParsing="false" onAction="#onSelectGameLocation"
text="%settings.fa.chooseDirectory" GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
Expand Down Expand Up @@ -669,7 +670,8 @@
</graphic>
</Label>
<TextField fx:id="vaultLocationTextField"
promptText="%settings.useDefaultDirectory" GridPane.rowIndex="1"/>
promptText="%settings.useDefaultDirectory"
GridPane.rowIndex="1" editable="false"/>
<Button mnemonicParsing="false" onAction="#onSelectVaultLocation"
text="%settings.fa.chooseDirectory" GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
Expand Down Expand Up @@ -1056,7 +1058,8 @@
<Label contentDisplay="RIGHT" maxWidth="1.7976931348623157E308"
styleClass="setting-title" text="%settings.data.dataLocation"/>
<TextField fx:id="dataLocationTextField"
promptText="%settings.useDefaultDirectory" GridPane.rowIndex="1"/>
promptText="%settings.useDefaultDirectory"
GridPane.rowIndex="1" editable="false"/>
<Button mnemonicParsing="false" onAction="#onSelectDataLocation"
text="%settings.fa.chooseDirectory" GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
Expand Down

0 comments on commit 60c84a7

Please sign in to comment.