-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
38 lines (34 loc) · 1.06 KB
/
Utils.cs
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
using System;
using System.IO;
namespace OpenLocalization
{
internal static class PathUtils
{
static public string GetPathRelative(string root, string dest)
{
var rootUri = new Uri(Path.GetFullPath(root) + "/", UriKind.Absolute);
var destUri = new Uri(dest, UriKind.Absolute);
return Uri.UnescapeDataString(rootUri.MakeRelativeUri(destUri).ToString());
}
static public string GetPathPossiblyRelativeToGameRoot(string path)
{
var relative = GetPathRelative(BepInEx.Paths.GameRootPath, path);
if (relative.StartsWith(".."))
{
return path;
}
return relative.Replace('\\', '/');
}
}
internal static class StringExtensions
{
public static string NullIfEmpty(this string s)
{
return string.IsNullOrEmpty(s) ? null : s;
}
public static string NullIfWhiteSpace(this string s)
{
return string.IsNullOrWhiteSpace(s) ? null : s;
}
}
}