summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities/PathUtilities.cs')
-rw-r--r--src/SMAPI.Toolkit/Utilities/PathUtilities.cs36
1 files changed, 0 insertions, 36 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
index 9a0e2ea7..d035d4cd 100644
--- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
+++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
@@ -92,43 +92,7 @@ namespace StardewModdingAPI.Toolkit.Utilities
[Pure]
public static string GetRelativePath(string sourceDir, string targetPath)
{
-#if NET5_0
return Path.GetRelativePath(sourceDir, targetPath);
-#else
- // NOTE:
- // this is a heuristic implementation that works in the cases SMAPI needs it for, but it
- // doesn't handle all edge cases (e.g. case-sensitivity on Linux, or traversing between
- // UNC paths on Windows). SMAPI and mods will use the more robust .NET 5 version anyway
- // though, this is only for compatibility with the mod build package.
-
- // convert to URIs
- Uri from = new(sourceDir.TrimEnd(PathUtilities.PossiblePathSeparators) + "/");
- Uri to = new(targetPath.TrimEnd(PathUtilities.PossiblePathSeparators) + "/");
- if (from.Scheme != to.Scheme)
- throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{sourceDir}'.");
-
- // get relative path
- string rawUrl = Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString());
- if (rawUrl.StartsWith("file://"))
- rawUrl = PathUtilities.WindowsUncRoot + rawUrl.Substring("file://".Length);
- string relative = PathUtilities.NormalizePath(rawUrl);
-
- // normalize
- if (relative == "")
- relative = ".";
- else
- {
- // trim trailing slash from URL
- if (relative.EndsWith(PathUtilities.PreferredPathSeparator.ToString()))
- relative = relative.Substring(0, relative.Length - 1);
-
- // fix root
- if (relative.StartsWith("file:") && !targetPath.Contains("file:"))
- relative = relative.Substring("file:".Length);
- }
-
- return relative;
-#endif
}
/// <summary>Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain <c>../</c>).</summary>