Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -153,7 +154,7 @@ public static void download(DownloadProvider downloadProvider, Profile profile,
}
}), 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))));
Comment on lines 155 to +157
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator 会在输入字符时触发,把 IO 操作放在这里不合适吧?


}

Expand Down
Loading