diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-02 18:49:49 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-12-02 18:49:49 -0500 |
commit | 5cc5f089b9645a60385ff293b5a7202f260bfc0f (patch) | |
tree | 68f8bee734d164277f711b8ac54bd1064c0757d6 /src/SMAPI/Framework/SContentManager.cs | |
parent | e0b72374cd14298aacc6f71dc391fdc9814be37c (diff) | |
parent | dc4f89acb6cd8f838934b60e8f5645c6145706f8 (diff) | |
download | SMAPI-5cc5f089b9645a60385ff293b5a7202f260bfc0f.tar.gz SMAPI-5cc5f089b9645a60385ff293b5a7202f260bfc0f.tar.bz2 SMAPI-5cc5f089b9645a60385ff293b5a7202f260bfc0f.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/SContentManager.cs')
-rw-r--r-- | src/SMAPI/Framework/SContentManager.cs | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/SMAPI/Framework/SContentManager.cs b/src/SMAPI/Framework/SContentManager.cs index a755a6df..524b2d17 100644 --- a/src/SMAPI/Framework/SContentManager.cs +++ b/src/SMAPI/Framework/SContentManager.cs @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Framework this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor)); this.Cache = new ContentCache(this, reflection, SContentManager.PossiblePathSeparators, SContentManager.PreferredPathSeparator); this.GetKeyLocale = reflection.GetPrivateMethod(this, "languageCode"); - this.ModContentPrefix = this.GetRelativePath(Constants.ModPath); + this.ModContentPrefix = this.GetAssetNameFromFilePath(Constants.ModPath); // get asset data this.CoreAssets = new CoreAssets(this.NormaliseAssetName); @@ -140,19 +140,17 @@ namespace StardewModdingAPI.Framework throw new ArgumentException("The asset key or local path contains invalid characters."); } - /// <summary>Get a directory path relative to the content root.</summary> - /// <param name="targetPath">The target file path.</param> - public string GetRelativePath(string targetPath) + /// <summary>Convert an absolute file path into a appropriate asset name.</summary> + /// <param name="absolutePath">The absolute path to the file.</param> + public string GetAssetNameFromFilePath(string absolutePath) { - // convert to URIs - Uri from = new Uri(this.FullRootDirectory + "/"); - Uri to = new Uri(targetPath + "/"); - if (from.Scheme != to.Scheme) - throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{this.FullRootDirectory}'."); - - // get relative path - return Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString()) - .Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar); // use correct separator for platform +#if SMAPI_FOR_WINDOWS + // XNA doesn't allow absolute asset paths, so get a path relative to the content folder + return this.GetRelativePath(absolutePath); +#else + // MonoGame is weird about relative paths on Mac, but allows absolute paths + return absolutePath; +#endif } /**** @@ -395,6 +393,21 @@ namespace StardewModdingAPI.Framework /**** ** Asset name/key handling ****/ + /// <summary>Get a directory or file path relative to the content root.</summary> + /// <param name="targetPath">The target file path.</param> + private string GetRelativePath(string targetPath) + { + // convert to URIs + Uri from = new Uri(this.FullRootDirectory + "/"); + Uri to = new Uri(targetPath + "/"); + if (from.Scheme != to.Scheme) + throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{this.FullRootDirectory}'."); + + // get relative path + return Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString()) + .Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar); // use correct separator for platform + } + /// <summary>Get the locale codes (like <c>ja-JP</c>) used in asset keys.</summary> /// <param name="reflection">Simplifies access to private game code.</param> private IDictionary<string, LanguageCode> GetKeyLocales(Reflector reflection) @@ -551,19 +564,6 @@ namespace StardewModdingAPI.Framework return file; } - /// <summary>Get a file from the game's content folder.</summary> - /// <param name="key">The asset key.</param> - private FileInfo GetContentFolderFile(string key) - { - // get file path - string path = Path.Combine(this.FullRootDirectory, key); - if (!path.EndsWith(".xnb")) - path += ".xnb"; - - // get file - return new FileInfo(path); - } - /// <summary>Load the initial asset from the registered <see cref="Loaders"/>.</summary> /// <param name="info">The basic asset metadata.</param> /// <returns>Returns the loaded asset metadata, or <c>null</c> if no loader matched.</returns> |