diff --git a/Assets/Scripts/Studio/UI/Panel/Panel_NewProjectInfo.cs b/Assets/Scripts/Studio/UI/Panel/Panel_NewProjectInfo.cs index c9748abd..a23dad7b 100644 --- a/Assets/Scripts/Studio/UI/Panel/Panel_NewProjectInfo.cs +++ b/Assets/Scripts/Studio/UI/Panel/Panel_NewProjectInfo.cs @@ -53,7 +53,7 @@ namespace Studio.UI var projectName = GetProjectName(); var projectPath = GetProjectRoute(); - if (!IsProjectNameVaild(projectName) || !IsProjectExistVaild()) + if (!IsProjectNameVaild(projectName) || !IsProjectExistVaild(projectName) || IsWindowRestrictedKey(projectName)) { InputFieldHighlight(InputField_ProjectName); return; @@ -107,18 +107,32 @@ namespace Studio.UI } return true; } - private bool IsProjectExistVaild() + private bool IsProjectExistVaild(string projectName) { - var projectPath = InputField_ProjectRoute.text; - var projectNameAndExtension = $"{InputField_ProjectName.text}.ocs"; - - var filePath = Path.Combine(projectPath, projectNameAndExtension); - if (File.Exists(filePath)) + var projectNameAndExtension = $"{projectName}.ocs"; + + if (File.Exists(projectNameAndExtension)) { return false; } return true; } + private bool IsWindowRestrictedKey(string input) + { + char[] invalidChars = Path.GetInvalidFileNameChars(); + + if (input[0] == ' ') + return true; + + foreach (char c in input) + { + if (invalidChars.Contains(c)) + { + return true; + } + } + return false; + } private void InputFieldHighlight(TMP_InputField inputField) { CoroutineRunner.instance.StartCoroutine(Blink(inputField)); diff --git a/Assets/Scripts/Studio/UI/Panel/Panel_TopMenuNewProjectInfo.cs b/Assets/Scripts/Studio/UI/Panel/Panel_TopMenuNewProjectInfo.cs index ea32f223..fc4b72af 100644 --- a/Assets/Scripts/Studio/UI/Panel/Panel_TopMenuNewProjectInfo.cs +++ b/Assets/Scripts/Studio/UI/Panel/Panel_TopMenuNewProjectInfo.cs @@ -2,6 +2,7 @@ using Studio.Core; using System; using System.Collections; using System.IO; +using System.Linq; using TMPro; using TriLibCore.SFB; using UnityEngine; @@ -47,7 +48,7 @@ namespace Studio.UI var projectName = GetProjectName(); var projectPath = GetProjectRoute(); - if (!IsProjectNameVaild(projectName) || !IsProjectExistVaild()) + if (!IsProjectNameVaild(projectName) || !IsProjectExistVaild(projectName) || IsWindowRestrictedKey(projectName)) { InputFieldHighlight(InputField_ProjectName); return; @@ -99,18 +100,32 @@ namespace Studio.UI } return true; } - private bool IsProjectExistVaild() + private bool IsProjectExistVaild(string projectName) { - var projectPath = InputField_ProjectRoute.text; - var projectNameAndExtension = $"{InputField_ProjectName.text}.ocs"; + var projectNameAndExtension = $"{projectName}.ocs"; - var filePath = Path.Combine(projectPath, projectNameAndExtension); - if (File.Exists(filePath)) + if (File.Exists(projectNameAndExtension)) { return false; } return true; } + private bool IsWindowRestrictedKey(string input) + { + char[] invalidChars = Path.GetInvalidFileNameChars(); + + if (input[0] == ' ') + return true; + + foreach (char c in input) + { + if (invalidChars.Contains(c)) + { + return true; + } + } + return false; + } private void InputFieldHighlight(TMP_InputField inputField) { CoroutineRunner.instance.StartCoroutine(Blink(inputField));