Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssetPathHelper.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3
4namespace ReLogic.Content;
5
6public static class AssetPathHelper
7{
8 public static string CleanPath(string path)
9 {
10 path = path.Replace("/", "\\", StringComparison.Ordinal);
11 path = path.Replace("\\.\\", "\\", StringComparison.Ordinal);
12 while (path.StartsWith(".\\", StringComparison.Ordinal))
13 {
14 path = path.Substring(".\\".Length);
15 }
16 while (path.EndsWith("\\.", StringComparison.Ordinal))
17 {
18 path = ((path.Length <= "\\.".Length) ? "\\" : path.Substring(0, path.Length - "\\.".Length));
19 }
20 int num;
21 for (num = 1; num < path.Length; num = CollapseParentDirectory(ref path, num, "\\..\\".Length))
22 {
23 num = path.IndexOf("\\..\\", num, StringComparison.Ordinal);
24 if (num < 0)
25 {
26 break;
27 }
28 }
29 if (path.EndsWith("\\..", StringComparison.Ordinal))
30 {
31 int num2 = path.Length - "\\..".Length;
32 if (num2 > 0)
33 {
34 CollapseParentDirectory(ref path, num2, "\\..".Length);
35 }
36 }
37 if (path == ".")
38 {
39 path = string.Empty;
40 }
41 if (Path.DirectorySeparatorChar != '\\')
42 {
43 path = path.Replace("\\", Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal);
44 }
45 return path;
46 }
47
48 private static int CollapseParentDirectory(ref string path, int position, int removeLength)
49 {
50 int num = path.LastIndexOf("\\", position - 1, StringComparison.Ordinal) + 1;
51 path = path.Remove(num, position - num + removeLength);
52 return Math.Max(num - 1, 1);
53 }
54}
static string CleanPath(string path)
static int CollapseParentDirectory(ref string path, int position, int removeLength)
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static byte Max(byte val1, byte val2)
Definition Math.cs:738