summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit/Utilities
diff options
context:
space:
mode:
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.cs20
-rw-r--r--src/SMAPI.Toolkit/Utilities/PathLookups/MinimalPathLookup.cs31
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) { }
+ }
+}