summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-03 18:36:39 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-03 18:36:39 -0400
commitc5b8cd626489dad6210fe629658314dfc85f4d08 (patch)
tree3e30c3172e6c0bb3e422036581684593156fad22 /src/SMAPI.Toolkit/Utilities/PathUtilities.cs
parent4ee96a20bb6c74bc7ff6176a03e7f15d47cddfa8 (diff)
parent6d4ea7f0bd584602632e6e308d52bb369b30006f (diff)
downloadSMAPI-c5b8cd626489dad6210fe629658314dfc85f4d08.tar.gz
SMAPI-c5b8cd626489dad6210fe629658314dfc85f4d08.tar.bz2
SMAPI-c5b8cd626489dad6210fe629658314dfc85f4d08.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities/PathUtilities.cs')
-rw-r--r--src/SMAPI.Toolkit/Utilities/PathUtilities.cs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
index babc0981..020ebc6d 100644
--- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
+++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs
@@ -23,9 +23,12 @@ namespace StardewModdingAPI.Toolkit.Utilities
/// <summary>The possible directory separator characters in a file path.</summary>
public static readonly char[] PossiblePathSeparators = new[] { '/', '\\', Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }.Distinct().ToArray();
- /// <summary>The preferred directory separator character in an asset key.</summary>
+ /// <summary>The preferred directory separator character in a file path.</summary>
public static readonly char PreferredPathSeparator = Path.DirectorySeparatorChar;
+ /// <summary>The preferred directory separator character in an asset key.</summary>
+ public static readonly char PreferredAssetSeparator = PathUtilities.PreferredPathSeparator;
+
/*********
** Public methods
@@ -41,8 +44,16 @@ namespace StardewModdingAPI.Toolkit.Utilities
: path.Split(PathUtilities.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries);
}
- /// <summary>Normalize separators in a file path.</summary>
+ /// <summary>Normalize an asset name to match how MonoGame's content APIs would normalize and cache it.</summary>
+ /// <param name="assetName">The asset name to normalize.</param>
+ public static string NormalizeAssetName(string assetName)
+ {
+ return string.Join(PathUtilities.PreferredAssetSeparator.ToString(), PathUtilities.GetSegments(assetName)); // based on MonoGame's ContentManager.Load<T> logic
+ }
+
+ /// <summary>Normalize separators in a file path for the current platform.</summary>
/// <param name="path">The file path to normalize.</param>
+ /// <remarks>This should only be used for file paths. For asset names, use <see cref="NormalizeAssetName"/> instead.</remarks>
[Pure]
public static string NormalizePath(string path)
{