Beispiel #1
0
        public static string RemoveInvalidCharsFromFileName(string filename, bool logIfInvalidChars)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(filename);
            }
            filename = filename.Trim();
            if (string.IsNullOrEmpty(filename))
            {
                return(filename);
            }
            string text  = new string(Path.GetInvalidFileNameChars());
            string text2 = string.Empty;
            bool   flag  = false;
            string text3 = filename;

            for (int i = 0; i < text3.Length; i++)
            {
                char c = text3[i];
                if (text.IndexOf(c) == -1)
                {
                    text2 += c;
                }
                else
                {
                    flag = true;
                }
            }
            if (flag && logIfInvalidChars)
            {
                string displayStringOfInvalidCharsOfFileName = InternalEditorUtility.GetDisplayStringOfInvalidCharsOfFileName(filename);
                if (displayStringOfInvalidCharsOfFileName.Length > 0)
                {
                    Debug.LogWarningFormat("A filename cannot contain the following character{0}:  {1}", new object[]
                    {
                        (displayStringOfInvalidCharsOfFileName.Length <= 1) ? string.Empty : "s",
                        displayStringOfInvalidCharsOfFileName
                    });
                }
            }
            return(text2);
        }