Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileSystemEnumerableFactory.cs
Go to the documentation of this file.
2
4
5internal static class FileSystemEnumerableFactory
6{
7 private static readonly char[] s_unixEscapeChars = new char[4] { '\\', '"', '<', '>' };
8
9 internal static bool NormalizeInputs(ref string directory, ref string expression, MatchType matchType)
10 {
12 {
13 throw new ArgumentException(SR.Arg_Path2IsRooted, "expression");
14 }
15 if (expression.Contains('\0'))
16 {
18 }
19 if (directory.Contains('\0'))
20 {
22 }
24 bool result = true;
25 if (directoryName.Length != 0)
26 {
28 expression = expression.Substring(directoryName.Length + 1);
29 result = false;
30 }
31 switch (matchType)
32 {
33 case MatchType.Win32:
34 if (expression == "*")
35 {
36 break;
37 }
38 if (string.IsNullOrEmpty(expression) || expression == "." || expression == "*.*")
39 {
40 expression = "*";
41 break;
42 }
43 if (Path.DirectorySeparatorChar != '\\' && expression.IndexOfAny(s_unixEscapeChars) != -1)
44 {
45 expression = expression.Replace("\\", "\\\\");
46 expression = expression.Replace("\"", "\\\"");
47 expression = expression.Replace(">", "\\>");
48 expression = expression.Replace("<", "\\<");
49 }
51 break;
52 default:
53 throw new ArgumentOutOfRangeException("matchType");
54 case MatchType.Simple:
55 break;
56 }
57 return result;
58 }
59
61 {
62 bool ignoreCase = (options.MatchCasing == MatchCasing.PlatformDefault && !PathInternal.IsCaseSensitive) || options.MatchCasing == MatchCasing.CaseInsensitive;
63 return options.MatchType switch
64 {
65 MatchType.Simple => FileSystemName.MatchesSimpleExpression(expression.AsSpan(), name, ignoreCase),
66 MatchType.Win32 => FileSystemName.MatchesWin32Expression(expression.AsSpan(), name, ignoreCase),
67 _ => throw new ArgumentOutOfRangeException("options"),
68 };
69 }
70
72 {
74 {
75 return entry.ToSpecifiedFullPath();
76 }, options)
77 {
78 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
79 {
80 return !entry.IsDirectory && MatchesPattern(expression, entry.FileName, options);
81 }
82 };
83 }
84
86 {
88 {
89 return entry.ToSpecifiedFullPath();
90 }, options)
91 {
92 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
93 {
94 return entry.IsDirectory && MatchesPattern(expression, entry.FileName, options);
95 }
96 };
97 }
98
100 {
102 {
103 return entry.ToSpecifiedFullPath();
104 }, options)
105 {
106 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
107 {
108 return MatchesPattern(expression, entry.FileName, options);
109 }
110 };
111 }
112
114 {
116 {
117 return (FileInfo)entry.ToFileSystemInfo();
119 {
120 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
121 {
122 return !entry.IsDirectory && MatchesPattern(expression, entry.FileName, options);
123 }
124 };
125 }
126
128 {
130 {
131 return (DirectoryInfo)entry.ToFileSystemInfo();
133 {
134 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
135 {
136 return entry.IsDirectory && MatchesPattern(expression, entry.FileName, options);
137 }
138 };
139 }
140
142 {
144 {
145 return entry.ToFileSystemInfo();
147 {
148 ShouldIncludePredicate = delegate(ref FileSystemEntry entry)
149 {
150 return MatchesPattern(expression, entry.FileName, options);
151 }
152 };
153 }
154}
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static IEnumerable< FileSystemInfo > FileSystemInfos(string directory, string expression, EnumerationOptions options, bool isNormalized)
static bool MatchesPattern(string expression, ReadOnlySpan< char > name, EnumerationOptions options)
static IEnumerable< DirectoryInfo > DirectoryInfos(string directory, string expression, EnumerationOptions options, bool isNormalized)
static IEnumerable< string > UserDirectories(string directory, string expression, EnumerationOptions options)
static IEnumerable< string > UserFiles(string directory, string expression, EnumerationOptions options)
static IEnumerable< FileInfo > FileInfos(string directory, string expression, EnumerationOptions options, bool isNormalized)
static bool NormalizeInputs(ref string directory, ref string expression, MatchType matchType)
static IEnumerable< string > UserEntries(string directory, string expression, EnumerationOptions options)
static bool MatchesSimpleExpression(ReadOnlySpan< char > expression, ReadOnlySpan< char > name, bool ignoreCase=true)
static bool MatchesWin32Expression(ReadOnlySpan< char > expression, ReadOnlySpan< char > name, bool ignoreCase=true)
static string TranslateWin32Expression(string? expression)
static bool IsCaseSensitive
static bool IsPathRooted([NotNullWhen(true)] string? path)
Definition Path.cs:985
static string Join(ReadOnlySpan< char > path1, ReadOnlySpan< char > path2)
Definition Path.cs:387
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static ? string GetDirectoryName(string? path)
Definition Path.cs:121
static string Argument_InvalidPathChars
Definition SR.cs:730
static string Arg_Path2IsRooted
Definition SR.cs:2198
Definition SR.cs:7