From 1974324c43b093a360507546e8be12ad594b56f2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 16 Apr 2022 13:41:37 -0400 Subject: make EntryDll manifest field case-insensitive --- src/SMAPI/Utilities/CaseInsensitivePathCache.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Utilities/CaseInsensitivePathCache.cs') diff --git a/src/SMAPI/Utilities/CaseInsensitivePathCache.cs b/src/SMAPI/Utilities/CaseInsensitivePathCache.cs index 2ac1b9f9..04fdcfae 100644 --- a/src/SMAPI/Utilities/CaseInsensitivePathCache.cs +++ b/src/SMAPI/Utilities/CaseInsensitivePathCache.cs @@ -16,6 +16,9 @@ namespace StardewModdingAPI.Utilities /// A case-insensitive lookup of file paths within the . Each path is listed in both file path and asset name format, so it's usable in both contexts without needing to re-parse paths. private readonly Lazy> RelativePathCache; + /// The case-insensitive path caches by root path. + private static readonly Dictionary CachesByRootPath = new(StringComparer.OrdinalIgnoreCase); + /********* ** Public methods @@ -65,6 +68,18 @@ namespace StardewModdingAPI.Utilities this.CacheRawPath(this.RelativePathCache.Value, relativePath); } + /// Get a cached dictionary of relative paths within a root path, for case-insensitive file lookups. + /// The root path to scan. + public static CaseInsensitivePathCache GetFor(string rootPath) + { + rootPath = PathUtilities.NormalizePath(rootPath); + + if (!CaseInsensitivePathCache.CachesByRootPath.TryGetValue(rootPath, out CaseInsensitivePathCache? cache)) + CaseInsensitivePathCache.CachesByRootPath[rootPath] = cache = new CaseInsensitivePathCache(rootPath); + + return cache; + } + /********* ** Private methods @@ -82,15 +97,13 @@ namespace StardewModdingAPI.Utilities if (this.RelativePathCache.Value.TryGetValue(relativePath, out string? resolved)) return resolved; - // file exists but isn't cached for some reason - // cache it now so any later references to it are case-insensitive + // keep capitalization as-is if (File.Exists(Path.Combine(this.RootPath, relativePath))) { + // file exists but isn't cached for some reason + // cache it now so any later references to it are case-insensitive this.CacheRawPath(this.RelativePathCache.Value, relativePath); - return relativePath; } - - // no such file, keep capitalization as-is return relativePath; } -- cgit