summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Framework/ContentHelper.cs1
-rw-r--r--src/StardewModdingAPI/Framework/SContentManager.cs17
2 files changed, 13 insertions, 5 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs
index 7cf726e1..762b7e35 100644
--- a/src/StardewModdingAPI/Framework/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ContentHelper.cs
@@ -61,6 +61,7 @@ namespace StardewModdingAPI.Framework
case ContentSource.ModFolder:
// find content file
+ key = this.ContentManager.NormalisePathSeparators(key);
FileInfo file = new FileInfo(Path.Combine(this.ModFolderPath, key));
if (!file.Exists && file.Extension == "")
file = new FileInfo(Path.Combine(this.ModFolderPath, key + ".xnb"));
diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs
index 99814c94..88e1df2b 100644
--- a/src/StardewModdingAPI/Framework/SContentManager.cs
+++ b/src/StardewModdingAPI/Framework/SContentManager.cs
@@ -83,15 +83,22 @@ namespace StardewModdingAPI.Framework
this.NormaliseAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load<T> logic
}
+ /// <summary>Normalise path separators in a file path. For asset keys, see <see cref="NormaliseAssetName"/> instead.</summary>
+ /// <param name="path">The file path to normalise.</param>
+ public string NormalisePathSeparators(string path)
+ {
+ string[] parts = path.Split(SContentManager.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries);
+ string normalised = string.Join(SContentManager.PreferredPathSeparator, parts);
+ if (path.StartsWith(SContentManager.PreferredPathSeparator))
+ normalised = SContentManager.PreferredPathSeparator + normalised; // keep root slash
+ return normalised;
+ }
+
/// <summary>Normalise an asset name so it's consistent with the underlying cache.</summary>
/// <param name="assetName">The asset key.</param>
public string NormaliseAssetName(string assetName)
{
- // ensure name format is consistent
- string[] parts = assetName.Split(SContentManager.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries);
- assetName = string.Join(SContentManager.PreferredPathSeparator, parts);
-
- // apply platform normalisation logic
+ assetName = this.NormalisePathSeparators(assetName);
return this.NormaliseAssetNameForPlatform(assetName);
}