1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
using System;
using System.Collections.Generic;
using System.Text;
namespace BigEyes.Viewer
{
public static class Path
{
// Fields
public static readonly char AltDirectorySeparatorChar = '/';
public static readonly char DirectorySeparatorChar = '\\';
private static readonly char[] InvalidFileNameChars = new char[] {
'"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v',
'\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b',
'\x001c', '\x001d', '\x001e', '\x001f', ':', '*', '?', '\\', '/'
};
[Obsolete("Please use GetInvalidPathChars or GetInvalidFileNameChars instead.")]
public static readonly char[] InvalidPathChars = new char[] {
'"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v',
'\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b',
'\x001c', '\x001d', '\x001e', '\x001f'
};
internal const int MAX_DIRECTORY_PATH = 0xf8;
internal const int MAX_PATH = 260;
internal static readonly int MaxPath = 260;
public static readonly char PathSeparator = ';';
private static readonly char[] RealInvalidPathChars = new char[] {
'"', '<', '>', '|', '\0', '\x0001', '\x0002', '\x0003', '\x0004', '\x0005', '\x0006', '\a', '\b', '\t', '\n', '\v',
'\f', '\r', '\x000e', '\x000f', '\x0010', '\x0011', '\x0012', '\x0013', '\x0014', '\x0015', '\x0016', '\x0017', '\x0018', '\x0019', '\x001a', '\x001b',
'\x001c', '\x001d', '\x001e', '\x001f'
};
public static readonly char VolumeSeparatorChar = ':';
// Methods
public static string ChangeExtension(string path, string extension)
{
if (path == null)
{
return null;
}
CheckInvalidPathChars(path);
string str = path;
int length = path.Length;
while (--length >= 0)
{
char ch = path[length];
if (ch == '.')
{
str = path.Substring(0, length);
break;
}
if (((ch == DirectorySeparatorChar) || (ch == AltDirectorySeparatorChar)) || (ch == VolumeSeparatorChar))
{
break;
}
}
if ((extension == null) || (path.Length == 0))
{
return str;
}
if ((extension.Length == 0) || (extension[0] != '.'))
{
str = str + ".";
}
return (str + extension);
}
private static bool CharArrayStartsWithOrdinal(char[] array, int numChars, string compareTo, bool ignoreCase)
{
if (numChars < compareTo.Length)
{
return false;
}
if (ignoreCase)
{
string str = new string(array, 0, compareTo.Length);
return compareTo.Equals(str, StringComparison.OrdinalIgnoreCase);
}
for (int i = 0; i < compareTo.Length; i++)
{
if (array[i] != compareTo[i])
{
return false;
}
}
return true;
}
internal static void CheckInvalidPathChars(string path)
{
for (int i = 0; i < path.Length; i++)
{
int num2 = path[i];
}
}
internal static void CheckSearchPattern(string searchPattern)
{
int num;
while ((num = searchPattern.IndexOf("..", StringComparison.Ordinal)) != -1)
{
searchPattern = searchPattern.Substring(num + 2);
}
}
public static string Combine(string path1, string path2)
{
if ((path1 == null) || (path2 == null))
{
throw new ArgumentNullException((path1 == null) ? "path1" : "path2");
}
CheckInvalidPathChars(path1);
CheckInvalidPathChars(path2);
if (path2.Length == 0)
{
return path1;
}
if (path1.Length == 0)
{
return path2;
}
if (IsPathRooted(path2))
{
return path2;
}
char ch = path1[path1.Length - 1];
if (((ch != DirectorySeparatorChar) && (ch != AltDirectorySeparatorChar)) && (ch != VolumeSeparatorChar))
{
return (path1 + DirectorySeparatorChar + path2);
}
return (path1 + path2);
}
public static string GetDirectoryName(string path)
{
if (path != null)
{
CheckInvalidPathChars(path);
int rootLength = GetRootLength(path);
if (path.Length > rootLength)
{
int length = path.Length;
if (length == rootLength)
{
return null;
}
while (((length > rootLength) && (path[--length] != DirectorySeparatorChar)) && (path[length] != AltDirectorySeparatorChar))
{
}
return path.Substring(0, length);
}
}
return null;
}
public static string GetExtension(string path)
{
if (path == null)
{
return null;
}
CheckInvalidPathChars(path);
int length = path.Length;
int startIndex = length;
while (--startIndex >= 0)
{
char ch = path[startIndex];
if (ch == '.')
{
if (startIndex != (length - 1))
{
return path.Substring(startIndex, length - startIndex);
}
return string.Empty;
}
if (((ch == DirectorySeparatorChar) || (ch == AltDirectorySeparatorChar)) || (ch == VolumeSeparatorChar))
{
break;
}
}
return string.Empty;
}
public static string GetFileName(string path)
{
if (path != null)
{
CheckInvalidPathChars(path);
int length = path.Length;
int num2 = length;
while (--num2 >= 0)
{
char ch = path[num2];
if (((ch == DirectorySeparatorChar) || (ch == AltDirectorySeparatorChar)) || (ch == VolumeSeparatorChar))
{
return path.Substring(num2 + 1, (length - num2) - 1);
}
}
}
return path;
}
public static string GetFileNameWithoutExtension(string path)
{
path = GetFileName(path);
if (path == null)
{
return null;
}
int length = path.LastIndexOf('.');
if (length == -1)
{
return path;
}
return path.Substring(0, length);
}
public static char[] GetInvalidFileNameChars()
{
return (char[])InvalidFileNameChars.Clone();
}
public static char[] GetInvalidPathChars()
{
return (char[])RealInvalidPathChars.Clone();
}
public static string GetPathRoot(string path)
{
if (path == null)
{
return null;
}
return path.Substring(0, GetRootLength(path));
}
internal static int GetRootLength(string path)
{
CheckInvalidPathChars(path);
int num = 0;
int length = path.Length;
if ((length >= 1) && IsDirectorySeparator(path[0]))
{
num = 1;
if ((length >= 2) && IsDirectorySeparator(path[1]))
{
num = 2;
int num3 = 2;
while ((num < length) && (((path[num] != DirectorySeparatorChar) && (path[num] != AltDirectorySeparatorChar)) || (--num3 > 0)))
{
num++;
}
}
return num;
}
if ((length >= 2) && (path[1] == VolumeSeparatorChar))
{
num = 2;
if ((length >= 3) && IsDirectorySeparator(path[2]))
{
num++;
}
}
return num;
}
public static bool HasExtension(string path)
{
if (path != null)
{
CheckInvalidPathChars(path);
int length = path.Length;
while (--length >= 0)
{
char ch = path[length];
if (ch == '.')
{
return (length != (path.Length - 1));
}
if (((ch == DirectorySeparatorChar) || (ch == AltDirectorySeparatorChar)) || (ch == VolumeSeparatorChar))
{
break;
}
}
}
return false;
}
internal static string InternalCombine(string path1, string path2)
{
if ((path1 == null) || (path2 == null))
{
throw new ArgumentNullException((path1 == null) ? "path1" : "path2");
}
CheckInvalidPathChars(path1);
CheckInvalidPathChars(path2);
int length = path1.Length;
if (length == 0)
{
return path2;
}
char ch = path1[length - 1];
if (((ch != DirectorySeparatorChar) && (ch != AltDirectorySeparatorChar)) && (ch != VolumeSeparatorChar))
{
return (path1 + DirectorySeparatorChar + path2);
}
return (path1 + path2);
}
internal static bool IsDirectorySeparator(char c)
{
if (c != DirectorySeparatorChar)
{
return (c == AltDirectorySeparatorChar);
}
return true;
}
public static bool IsPathRooted(string path)
{
if (path != null)
{
CheckInvalidPathChars(path);
int length = path.Length;
if (((length >= 1) && ((path[0] == DirectorySeparatorChar) || (path[0] == AltDirectorySeparatorChar))) || ((length >= 2) && (path[1] == VolumeSeparatorChar)))
{
return true;
}
}
return false;
}
}
}
|