summaryrefslogtreecommitdiff
path: root/src/SMAPI.Toolkit
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Toolkit')
-rw-r--r--src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs18
-rw-r--r--src/SMAPI.Toolkit/ModToolkit.cs10
-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
5 files changed, 73 insertions, 23 deletions
diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
index 24485620..aa4c3338 100644
--- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
+++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs
@@ -5,7 +5,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using StardewModdingAPI.Toolkit.Serialization;
using StardewModdingAPI.Toolkit.Serialization.Models;
-using StardewModdingAPI.Toolkit.Utilities;
+using StardewModdingAPI.Toolkit.Utilities.PathLookups;
namespace StardewModdingAPI.Toolkit.Framework.ModScanning
{
@@ -95,19 +95,20 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
/// <summary>Extract information about all mods in the given folder.</summary>
/// <param name="rootPath">The root folder containing mods.</param>
- public IEnumerable<ModFolder> GetModFolders(string rootPath)
+ /// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
+ public IEnumerable<ModFolder> GetModFolders(string rootPath, bool useCaseInsensitiveFilePaths)
{
DirectoryInfo root = new(rootPath);
- return this.GetModFolders(root, root);
+ return this.GetModFolders(root, root, useCaseInsensitiveFilePaths);
}
/// <summary>Extract information about all mods in the given folder.</summary>
/// <param name="rootPath">The root folder containing mods. Only the <paramref name="modPath"/> will be searched, but this field allows it to be treated as a potential mod folder of its own.</param>
/// <param name="modPath">The mod path to search.</param>
- // /// <param name="tryConsolidateMod">If the folder contains multiple XNB mods, treat them as subfolders of a single mod. This is useful when reading a single mod archive, as opposed to a mods folder.</param>
- public IEnumerable<ModFolder> GetModFolders(string rootPath, string modPath)
+ /// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
+ public IEnumerable<ModFolder> GetModFolders(string rootPath, string modPath, bool useCaseInsensitiveFilePaths)
{
- return this.GetModFolders(root: new DirectoryInfo(rootPath), folder: new DirectoryInfo(modPath));
+ return this.GetModFolders(root: new DirectoryInfo(rootPath), folder: new DirectoryInfo(modPath), useCaseInsensitiveFilePaths: useCaseInsensitiveFilePaths);
}
/// <summary>Extract information from a mod folder.</summary>
@@ -195,7 +196,8 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
/// <summary>Recursively extract information about all mods in the given folder.</summary>
/// <param name="root">The root mod folder.</param>
/// <param name="folder">The folder to search for mods.</param>
- private IEnumerable<ModFolder> GetModFolders(DirectoryInfo root, DirectoryInfo folder)
+ /// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
+ private IEnumerable<ModFolder> GetModFolders(DirectoryInfo root, DirectoryInfo folder, bool useCaseInsensitiveFilePaths)
{
bool isRoot = folder.FullName == root.FullName;
@@ -214,7 +216,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
// find mods in subfolders
if (this.IsModSearchFolder(root, folder))
{
- IEnumerable<ModFolder> subfolders = folder.EnumerateDirectories().SelectMany(sub => this.GetModFolders(root, sub));
+ IEnumerable<ModFolder> subfolders = folder.EnumerateDirectories().SelectMany(sub => this.GetModFolders(root, sub, useCaseInsensitiveFilePaths));
if (!isRoot)
subfolders = this.TryConsolidate(root, folder, subfolders.ToArray());
foreach (ModFolder subfolder in subfolders)
diff --git a/src/SMAPI.Toolkit/ModToolkit.cs b/src/SMAPI.Toolkit/ModToolkit.cs
index 51f6fa24..ce14b057 100644
--- a/src/SMAPI.Toolkit/ModToolkit.cs
+++ b/src/SMAPI.Toolkit/ModToolkit.cs
@@ -72,17 +72,19 @@ namespace StardewModdingAPI.Toolkit
/// <summary>Extract information about all mods in the given folder.</summary>
/// <param name="rootPath">The root folder containing mods.</param>
- public IEnumerable<ModFolder> GetModFolders(string rootPath)
+ /// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
+ public IEnumerable<ModFolder> GetModFolders(string rootPath, bool useCaseInsensitiveFilePaths)
{
- return new ModScanner(this.JsonHelper).GetModFolders(rootPath);
+ return new ModScanner(this.JsonHelper).GetModFolders(rootPath, useCaseInsensitiveFilePaths);
}
/// <summary>Extract information about all mods in the given folder.</summary>
/// <param name="rootPath">The root folder containing mods. Only the <paramref name="modPath"/> will be searched, but this field allows it to be treated as a potential mod folder of its own.</param>
/// <param name="modPath">The mod path to search.</param>
- public IEnumerable<ModFolder> GetModFolders(string rootPath, string modPath)
+ /// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
+ public IEnumerable<ModFolder> GetModFolders(string rootPath, string modPath, bool useCaseInsensitiveFilePaths)
{
- return new ModScanner(this.JsonHelper).GetModFolders(rootPath, modPath);
+ return new ModScanner(this.JsonHelper).GetModFolders(rootPath, modPath, useCaseInsensitiveFilePaths);
}
/// <summary>Get an update URL for an update key (if valid).</summary>
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) { }
+ }
+}