Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a missing destination filename collision check when downloading/installing mods (and other downloadable content using the same prompt) so users don’t unintentionally overwrite an existing file in the target subdirectory.
Changes:
- Add
java.nio.file.Filesusage to check whether the chosen destination filename already exists. - Add a second input
Validatorto the download filename prompt to reject existing filenames.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }), i18n("message.downloading"), TaskCancellationAction.NORMAL); | ||
| handler.resolve(); | ||
| }, file.getFile().getFilename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValid)); | ||
| }, file.getFile().getFilename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValid), new Validator(i18n("profile.already_exists"), (it) -> !Files.exists(runDirectory.resolve(subdirectoryName).resolve(it)))); |
There was a problem hiding this comment.
The new filename-exists validator only runs when the text changes (InputDialogPane uses FXUtils.setValidateWhileTextChanged), so the OK button can remain enabled if the destination file appears after the last keystroke. Since FileDownloadTask ultimately moves the temp file with REPLACE_EXISTING, this can still overwrite an existing file. Consider re-checking Files.exists(dest) inside the prompt callback (before starting the task) and rejecting via handler.reject(...) when it exists, so the no-overwrite guarantee holds at execution time.
| }), i18n("message.downloading"), TaskCancellationAction.NORMAL); | ||
| handler.resolve(); | ||
| }, file.getFile().getFilename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValid)); | ||
| }, file.getFile().getFilename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValid), new Validator(i18n("profile.already_exists"), (it) -> !Files.exists(runDirectory.resolve(subdirectoryName).resolve(it)))); |
There was a problem hiding this comment.
Validator 会在输入字符时触发,把 IO 操作放在这里不合适吧?
No description provided.