summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-07 01:51:50 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-07 01:51:50 -0400
commit6b05296e71c32abd158f354eeeaf1e135e72e6e2 (patch)
tree417ee622b7cf56bc98f6a55ddb7ab63f414c25e4 /src/SMAPI.Toolkit/Utilities/PathUtilities.cs
parente58e8a22836081ec4baffa5a9b4b093a329f3d88 (diff)
downloadSMAPI-6b05296e71c32abd158f354eeeaf1e135e72e6e2.tar.gz
SMAPI-6b05296e71c32abd158f354eeeaf1e135e72e6e2.tar.bz2
SMAPI-6b05296e71c32abd158f354eeeaf1e135e72e6e2.zip
migrate mod build package to .NET 5 to allow full nullable annotations (#837)
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>