diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-30 01:06:57 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-30 01:06:57 -0400 |
commit | d21f8d6b22d500ec627f0448f132b37d516e3830 (patch) | |
tree | 8e8f3c2b39efa56ede5e60d21df732f6cc571abb | |
parent | 06c4273c1e263eee6efcecad16b22ef4e03a0f1f (diff) | |
download | SMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.tar.gz SMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.tar.bz2 SMAPI-d21f8d6b22d500ec627f0448f132b37d516e3830.zip |
fix crossplatform compatibility (#257)
-rw-r--r-- | src/StardewModdingAPI/Framework/ContentHelper.cs | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/SContentManager.cs | 17 |
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); } |