summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-30 01:06:57 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-30 01:06:57 -0400
commitd21f8d6b22d500ec627f0448f132b37d516e3830 (patch)
tree8e8f3c2b39efa56ede5e60d21df732f6cc571abb /src
parent06c4273c1e263eee6efcecad16b22ef4e03a0f1f (diff)
downloadSMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.tar.gz
SMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.tar.bz2
SMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.zip
fix crossplatform compatibility (#257)
Diffstat (limited to 'src')
-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);
}