在实例名称中包含非字母、数字、减号和下划线字符时弹出警告 (#4222)

This commit is contained in:
Glavo
2025-08-09 21:29:41 +08:00
committed by GitHub
parent b1d8edc72a
commit 3cdddfa86d
4 changed files with 18 additions and 6 deletions

View File

@@ -27,7 +27,6 @@ import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
import org.jackhuang.hmcl.ui.construct.RequiredValidator;
import org.jackhuang.hmcl.ui.construct.Validator;
import org.jackhuang.hmcl.ui.wizard.WizardController;
import org.jackhuang.hmcl.util.StringUtils;
import java.util.Map;
@@ -77,11 +76,24 @@ public class InstallersPage extends AbstractInstallersPage {
public void cleanup(Map<String, Object> settings) {
}
private static boolean checkName(String name) {
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if (!(c >= '0' && c <= '9')
&& !(c >= 'a' && c <= 'z')
&& !(c >= 'A' && c <= 'Z')
&& c != '-' && c != '_' && c != '.'
)
return false;
}
return true;
}
protected void onInstall() {
String name = txtName.getText();
// Check for non-ASCII characters.
if (!StringUtils.isASCII(name)) {
if (!checkName(name)) {
Controllers.dialog(new MessageDialogPane.Builder(
i18n("install.name.invalid"),
i18n("message.warning"),

View File

@@ -714,7 +714,7 @@ install.installer.external_version=%s (Installed by external process, which cann
install.installing=Installing
install.modpack=Install Modpack
install.modpack.installation=Modpack Installation
install.name.invalid=The name contains non-ASCII characters (such as emoji or CJK characters).\nIt is recommended to change the name to include only English letters, numbers, and underscores to avoid potential issues when launching the game.\nDo you want to proceed with the installation?
install.name.invalid=The name contains special characters (such as emoji or CJK characters).\nIt is recommended to change the name to include only English letters, numbers, and underscores to avoid potential issues when launching the game.\nDo you want to proceed with the installation?
install.new_game=Install Instance
install.new_game.already_exists=This instance name already exists. Please use another name.
install.new_game.current_game_version=Current Instance Version

View File

@@ -530,7 +530,7 @@ install.installer.external_version=%s [由外部安裝的版本,無法解除
install.installing=安裝
install.modpack=安裝模組包
install.modpack.installation=安裝模組包
install.name.invalid=名稱中包含非 ASCII 字元(如 Emoji 表情或中文字元)。\n建議修改名稱。名稱建議僅包含英文字母、數字和底線以防啟動遊戲時出現問題。是否繼續安裝
install.name.invalid=名稱中包含特殊字元(如 Emoji 表情或中文字元)。\n建議修改名稱。名稱建議僅包含英文字母、數字和底線以防啟動遊戲時出現問題。是否繼續安裝
install.new_game=安裝新實例
install.new_game.already_exists=此實例已經存在,請重新命名
install.new_game.current_game_version=目前遊戲實例

View File

@@ -540,7 +540,7 @@ install.installer.external_version=%s (由外部安装的版本,无法卸载
install.installing=安装
install.modpack=安装整合包
install.modpack.installation=安装整合包
install.name.invalid=名称中包含非 ASCII 字符(如 Emoji 表情或中文字符)。\n建议修改名称。名称建议仅包含英文字母、数字和下划线以防启动游戏时出现问题。是否继续安装
install.name.invalid=名称中包含特殊字符(如 Emoji 表情或中文字符)。\n建议修改名称。名称建议仅包含英文字母、数字和下划线以防启动游戏时出现问题。是否继续安装
install.new_game=安装新游戏
install.new_game.already_exists=此版本已经存在,请换一个名字
install.new_game.current_game_version=当前游戏版本