From 4e2d7f2550b05e410735f51beac76ed040178cf4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 1 Apr 2022 23:42:37 -0400 Subject: make mod file paths case-insensitive in all SMAPI APIs --- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 9ed989da..a451fd7c 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -9,7 +9,7 @@ using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Toolkit.Serialization; -using StardewModdingAPI.Toolkit.Utilities; +using StardewModdingAPI.Utilities; using StardewValley; using xTile; using xTile.Format; @@ -32,6 +32,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The game content manager used for map tilesheets not provided by the mod. private readonly IContentManager GameContentManager; + /// A case-insensitive lookup of relative paths within the . + private readonly CaseInsensitivePathCache RelativePathCache; + /// If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder. private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" }; @@ -52,10 +55,12 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Encapsulates SMAPI's JSON file parsing. /// A callback to invoke when the content manager is being disposed. /// Whether to enable more aggressive memory optimizations. - public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onDisposing, bool aggressiveMemoryOptimizations) + /// A case-insensitive lookup of relative paths within the . + public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onDisposing, bool aggressiveMemoryOptimizations, CaseInsensitivePathCache relativePathCache) : base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true, aggressiveMemoryOptimizations: aggressiveMemoryOptimizations) { this.GameContentManager = gameContentManager; + this.RelativePathCache = relativePathCache; this.JsonHelper = jsonHelper; this.ModName = modName; @@ -198,7 +203,7 @@ namespace StardewModdingAPI.Framework.ContentManagers public IAssetName GetInternalAssetKey(string key) { FileInfo file = this.GetModFile(key); - string relativePath = PathUtilities.GetRelativePath(this.RootDirectory, file.FullName); + string relativePath = Path.GetRelativePath(this.RootDirectory, file.FullName); string internalKey = Path.Combine(this.Name, relativePath); return this.Coordinator.ParseAssetName(internalKey, allowLocales: false); @@ -212,6 +217,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The asset path relative to the content folder. private FileInfo GetModFile(string path) { + // map to case-insensitive path if needed + path = this.RelativePathCache.GetFilePath(path); + // try exact match FileInfo file = new(Path.Combine(this.FullRootDirectory, path)); -- cgit