using System.Collections.Generic; using System.IO; namespace StardewModdingAPI.Toolkit.Utilities.PathLookups { /// An API for file lookups within a root directory with minimal preprocessing. internal class MinimalFileLookup : IFileLookup { /********* ** Accessors *********/ /// The file lookups by root path. private static readonly Dictionary CachedRoots = new(); /// The root directory path for relative paths. private readonly string RootPath; /********* ** Public methods *********/ /// Construct an instance. /// The root directory path for relative paths. public MinimalFileLookup(string rootPath) { this.RootPath = rootPath; } /// public FileInfo GetFile(string relativePath) { return new( Path.Combine(this.RootPath, PathUtilities.NormalizePath(relativePath)) ); } /// public void Add(string relativePath) { } /// Get a cached dictionary of relative paths within a root path, for case-insensitive file lookups. /// The root path to scan. public static MinimalFileLookup GetCachedFor(string rootPath) { rootPath = PathUtilities.NormalizePath(rootPath); if (!MinimalFileLookup.CachedRoots.TryGetValue(rootPath, out MinimalFileLookup? lookup)) MinimalFileLookup.CachedRoots[rootPath] = lookup = new MinimalFileLookup(rootPath); return lookup; } } }