Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssetPathHelper.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.IO
;
3
4
namespace
ReLogic.Content
;
5
6
public
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
}
ReLogic.Content.AssetPathHelper.CleanPath
static string CleanPath(string path)
Definition
AssetPathHelper.cs:8
ReLogic.Content.AssetPathHelper.CollapseParentDirectory
static int CollapseParentDirectory(ref string path, int position, int removeLength)
Definition
AssetPathHelper.cs:48
ReLogic.Content.AssetPathHelper
Definition
AssetPathHelper.cs:7
System.IO.Path.DirectorySeparatorChar
static readonly char DirectorySeparatorChar
Definition
Path.cs:71
System.IO.Path
Definition
Path.cs:8
System.Math.Max
static byte Max(byte val1, byte val2)
Definition
Math.cs:738
System.Math
Definition
Math.cs:13
ReLogic.Content
Definition
IAssetReader.cs:5
System.IO
Definition
ConsoleStream.cs:3
System.StringComparison
StringComparison
Definition
StringComparison.cs:4
System
Definition
BlockingCollection.cs:8
source
ReLogic
ReLogic.Content
AssetPathHelper.cs
Generated by
1.10.0