diff options
| author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 20:58:19 -0400 |
|---|---|---|
| committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-06 20:58:19 -0400 |
| commit | e7e6327b3c85d52ab666aad2a054fbbdbd9431da (patch) | |
| tree | 436b963d47bd8062ab38b676f57cbfb5c4e99821 /src/SMAPI.Toolkit/Utilities | |
| parent | c8ad50dad1d706a1901798f9396f6becfea36c0e (diff) | |
| parent | b45f50b57e3895620a682e2c7a438391dce0c5dd (diff) | |
| download | SMAPI-e7e6327b3c85d52ab666aad2a054fbbdbd9431da.tar.gz SMAPI-e7e6327b3c85d52ab666aad2a054fbbdbd9431da.tar.bz2 SMAPI-e7e6327b3c85d52ab666aad2a054fbbdbd9431da.zip | |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities')
| -rw-r--r-- | src/SMAPI.Toolkit/Utilities/PathLookups/CaseInsensitivePathLookup.cs (renamed from src/SMAPI.Toolkit/Utilities/CaseInsensitivePathLookup.cs) | 17 | ||||
| -rw-r--r-- | src/SMAPI.Toolkit/Utilities/PathLookups/IFilePathLookup.cs | 20 | ||||
| -rw-r--r-- | src/SMAPI.Toolkit/Utilities/PathLookups/MinimalPathLookup.cs | 31 |
3 files changed, 57 insertions, 11 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/CaseInsensitivePathLookup.cs b/src/SMAPI.Toolkit/Utilities/PathLookups/CaseInsensitivePathLookup.cs index 12fad008..9cc00737 100644 --- a/src/SMAPI.Toolkit/Utilities/CaseInsensitivePathLookup.cs +++ b/src/SMAPI.Toolkit/Utilities/PathLookups/CaseInsensitivePathLookup.cs @@ -2,10 +2,10 @@ using System; using System.Collections.Generic; using System.IO; -namespace StardewModdingAPI.Toolkit.Utilities +namespace StardewModdingAPI.Toolkit.Utilities.PathLookups { - /// <summary>Provides an API for case-insensitive relative path lookups within a root directory.</summary> - internal class CaseInsensitivePathLookup + /// <summary>An API for case-insensitive relative path lookups within a root directory.</summary> + internal class CaseInsensitivePathLookup : IFilePathLookup { /********* ** Fields @@ -32,24 +32,19 @@ namespace StardewModdingAPI.Toolkit.Utilities this.RelativePathCache = new(() => this.GetRelativePathCache(searchOption)); } - /// <summary>Get the exact capitalization for a given relative file path.</summary> - /// <param name="relativePath">The relative path.</param> - /// <remarks>Returns the resolved path in file path format, else the normalized <paramref name="relativePath"/>.</remarks> + /// <inheritdoc /> public string GetFilePath(string relativePath) { return this.GetImpl(PathUtilities.NormalizePath(relativePath)); } - /// <summary>Get the exact capitalization for a given asset name.</summary> - /// <param name="relativePath">The relative path.</param> - /// <remarks>Returns the resolved path in asset name format, else the normalized <paramref name="relativePath"/>.</remarks> + /// <inheritdoc /> public string GetAssetName(string relativePath) { return this.GetImpl(PathUtilities.NormalizeAssetName(relativePath)); } - /// <summary>Add a relative path that was just created by a SMAPI API.</summary> - /// <param name="relativePath">The relative path. This must already be normalized in asset name or file path format.</param> + /// <inheritdoc /> public void Add(string relativePath) { // skip if cache isn't created yet (no need to add files manually in that case) diff --git a/src/SMAPI.Toolkit/Utilities/PathLookups/IFilePathLookup.cs b/src/SMAPI.Toolkit/Utilities/PathLookups/IFilePathLookup.cs new file mode 100644 index 00000000..678e1383 --- /dev/null +++ b/src/SMAPI.Toolkit/Utilities/PathLookups/IFilePathLookup.cs @@ -0,0 +1,20 @@ +namespace StardewModdingAPI.Toolkit.Utilities.PathLookups +{ + /// <summary>An API for relative path lookups within a root directory.</summary> + internal interface IFilePathLookup + { + /// <summary>Get the actual path for a given relative file path.</summary> + /// <param name="relativePath">The relative path.</param> + /// <remarks>Returns the resolved path in file path format, else the normalized <paramref name="relativePath"/>.</remarks> + string GetFilePath(string relativePath); + + /// <summary>Get the actual path for a given asset name.</summary> + /// <param name="relativePath">The relative path.</param> + /// <remarks>Returns the resolved path in asset name format, else the normalized <paramref name="relativePath"/>.</remarks> + string GetAssetName(string relativePath); + + /// <summary>Add a relative path that was just created by a SMAPI API.</summary> + /// <param name="relativePath">The relative path. This must already be normalized in asset name or file path format.</param> + void Add(string relativePath); + } +} diff --git a/src/SMAPI.Toolkit/Utilities/PathLookups/MinimalPathLookup.cs b/src/SMAPI.Toolkit/Utilities/PathLookups/MinimalPathLookup.cs new file mode 100644 index 00000000..2cf14704 --- /dev/null +++ b/src/SMAPI.Toolkit/Utilities/PathLookups/MinimalPathLookup.cs @@ -0,0 +1,31 @@ +namespace StardewModdingAPI.Toolkit.Utilities.PathLookups +{ + /// <summary>An API for relative path lookups within a root directory with minimal preprocessing.</summary> + internal class MinimalPathLookup : IFilePathLookup + { + /********* + ** Accessors + *********/ + /// <summary>A singleton instance for reuse.</summary> + public static readonly MinimalPathLookup Instance = new(); + + + /********* + ** Public methods + *********/ + /// <inheritdoc /> + public string GetFilePath(string relativePath) + { + return PathUtilities.NormalizePath(relativePath); + } + + /// <inheritdoc /> + public string GetAssetName(string relativePath) + { + return PathUtilities.NormalizeAssetName(relativePath); + } + + /// <inheritdoc /> + public void Add(string relativePath) { } + } +} |
