-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathHelper.cs
More file actions
49 lines (39 loc) · 1.38 KB
/
PathHelper.cs
File metadata and controls
49 lines (39 loc) · 1.38 KB
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
using System.Globalization;
public static class PathHelper {
static CultureInfo cultureInfo = new CultureInfo("en-US");
public static bool EndsWith(string path, string endsWith, bool ignoreCase) {
if (path == "")
return false;
if (path.EndsWith(endsWith, ignoreCase, cultureInfo))
return true;
else if (path.EndsWith(endsWith + Path.DirectorySeparatorChar, ignoreCase, cultureInfo))
return true;
else if (path.EndsWith(endsWith + '\\', ignoreCase, cultureInfo))
return true;
return false;
}
public static bool GetSpritesFolder(string path, out string outPath, bool onlyResources = false) {
if (path == "") {
outPath = "";
return false;
}
while (true) {
System.IO.DirectoryInfo? parent = Directory.GetParent(path);
if (parent == null) {
outPath = "";
return false;
}
path = parent.FullName;
if (EndsInRootPath(path, onlyResources)) {
outPath = path;
return true;
}
}
}
public static bool EndsInRootPath(string path, bool onlyResources = false) {
if (!onlyResources && EndsWith(path, "Sprites", true)) {
return true;
}
return EndsWith(path, "Resources", true);
}
}