disable case-insensitive paths by default pending performance rework
This commit is contained in:
parent
42bf82d870
commit
c1342bd4cd
|
@ -3,6 +3,8 @@
|
||||||
# Release notes
|
# Release notes
|
||||||
## Upcoming release
|
## Upcoming release
|
||||||
* For players:
|
* For players:
|
||||||
|
* Case-insensitive file paths (introduced in 3.14.0) are now disabled by default.
|
||||||
|
_You can enable them via `smapi-internal/config.json` if needed. These will be re-enabled in a later version after reworking them to reduce performance impact._
|
||||||
* Updated compatibility list.
|
* Updated compatibility list.
|
||||||
|
|
||||||
## 3.14.0
|
## 3.14.0
|
||||||
|
|
|
@ -435,8 +435,8 @@ namespace StardewModdingApi.Installer
|
||||||
{
|
{
|
||||||
this.PrintDebug("Adding bundled mods...");
|
this.PrintDebug("Adding bundled mods...");
|
||||||
|
|
||||||
ModFolder[] targetMods = toolkit.GetModFolders(paths.ModsPath).ToArray();
|
ModFolder[] targetMods = toolkit.GetModFolders(paths.ModsPath, useCaseInsensitiveFilePaths: true).ToArray();
|
||||||
foreach (ModFolder sourceMod in toolkit.GetModFolders(bundledModsDir.FullName))
|
foreach (ModFolder sourceMod in toolkit.GetModFolders(bundledModsDir.FullName, useCaseInsensitiveFilePaths: true))
|
||||||
{
|
{
|
||||||
// validate source mod
|
// validate source mod
|
||||||
if (sourceMod.Manifest == null)
|
if (sourceMod.Manifest == null)
|
||||||
|
|
|
@ -12,6 +12,7 @@ using StardewModdingAPI.Toolkit;
|
||||||
using StardewModdingAPI.Toolkit.Framework.ModData;
|
using StardewModdingAPI.Toolkit.Framework.ModData;
|
||||||
using StardewModdingAPI.Toolkit.Framework.UpdateData;
|
using StardewModdingAPI.Toolkit.Framework.UpdateData;
|
||||||
using StardewModdingAPI.Toolkit.Serialization.Models;
|
using StardewModdingAPI.Toolkit.Serialization.Models;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
using SemanticVersion = StardewModdingAPI.SemanticVersion;
|
using SemanticVersion = StardewModdingAPI.SemanticVersion;
|
||||||
|
|
||||||
namespace SMAPI.Tests.Core
|
namespace SMAPI.Tests.Core
|
||||||
|
@ -34,7 +35,7 @@ namespace SMAPI.Tests.Core
|
||||||
Directory.CreateDirectory(rootFolder);
|
Directory.CreateDirectory(rootFolder);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase()).ToArray();
|
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase(), useCaseInsensitiveFilePaths: true).ToArray();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
Assert.AreEqual(0, mods.Length, 0, $"Expected to find zero manifests, found {mods.Length} instead.");
|
Assert.AreEqual(0, mods.Length, 0, $"Expected to find zero manifests, found {mods.Length} instead.");
|
||||||
|
@ -52,7 +53,7 @@ namespace SMAPI.Tests.Core
|
||||||
Directory.CreateDirectory(modFolder);
|
Directory.CreateDirectory(modFolder);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase()).ToArray();
|
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase(), useCaseInsensitiveFilePaths: true).ToArray();
|
||||||
IModMetadata? mod = mods.FirstOrDefault();
|
IModMetadata? mod = mods.FirstOrDefault();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
|
@ -94,7 +95,7 @@ namespace SMAPI.Tests.Core
|
||||||
File.WriteAllText(filename, JsonConvert.SerializeObject(original));
|
File.WriteAllText(filename, JsonConvert.SerializeObject(original));
|
||||||
|
|
||||||
// act
|
// act
|
||||||
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase()).ToArray();
|
IModMetadata[] mods = new ModResolver().ReadManifests(new ModToolkit(), rootFolder, new ModDatabase(), useCaseInsensitiveFilePaths: true).ToArray();
|
||||||
IModMetadata? mod = mods.FirstOrDefault();
|
IModMetadata? mod = mods.FirstOrDefault();
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
|
@ -132,7 +133,7 @@ namespace SMAPI.Tests.Core
|
||||||
[Test(Description = "Assert that validation doesn't fail if there are no mods installed.")]
|
[Test(Description = "Assert that validation doesn't fail if there are no mods installed.")]
|
||||||
public void ValidateManifests_NoMods_DoesNothing()
|
public void ValidateManifests_NoMods_DoesNothing()
|
||||||
{
|
{
|
||||||
new ModResolver().ValidateManifests(Array.Empty<ModMetadata>(), apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, validateFilesExist: false);
|
new ModResolver().ValidateManifests(Array.Empty<ModMetadata>(), apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance, validateFilesExist: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test(Description = "Assert that validation skips manifests that have already failed without calling any other properties.")]
|
[Test(Description = "Assert that validation skips manifests that have already failed without calling any other properties.")]
|
||||||
|
@ -143,7 +144,7 @@ namespace SMAPI.Tests.Core
|
||||||
mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
|
mock.Setup(p => p.Status).Returns(ModMetadataStatus.Failed);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, validateFilesExist: false);
|
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance, validateFilesExist: false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
mock.VerifyGet(p => p.Status, Times.Once, "The validation did not check the manifest status.");
|
mock.VerifyGet(p => p.Status, Times.Once, "The validation did not check the manifest status.");
|
||||||
|
@ -160,7 +161,7 @@ namespace SMAPI.Tests.Core
|
||||||
});
|
});
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, validateFilesExist: false);
|
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance, validateFilesExist: false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
||||||
|
@ -174,7 +175,7 @@ namespace SMAPI.Tests.Core
|
||||||
mock.Setup(p => p.Manifest).Returns(this.GetManifest(minimumApiVersion: "1.1"));
|
mock.Setup(p => p.Manifest).Returns(this.GetManifest(minimumApiVersion: "1.1"));
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, validateFilesExist: false);
|
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance, validateFilesExist: false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
||||||
|
@ -189,7 +190,7 @@ namespace SMAPI.Tests.Core
|
||||||
Directory.CreateDirectory(directoryPath);
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null);
|
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
mock.Verify(p => p.SetStatus(ModMetadataStatus.Failed, It.IsAny<ModFailReason>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "The validation did not fail the metadata.");
|
||||||
|
@ -206,7 +207,7 @@ namespace SMAPI.Tests.Core
|
||||||
Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest(id: "Mod A", name: "Mod B", version: "1.0"), allowStatusChange: true);
|
Mock<IModMetadata> modB = this.GetMetadata(this.GetManifest(id: "Mod A", name: "Mod B", version: "1.0"), allowStatusChange: true);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { modA.Object, modB.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, validateFilesExist: false);
|
new ModResolver().ValidateManifests(new[] { modA.Object, modB.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance, validateFilesExist: false);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
modA.Verify(p => p.SetStatus(ModMetadataStatus.Failed, ModFailReason.Duplicate, It.IsAny<string>(), It.IsAny<string>()), Times.AtLeastOnce, "The validation did not fail the first mod with a unique ID.");
|
modA.Verify(p => p.SetStatus(ModMetadataStatus.Failed, ModFailReason.Duplicate, It.IsAny<string>(), It.IsAny<string>()), Times.AtLeastOnce, "The validation did not fail the first mod with a unique ID.");
|
||||||
|
@ -232,7 +233,7 @@ namespace SMAPI.Tests.Core
|
||||||
mock.Setup(p => p.DirectoryPath).Returns(modFolder);
|
mock.Setup(p => p.DirectoryPath).Returns(modFolder);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null);
|
new ModResolver().ValidateManifests(new[] { mock.Object }, apiVersion: new SemanticVersion("1.0"), getUpdateUrl: _ => null, getFilePathLookup: _ => MinimalPathLookup.Instance);
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
// if Moq doesn't throw a method-not-setup exception, the validation didn't override the status.
|
// if Moq doesn't throw a method-not-setup exception, the validation didn't override the status.
|
||||||
|
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using StardewModdingAPI.Toolkit.Serialization;
|
using StardewModdingAPI.Toolkit.Serialization;
|
||||||
using StardewModdingAPI.Toolkit.Serialization.Models;
|
using StardewModdingAPI.Toolkit.Serialization.Models;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
|
|
||||||
namespace StardewModdingAPI.Toolkit.Framework.ModScanning
|
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>
|
/// <summary>Extract information about all mods in the given folder.</summary>
|
||||||
/// <param name="rootPath">The root folder containing mods.</param>
|
/// <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);
|
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>
|
/// <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="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="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>
|
/// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
|
||||||
public IEnumerable<ModFolder> GetModFolders(string rootPath, string modPath)
|
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>
|
/// <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>
|
/// <summary>Recursively extract information about all mods in the given folder.</summary>
|
||||||
/// <param name="root">The root mod folder.</param>
|
/// <param name="root">The root mod folder.</param>
|
||||||
/// <param name="folder">The folder to search for mods.</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;
|
bool isRoot = folder.FullName == root.FullName;
|
||||||
|
|
||||||
|
@ -214,7 +216,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning
|
||||||
// find mods in subfolders
|
// find mods in subfolders
|
||||||
if (this.IsModSearchFolder(root, folder))
|
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)
|
if (!isRoot)
|
||||||
subfolders = this.TryConsolidate(root, folder, subfolders.ToArray());
|
subfolders = this.TryConsolidate(root, folder, subfolders.ToArray());
|
||||||
foreach (ModFolder subfolder in subfolders)
|
foreach (ModFolder subfolder in subfolders)
|
||||||
|
|
|
@ -72,17 +72,19 @@ namespace StardewModdingAPI.Toolkit
|
||||||
|
|
||||||
/// <summary>Extract information about all mods in the given folder.</summary>
|
/// <summary>Extract information about all mods in the given folder.</summary>
|
||||||
/// <param name="rootPath">The root folder containing mods.</param>
|
/// <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>
|
/// <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="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="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>
|
/// <summary>Get an update URL for an update key (if valid).</summary>
|
||||||
|
|
|
@ -2,10 +2,10 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
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>
|
/// <summary>An API for case-insensitive relative path lookups within a root directory.</summary>
|
||||||
internal class CaseInsensitivePathLookup
|
internal class CaseInsensitivePathLookup : IFilePathLookup
|
||||||
{
|
{
|
||||||
/*********
|
/*********
|
||||||
** Fields
|
** Fields
|
||||||
|
@ -32,24 +32,19 @@ namespace StardewModdingAPI.Toolkit.Utilities
|
||||||
this.RelativePathCache = new(() => this.GetRelativePathCache(searchOption));
|
this.RelativePathCache = new(() => this.GetRelativePathCache(searchOption));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Get the exact capitalization for a given relative file path.</summary>
|
/// <inheritdoc />
|
||||||
/// <param name="relativePath">The relative path.</param>
|
|
||||||
/// <remarks>Returns the resolved path in file path format, else the normalized <paramref name="relativePath"/>.</remarks>
|
|
||||||
public string GetFilePath(string relativePath)
|
public string GetFilePath(string relativePath)
|
||||||
{
|
{
|
||||||
return this.GetImpl(PathUtilities.NormalizePath(relativePath));
|
return this.GetImpl(PathUtilities.NormalizePath(relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Get the exact capitalization for a given asset name.</summary>
|
/// <inheritdoc />
|
||||||
/// <param name="relativePath">The relative path.</param>
|
|
||||||
/// <remarks>Returns the resolved path in asset name format, else the normalized <paramref name="relativePath"/>.</remarks>
|
|
||||||
public string GetAssetName(string relativePath)
|
public string GetAssetName(string relativePath)
|
||||||
{
|
{
|
||||||
return this.GetImpl(PathUtilities.NormalizeAssetName(relativePath));
|
return this.GetImpl(PathUtilities.NormalizeAssetName(relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Add a relative path that was just created by a SMAPI API.</summary>
|
/// <inheritdoc />
|
||||||
/// <param name="relativePath">The relative path. This must already be normalized in asset name or file path format.</param>
|
|
||||||
public void Add(string relativePath)
|
public void Add(string relativePath)
|
||||||
{
|
{
|
||||||
// skip if cache isn't created yet (no need to add files manually in that case)
|
// skip if cache isn't created yet (no need to add files manually in that case)
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ using StardewModdingAPI.Internal;
|
||||||
using StardewModdingAPI.Metadata;
|
using StardewModdingAPI.Metadata;
|
||||||
using StardewModdingAPI.Toolkit.Serialization;
|
using StardewModdingAPI.Toolkit.Serialization;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using StardewValley.GameData;
|
using StardewValley.GameData;
|
||||||
using xTile;
|
using xTile;
|
||||||
|
@ -34,6 +35,9 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <summary>Whether to enable more aggressive memory optimizations.</summary>
|
/// <summary>Whether to enable more aggressive memory optimizations.</summary>
|
||||||
private readonly bool AggressiveMemoryOptimizations;
|
private readonly bool AggressiveMemoryOptimizations;
|
||||||
|
|
||||||
|
/// <summary>Get a file path lookup for the given directory.</summary>
|
||||||
|
private readonly Func<string, IFilePathLookup> GetFilePathLookup;
|
||||||
|
|
||||||
/// <summary>Encapsulates monitoring and logging.</summary>
|
/// <summary>Encapsulates monitoring and logging.</summary>
|
||||||
private readonly IMonitor Monitor;
|
private readonly IMonitor Monitor;
|
||||||
|
|
||||||
|
@ -115,11 +119,13 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
||||||
/// <param name="onAssetLoaded">A callback to invoke when an asset is fully loaded.</param>
|
/// <param name="onAssetLoaded">A callback to invoke when an asset is fully loaded.</param>
|
||||||
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
||||||
|
/// <param name="getFilePathLookup">Get a file path lookup for the given directory.</param>
|
||||||
/// <param name="onAssetsInvalidated">A callback to invoke when any asset names have been invalidated from the cache.</param>
|
/// <param name="onAssetsInvalidated">A callback to invoke when any asset names have been invalidated from the cache.</param>
|
||||||
/// <param name="requestAssetOperations">Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</param>
|
/// <param name="requestAssetOperations">Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</param>
|
||||||
public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, bool aggressiveMemoryOptimizations, Action<IList<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, IList<AssetOperationGroup>> requestAssetOperations)
|
public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, bool aggressiveMemoryOptimizations, Func<string, IFilePathLookup> getFilePathLookup, Action<IList<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, IList<AssetOperationGroup>> requestAssetOperations)
|
||||||
{
|
{
|
||||||
this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations;
|
this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations;
|
||||||
|
this.GetFilePathLookup = getFilePathLookup;
|
||||||
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
||||||
this.Reflection = reflection;
|
this.Reflection = reflection;
|
||||||
this.JsonHelper = jsonHelper;
|
this.JsonHelper = jsonHelper;
|
||||||
|
@ -208,7 +214,7 @@ namespace StardewModdingAPI.Framework
|
||||||
jsonHelper: this.JsonHelper,
|
jsonHelper: this.JsonHelper,
|
||||||
onDisposing: this.OnDisposing,
|
onDisposing: this.OnDisposing,
|
||||||
aggressiveMemoryOptimizations: this.AggressiveMemoryOptimizations,
|
aggressiveMemoryOptimizations: this.AggressiveMemoryOptimizations,
|
||||||
relativePathCache: CaseInsensitivePathLookup.GetCachedFor(rootDirectory)
|
relativePathLookup: this.GetFilePathLookup(rootDirectory)
|
||||||
);
|
);
|
||||||
this.ContentManagers.Add(manager);
|
this.ContentManagers.Add(manager);
|
||||||
return manager;
|
return manager;
|
||||||
|
|
|
@ -10,6 +10,7 @@ using StardewModdingAPI.Framework.Exceptions;
|
||||||
using StardewModdingAPI.Framework.Reflection;
|
using StardewModdingAPI.Framework.Reflection;
|
||||||
using StardewModdingAPI.Toolkit.Serialization;
|
using StardewModdingAPI.Toolkit.Serialization;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using xTile;
|
using xTile;
|
||||||
using xTile.Format;
|
using xTile.Format;
|
||||||
|
@ -32,8 +33,8 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <summary>The game content manager used for map tilesheets not provided by the mod.</summary>
|
/// <summary>The game content manager used for map tilesheets not provided by the mod.</summary>
|
||||||
private readonly IContentManager GameContentManager;
|
private readonly IContentManager GameContentManager;
|
||||||
|
|
||||||
/// <summary>A case-insensitive lookup of relative paths within the <see cref="ContentManager.RootDirectory"/>.</summary>
|
/// <summary>A lookup for relative paths within the <see cref="ContentManager.RootDirectory"/>.</summary>
|
||||||
private readonly CaseInsensitivePathLookup RelativePathCache;
|
private readonly IFilePathLookup RelativePathLookup;
|
||||||
|
|
||||||
/// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary>
|
/// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary>
|
||||||
private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" };
|
private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" };
|
||||||
|
@ -55,12 +56,12 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
||||||
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
||||||
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
||||||
/// <param name="relativePathCache">A case-insensitive lookup of relative paths within the <paramref name="rootDirectory"/>.</param>
|
/// <param name="relativePathLookup">A lookup for relative paths within the <paramref name="rootDirectory"/>.</param>
|
||||||
public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action<BaseContentManager> onDisposing, bool aggressiveMemoryOptimizations, CaseInsensitivePathLookup relativePathCache)
|
public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string modName, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action<BaseContentManager> onDisposing, bool aggressiveMemoryOptimizations, IFilePathLookup relativePathLookup)
|
||||||
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true, aggressiveMemoryOptimizations: aggressiveMemoryOptimizations)
|
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true, aggressiveMemoryOptimizations: aggressiveMemoryOptimizations)
|
||||||
{
|
{
|
||||||
this.GameContentManager = gameContentManager;
|
this.GameContentManager = gameContentManager;
|
||||||
this.RelativePathCache = relativePathCache;
|
this.RelativePathLookup = relativePathLookup;
|
||||||
this.JsonHelper = jsonHelper;
|
this.JsonHelper = jsonHelper;
|
||||||
this.ModName = modName;
|
this.ModName = modName;
|
||||||
|
|
||||||
|
@ -257,7 +258,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
private FileInfo GetModFile(string path)
|
private FileInfo GetModFile(string path)
|
||||||
{
|
{
|
||||||
// map to case-insensitive path if needed
|
// map to case-insensitive path if needed
|
||||||
path = this.RelativePathCache.GetFilePath(path);
|
path = this.RelativePathLookup.GetFilePath(path);
|
||||||
|
|
||||||
// try exact match
|
// try exact match
|
||||||
FileInfo file = new(Path.Combine(this.FullRootDirectory, path));
|
FileInfo file = new(Path.Combine(this.FullRootDirectory, path));
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using StardewModdingAPI.Framework.ModHelpers;
|
using StardewModdingAPI.Framework.ModHelpers;
|
||||||
using StardewModdingAPI.Toolkit.Serialization;
|
using StardewModdingAPI.Toolkit.Serialization;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
|
|
||||||
namespace StardewModdingAPI.Framework
|
namespace StardewModdingAPI.Framework
|
||||||
{
|
{
|
||||||
|
@ -15,8 +16,8 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
|
/// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
|
||||||
private readonly JsonHelper JsonHelper;
|
private readonly JsonHelper JsonHelper;
|
||||||
|
|
||||||
/// <summary>A case-insensitive lookup of relative paths within the <see cref="DirectoryPath"/>.</summary>
|
/// <summary>A lookup for relative paths within the <see cref="DirectoryPath"/>.</summary>
|
||||||
private readonly CaseInsensitivePathLookup RelativePathCache;
|
private readonly IFilePathLookup RelativePathCache;
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
|
@ -47,8 +48,8 @@ namespace StardewModdingAPI.Framework
|
||||||
/// <param name="content">Provides an API for loading content assets from the content pack's folder.</param>
|
/// <param name="content">Provides an API for loading content assets from the content pack's folder.</param>
|
||||||
/// <param name="translation">Provides translations stored in the content pack's <c>i18n</c> folder.</param>
|
/// <param name="translation">Provides translations stored in the content pack's <c>i18n</c> folder.</param>
|
||||||
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
||||||
/// <param name="relativePathCache">A case-insensitive lookup of relative paths within the <paramref name="directoryPath"/>.</param>
|
/// <param name="relativePathCache">A lookup for relative paths within the <paramref name="directoryPath"/>.</param>
|
||||||
public ContentPack(string directoryPath, IManifest manifest, IModContentHelper content, TranslationHelper translation, JsonHelper jsonHelper, CaseInsensitivePathLookup relativePathCache)
|
public ContentPack(string directoryPath, IManifest manifest, IModContentHelper content, TranslationHelper translation, JsonHelper jsonHelper, IFilePathLookup relativePathCache)
|
||||||
{
|
{
|
||||||
this.DirectoryPath = directoryPath;
|
this.DirectoryPath = directoryPath;
|
||||||
this.Manifest = manifest;
|
this.Manifest = manifest;
|
||||||
|
|
|
@ -4,7 +4,7 @@ using StardewModdingAPI.Framework.Content;
|
||||||
using StardewModdingAPI.Framework.ContentManagers;
|
using StardewModdingAPI.Framework.ContentManagers;
|
||||||
using StardewModdingAPI.Framework.Exceptions;
|
using StardewModdingAPI.Framework.Exceptions;
|
||||||
using StardewModdingAPI.Framework.Reflection;
|
using StardewModdingAPI.Framework.Reflection;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
|
|
||||||
namespace StardewModdingAPI.Framework.ModHelpers
|
namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,8 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
/// <summary>The friendly mod name for use in errors.</summary>
|
/// <summary>The friendly mod name for use in errors.</summary>
|
||||||
private readonly string ModName;
|
private readonly string ModName;
|
||||||
|
|
||||||
/// <summary>A case-insensitive lookup of relative paths within the <see cref="ContentManager.RootDirectory"/>.</summary>
|
/// <summary>A lookup for relative paths within the <see cref="ContentManager.RootDirectory"/>.</summary>
|
||||||
private readonly CaseInsensitivePathLookup RelativePathCache;
|
private readonly IFilePathLookup RelativePathLookup;
|
||||||
|
|
||||||
/// <summary>Simplifies access to private code.</summary>
|
/// <summary>Simplifies access to private code.</summary>
|
||||||
private readonly Reflector Reflection;
|
private readonly Reflector Reflection;
|
||||||
|
@ -39,9 +39,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
/// <param name="mod">The mod using this instance.</param>
|
/// <param name="mod">The mod using this instance.</param>
|
||||||
/// <param name="modName">The friendly mod name for use in errors.</param>
|
/// <param name="modName">The friendly mod name for use in errors.</param>
|
||||||
/// <param name="gameContentManager">The game content manager used for map tilesheets not provided by the mod.</param>
|
/// <param name="gameContentManager">The game content manager used for map tilesheets not provided by the mod.</param>
|
||||||
/// <param name="relativePathCache">A case-insensitive lookup of relative paths within the <paramref name="relativePathCache"/>.</param>
|
/// <param name="relativePathLookup">A lookup for relative paths within the <paramref name="relativePathLookup"/>.</param>
|
||||||
/// <param name="reflection">Simplifies access to private code.</param>
|
/// <param name="reflection">Simplifies access to private code.</param>
|
||||||
public ModContentHelper(ContentCoordinator contentCore, string modFolderPath, IModMetadata mod, string modName, IContentManager gameContentManager, CaseInsensitivePathLookup relativePathCache, Reflector reflection)
|
public ModContentHelper(ContentCoordinator contentCore, string modFolderPath, IModMetadata mod, string modName, IContentManager gameContentManager, IFilePathLookup relativePathLookup, Reflector reflection)
|
||||||
: base(mod)
|
: base(mod)
|
||||||
{
|
{
|
||||||
string managedAssetPrefix = contentCore.GetManagedAssetPrefix(mod.Manifest.UniqueID);
|
string managedAssetPrefix = contentCore.GetManagedAssetPrefix(mod.Manifest.UniqueID);
|
||||||
|
@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
this.ContentCore = contentCore;
|
this.ContentCore = contentCore;
|
||||||
this.ModContentManager = contentCore.CreateModContentManager(managedAssetPrefix, modName, modFolderPath, gameContentManager);
|
this.ModContentManager = contentCore.CreateModContentManager(managedAssetPrefix, modName, modFolderPath, gameContentManager);
|
||||||
this.ModName = modName;
|
this.ModName = modName;
|
||||||
this.RelativePathCache = relativePathCache;
|
this.RelativePathLookup = relativePathLookup;
|
||||||
this.Reflection = reflection;
|
this.Reflection = reflection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
public T Load<T>(string relativePath)
|
public T Load<T>(string relativePath)
|
||||||
where T : notnull
|
where T : notnull
|
||||||
{
|
{
|
||||||
relativePath = this.RelativePathCache.GetAssetName(relativePath);
|
relativePath = this.RelativePathLookup.GetAssetName(relativePath);
|
||||||
|
|
||||||
IAssetName assetName = this.ContentCore.ParseAssetName(relativePath, allowLocales: false);
|
IAssetName assetName = this.ContentCore.ParseAssetName(relativePath, allowLocales: false);
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IAssetName GetInternalAssetName(string relativePath)
|
public IAssetName GetInternalAssetName(string relativePath)
|
||||||
{
|
{
|
||||||
relativePath = this.RelativePathCache.GetAssetName(relativePath);
|
relativePath = this.RelativePathLookup.GetAssetName(relativePath);
|
||||||
return this.ModContentManager.GetInternalAssetKey(relativePath);
|
return this.ModContentManager.GetInternalAssetKey(relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
||||||
throw new ArgumentNullException(nameof(data), "Can't get a patch helper for a null value.");
|
throw new ArgumentNullException(nameof(data), "Can't get a patch helper for a null value.");
|
||||||
|
|
||||||
relativePath = relativePath != null
|
relativePath = relativePath != null
|
||||||
? this.RelativePathCache.GetAssetName(relativePath)
|
? this.RelativePathLookup.GetAssetName(relativePath)
|
||||||
: $"temp/{Guid.NewGuid():N}";
|
: $"temp/{Guid.NewGuid():N}";
|
||||||
|
|
||||||
return new AssetDataForObject(
|
return new AssetDataForObject(
|
||||||
|
|
|
@ -9,6 +9,7 @@ using StardewModdingAPI.Toolkit.Framework.ModScanning;
|
||||||
using StardewModdingAPI.Toolkit.Framework.UpdateData;
|
using StardewModdingAPI.Toolkit.Framework.UpdateData;
|
||||||
using StardewModdingAPI.Toolkit.Serialization.Models;
|
using StardewModdingAPI.Toolkit.Serialization.Models;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
|
|
||||||
namespace StardewModdingAPI.Framework.ModLoading
|
namespace StardewModdingAPI.Framework.ModLoading
|
||||||
{
|
{
|
||||||
|
@ -22,10 +23,11 @@ namespace StardewModdingAPI.Framework.ModLoading
|
||||||
/// <param name="toolkit">The mod toolkit.</param>
|
/// <param name="toolkit">The mod toolkit.</param>
|
||||||
/// <param name="rootPath">The root path to search for mods.</param>
|
/// <param name="rootPath">The root path to search for mods.</param>
|
||||||
/// <param name="modDatabase">Handles access to SMAPI's internal mod metadata list.</param>
|
/// <param name="modDatabase">Handles access to SMAPI's internal mod metadata list.</param>
|
||||||
|
/// <param name="useCaseInsensitiveFilePaths">Whether to match file paths case-insensitively, even on Linux.</param>
|
||||||
/// <returns>Returns the manifests by relative folder.</returns>
|
/// <returns>Returns the manifests by relative folder.</returns>
|
||||||
public IEnumerable<IModMetadata> ReadManifests(ModToolkit toolkit, string rootPath, ModDatabase modDatabase)
|
public IEnumerable<IModMetadata> ReadManifests(ModToolkit toolkit, string rootPath, ModDatabase modDatabase, bool useCaseInsensitiveFilePaths)
|
||||||
{
|
{
|
||||||
foreach (ModFolder folder in toolkit.GetModFolders(rootPath))
|
foreach (ModFolder folder in toolkit.GetModFolders(rootPath, useCaseInsensitiveFilePaths))
|
||||||
{
|
{
|
||||||
Manifest? manifest = folder.Manifest;
|
Manifest? manifest = folder.Manifest;
|
||||||
|
|
||||||
|
@ -56,10 +58,11 @@ namespace StardewModdingAPI.Framework.ModLoading
|
||||||
/// <param name="mods">The mod manifests to validate.</param>
|
/// <param name="mods">The mod manifests to validate.</param>
|
||||||
/// <param name="apiVersion">The current SMAPI version.</param>
|
/// <param name="apiVersion">The current SMAPI version.</param>
|
||||||
/// <param name="getUpdateUrl">Get an update URL for an update key (if valid).</param>
|
/// <param name="getUpdateUrl">Get an update URL for an update key (if valid).</param>
|
||||||
|
/// <param name="getFilePathLookup">Get a file path lookup for the given directory.</param>
|
||||||
/// <param name="validateFilesExist">Whether to validate that files referenced in the manifest (like <see cref="IManifest.EntryDll"/>) exist on disk. This can be disabled to only validate the manifest itself.</param>
|
/// <param name="validateFilesExist">Whether to validate that files referenced in the manifest (like <see cref="IManifest.EntryDll"/>) exist on disk. This can be disabled to only validate the manifest itself.</param>
|
||||||
[SuppressMessage("ReSharper", "ConstantConditionalAccessQualifier", Justification = "Manifest values may be null before they're validated.")]
|
[SuppressMessage("ReSharper", "ConstantConditionalAccessQualifier", Justification = "Manifest values may be null before they're validated.")]
|
||||||
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse", Justification = "Manifest values may be null before they're validated.")]
|
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse", Justification = "Manifest values may be null before they're validated.")]
|
||||||
public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion, Func<string, string?> getUpdateUrl, bool validateFilesExist = true)
|
public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion, Func<string, string?> getUpdateUrl, Func<string, IFilePathLookup> getFilePathLookup, bool validateFilesExist = true)
|
||||||
{
|
{
|
||||||
mods = mods.ToArray();
|
mods = mods.ToArray();
|
||||||
|
|
||||||
|
@ -144,7 +147,8 @@ namespace StardewModdingAPI.Framework.ModLoading
|
||||||
// file doesn't exist
|
// file doesn't exist
|
||||||
if (validateFilesExist)
|
if (validateFilesExist)
|
||||||
{
|
{
|
||||||
string fileName = CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath).GetFilePath(mod.Manifest.EntryDll!);
|
IFilePathLookup pathLookup = getFilePathLookup(mod.DirectoryPath);
|
||||||
|
string fileName = pathLookup.GetFilePath(mod.Manifest.EntryDll!);
|
||||||
if (!File.Exists(Path.Combine(mod.DirectoryPath, fileName)))
|
if (!File.Exists(Path.Combine(mod.DirectoryPath, fileName)))
|
||||||
{
|
{
|
||||||
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its DLL '{mod.Manifest.EntryDll}' doesn't exist.");
|
mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its DLL '{mod.Manifest.EntryDll}' doesn't exist.");
|
||||||
|
|
|
@ -23,7 +23,8 @@ namespace StardewModdingAPI.Framework.Models
|
||||||
[nameof(LogNetworkTraffic)] = false,
|
[nameof(LogNetworkTraffic)] = false,
|
||||||
[nameof(RewriteMods)] = true,
|
[nameof(RewriteMods)] = true,
|
||||||
[nameof(AggressiveMemoryOptimizations)] = false,
|
[nameof(AggressiveMemoryOptimizations)] = false,
|
||||||
[nameof(UsePintail)] = true
|
[nameof(UsePintail)] = true,
|
||||||
|
[nameof(UseCaseInsensitivePaths)] = false
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>The default values for <see cref="SuppressUpdateChecks"/>, to log changes if different.</summary>
|
/// <summary>The default values for <see cref="SuppressUpdateChecks"/>, to log changes if different.</summary>
|
||||||
|
@ -68,6 +69,9 @@ namespace StardewModdingAPI.Framework.Models
|
||||||
/// <summary>Whether to use the experimental Pintail API proxying library, instead of the original proxying built into SMAPI itself.</summary>
|
/// <summary>Whether to use the experimental Pintail API proxying library, instead of the original proxying built into SMAPI itself.</summary>
|
||||||
public bool UsePintail { get; }
|
public bool UsePintail { get; }
|
||||||
|
|
||||||
|
/// <summary>Whether to make SMAPI file APIs case-insensitive, even on Linux.</summary>
|
||||||
|
public bool UseCaseInsensitivePaths { get; }
|
||||||
|
|
||||||
/// <summary>Whether SMAPI should log network traffic. Best combined with <see cref="VerboseLogging"/>, which includes network metadata.</summary>
|
/// <summary>Whether SMAPI should log network traffic. Best combined with <see cref="VerboseLogging"/>, which includes network metadata.</summary>
|
||||||
public bool LogNetworkTraffic { get; }
|
public bool LogNetworkTraffic { get; }
|
||||||
|
|
||||||
|
@ -92,10 +96,11 @@ namespace StardewModdingAPI.Framework.Models
|
||||||
/// <param name="rewriteMods">Whether SMAPI should rewrite mods for compatibility.</param>
|
/// <param name="rewriteMods">Whether SMAPI should rewrite mods for compatibility.</param>
|
||||||
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
|
||||||
/// <param name="usePintail">Whether to use the experimental Pintail API proxying library, instead of the original proxying built into SMAPI itself.</param>
|
/// <param name="usePintail">Whether to use the experimental Pintail API proxying library, instead of the original proxying built into SMAPI itself.</param>
|
||||||
|
/// <param name="useCaseInsensitivePaths">>Whether to make SMAPI file APIs case-insensitive, even on Linux.</param>
|
||||||
/// <param name="logNetworkTraffic">Whether SMAPI should log network traffic.</param>
|
/// <param name="logNetworkTraffic">Whether SMAPI should log network traffic.</param>
|
||||||
/// <param name="consoleColors">The colors to use for text written to the SMAPI console.</param>
|
/// <param name="consoleColors">The colors to use for text written to the SMAPI console.</param>
|
||||||
/// <param name="suppressUpdateChecks">The mod IDs SMAPI should ignore when performing update checks or validating update keys.</param>
|
/// <param name="suppressUpdateChecks">The mod IDs SMAPI should ignore when performing update checks or validating update keys.</param>
|
||||||
public SConfig(bool developerMode, bool checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, bool verboseLogging, bool? rewriteMods, bool? aggressiveMemoryOptimizations, bool usePintail, bool logNetworkTraffic, ColorSchemeConfig consoleColors, string[]? suppressUpdateChecks)
|
public SConfig(bool developerMode, bool checkForUpdates, bool? paranoidWarnings, bool? useBetaChannel, string gitHubProjectName, string webApiBaseUrl, bool verboseLogging, bool? rewriteMods, bool? aggressiveMemoryOptimizations, bool? usePintail, bool? useCaseInsensitivePaths, bool logNetworkTraffic, ColorSchemeConfig consoleColors, string[]? suppressUpdateChecks)
|
||||||
{
|
{
|
||||||
this.DeveloperMode = developerMode;
|
this.DeveloperMode = developerMode;
|
||||||
this.CheckForUpdates = checkForUpdates;
|
this.CheckForUpdates = checkForUpdates;
|
||||||
|
@ -106,7 +111,8 @@ namespace StardewModdingAPI.Framework.Models
|
||||||
this.VerboseLogging = verboseLogging;
|
this.VerboseLogging = verboseLogging;
|
||||||
this.RewriteMods = rewriteMods ?? (bool)SConfig.DefaultValues[nameof(SConfig.RewriteMods)];
|
this.RewriteMods = rewriteMods ?? (bool)SConfig.DefaultValues[nameof(SConfig.RewriteMods)];
|
||||||
this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations ?? (bool)SConfig.DefaultValues[nameof(SConfig.AggressiveMemoryOptimizations)];
|
this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations ?? (bool)SConfig.DefaultValues[nameof(SConfig.AggressiveMemoryOptimizations)];
|
||||||
this.UsePintail = usePintail;
|
this.UsePintail = usePintail ?? (bool)SConfig.DefaultValues[nameof(SConfig.UsePintail)];
|
||||||
|
this.UseCaseInsensitivePaths = useCaseInsensitivePaths ?? (bool)SConfig.DefaultValues[nameof(SConfig.UseCaseInsensitivePaths)];
|
||||||
this.LogNetworkTraffic = logNetworkTraffic;
|
this.LogNetworkTraffic = logNetworkTraffic;
|
||||||
this.ConsoleColors = consoleColors;
|
this.ConsoleColors = consoleColors;
|
||||||
this.SuppressUpdateChecks = suppressUpdateChecks ?? Array.Empty<string>();
|
this.SuppressUpdateChecks = suppressUpdateChecks ?? Array.Empty<string>();
|
||||||
|
|
|
@ -43,6 +43,7 @@ using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
|
||||||
using StardewModdingAPI.Toolkit.Framework.ModData;
|
using StardewModdingAPI.Toolkit.Framework.ModData;
|
||||||
using StardewModdingAPI.Toolkit.Serialization;
|
using StardewModdingAPI.Toolkit.Serialization;
|
||||||
using StardewModdingAPI.Toolkit.Utilities;
|
using StardewModdingAPI.Toolkit.Utilities;
|
||||||
|
using StardewModdingAPI.Toolkit.Utilities.PathLookups;
|
||||||
using StardewModdingAPI.Utilities;
|
using StardewModdingAPI.Utilities;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
using StardewValley.Menus;
|
using StardewValley.Menus;
|
||||||
|
@ -396,7 +397,7 @@ namespace StardewModdingAPI.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
// load manifests
|
// load manifests
|
||||||
IModMetadata[] mods = resolver.ReadManifests(toolkit, this.ModsPath, modDatabase).ToArray();
|
IModMetadata[] mods = resolver.ReadManifests(toolkit, this.ModsPath, modDatabase, useCaseInsensitiveFilePaths: this.Settings.UseCaseInsensitivePaths).ToArray();
|
||||||
|
|
||||||
// filter out ignored mods
|
// filter out ignored mods
|
||||||
foreach (IModMetadata mod in mods.Where(p => p.IsIgnored))
|
foreach (IModMetadata mod in mods.Where(p => p.IsIgnored))
|
||||||
|
@ -404,7 +405,7 @@ namespace StardewModdingAPI.Framework
|
||||||
mods = mods.Where(p => !p.IsIgnored).ToArray();
|
mods = mods.Where(p => !p.IsIgnored).ToArray();
|
||||||
|
|
||||||
// load mods
|
// load mods
|
||||||
resolver.ValidateManifests(mods, Constants.ApiVersion, toolkit.GetUpdateUrl);
|
resolver.ValidateManifests(mods, Constants.ApiVersion, toolkit.GetUpdateUrl, getFilePathLookup: this.GetFilePathLookup);
|
||||||
mods = resolver.ProcessDependencies(mods, modDatabase).ToArray();
|
mods = resolver.ProcessDependencies(mods, modDatabase).ToArray();
|
||||||
this.LoadMods(mods, this.Toolkit.JsonHelper, this.ContentCore, modDatabase);
|
this.LoadMods(mods, this.Toolkit.JsonHelper, this.ContentCore, modDatabase);
|
||||||
|
|
||||||
|
@ -1253,6 +1254,7 @@ namespace StardewModdingAPI.Framework
|
||||||
onAssetLoaded: this.OnAssetLoaded,
|
onAssetLoaded: this.OnAssetLoaded,
|
||||||
onAssetsInvalidated: this.OnAssetsInvalidated,
|
onAssetsInvalidated: this.OnAssetsInvalidated,
|
||||||
aggressiveMemoryOptimizations: this.Settings.AggressiveMemoryOptimizations,
|
aggressiveMemoryOptimizations: this.Settings.AggressiveMemoryOptimizations,
|
||||||
|
getFilePathLookup: this.GetFilePathLookup,
|
||||||
requestAssetOperations: this.RequestAssetOperations
|
requestAssetOperations: this.RequestAssetOperations
|
||||||
);
|
);
|
||||||
if (this.ContentCore.Language != this.Translator.LocaleEnum)
|
if (this.ContentCore.Language != this.Translator.LocaleEnum)
|
||||||
|
@ -1753,7 +1755,7 @@ namespace StardewModdingAPI.Framework
|
||||||
if (mod.IsContentPack)
|
if (mod.IsContentPack)
|
||||||
{
|
{
|
||||||
IMonitor monitor = this.LogManager.GetMonitor(mod.DisplayName);
|
IMonitor monitor = this.LogManager.GetMonitor(mod.DisplayName);
|
||||||
CaseInsensitivePathLookup relativePathCache = CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath);
|
IFilePathLookup relativePathCache = this.GetFilePathLookup(mod.DirectoryPath);
|
||||||
GameContentHelper gameContentHelper = new(this.ContentCore, mod, mod.DisplayName, monitor, this.Reflection);
|
GameContentHelper gameContentHelper = new(this.ContentCore, mod, mod.DisplayName, monitor, this.Reflection);
|
||||||
IModContentHelper modContentHelper = new ModContentHelper(this.ContentCore, mod.DirectoryPath, mod, mod.DisplayName, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection);
|
IModContentHelper modContentHelper = new ModContentHelper(this.ContentCore, mod.DirectoryPath, mod, mod.DisplayName, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection);
|
||||||
TranslationHelper translationHelper = new(mod, contentCore.GetLocale(), contentCore.Language);
|
TranslationHelper translationHelper = new(mod, contentCore.GetLocale(), contentCore.Language);
|
||||||
|
@ -1772,7 +1774,7 @@ namespace StardewModdingAPI.Framework
|
||||||
// get mod info
|
// get mod info
|
||||||
string assemblyPath = Path.Combine(
|
string assemblyPath = Path.Combine(
|
||||||
mod.DirectoryPath,
|
mod.DirectoryPath,
|
||||||
CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath).GetFilePath(manifest.EntryDll!)
|
this.GetFilePathLookup(mod.DirectoryPath).GetFilePath(manifest.EntryDll!)
|
||||||
);
|
);
|
||||||
|
|
||||||
// load mod
|
// load mod
|
||||||
|
@ -1838,7 +1840,7 @@ namespace StardewModdingAPI.Framework
|
||||||
{
|
{
|
||||||
IMonitor packMonitor = this.LogManager.GetMonitor(packManifest.Name);
|
IMonitor packMonitor = this.LogManager.GetMonitor(packManifest.Name);
|
||||||
|
|
||||||
CaseInsensitivePathLookup relativePathCache = CaseInsensitivePathLookup.GetCachedFor(packDirPath);
|
IFilePathLookup relativePathCache = this.GetFilePathLookup(packDirPath);
|
||||||
|
|
||||||
GameContentHelper gameContentHelper = new(contentCore, mod, packManifest.Name, packMonitor, this.Reflection);
|
GameContentHelper gameContentHelper = new(contentCore, mod, packManifest.Name, packMonitor, this.Reflection);
|
||||||
IModContentHelper packContentHelper = new ModContentHelper(contentCore, packDirPath, mod, packManifest.Name, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection);
|
IModContentHelper packContentHelper = new ModContentHelper(contentCore, packDirPath, mod, packManifest.Name, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection);
|
||||||
|
@ -1852,12 +1854,12 @@ namespace StardewModdingAPI.Framework
|
||||||
|
|
||||||
IModEvents events = new ModEvents(mod, this.EventManager);
|
IModEvents events = new ModEvents(mod, this.EventManager);
|
||||||
ICommandHelper commandHelper = new CommandHelper(mod, this.CommandManager);
|
ICommandHelper commandHelper = new CommandHelper(mod, this.CommandManager);
|
||||||
CaseInsensitivePathLookup relativePathCache = CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath);
|
IFilePathLookup relativePathLookup = this.GetFilePathLookup(mod.DirectoryPath);
|
||||||
#pragma warning disable CS0612 // deprecated code
|
#pragma warning disable CS0612 // deprecated code
|
||||||
ContentHelper contentHelper = new(contentCore, mod.DirectoryPath, mod, monitor, this.Reflection);
|
ContentHelper contentHelper = new(contentCore, mod.DirectoryPath, mod, monitor, this.Reflection);
|
||||||
#pragma warning restore CS0612
|
#pragma warning restore CS0612
|
||||||
GameContentHelper gameContentHelper = new(contentCore, mod, mod.DisplayName, monitor, this.Reflection);
|
GameContentHelper gameContentHelper = new(contentCore, mod, mod.DisplayName, monitor, this.Reflection);
|
||||||
IModContentHelper modContentHelper = new ModContentHelper(contentCore, mod.DirectoryPath, mod, mod.DisplayName, gameContentHelper.GetUnderlyingContentManager(), relativePathCache, this.Reflection);
|
IModContentHelper modContentHelper = new ModContentHelper(contentCore, mod.DirectoryPath, mod, mod.DisplayName, gameContentHelper.GetUnderlyingContentManager(), relativePathLookup, this.Reflection);
|
||||||
IContentPackHelper contentPackHelper = new ContentPackHelper(mod, new Lazy<IContentPack[]>(GetContentPacks), CreateFakeContentPack);
|
IContentPackHelper contentPackHelper = new ContentPackHelper(mod, new Lazy<IContentPack[]>(GetContentPacks), CreateFakeContentPack);
|
||||||
IDataHelper dataHelper = new DataHelper(mod, mod.DirectoryPath, jsonHelper);
|
IDataHelper dataHelper = new DataHelper(mod, mod.DirectoryPath, jsonHelper);
|
||||||
IReflectionHelper reflectionHelper = new ReflectionHelper(mod, mod.DisplayName, this.Reflection);
|
IReflectionHelper reflectionHelper = new ReflectionHelper(mod, mod.DisplayName, this.Reflection);
|
||||||
|
@ -2035,6 +2037,15 @@ namespace StardewModdingAPI.Framework
|
||||||
return translations;
|
return translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Get a file path lookup for the given directory.</summary>
|
||||||
|
/// <param name="rootDirectory">The root path to scan.</param>
|
||||||
|
private IFilePathLookup GetFilePathLookup(string rootDirectory)
|
||||||
|
{
|
||||||
|
return this.Settings.UseCaseInsensitivePaths
|
||||||
|
? CaseInsensitivePathLookup.GetCachedFor(rootDirectory)
|
||||||
|
: MinimalPathLookup.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Get the map display device which applies SMAPI features like tile rotation to loaded maps.</summary>
|
/// <summary>Get the map display device which applies SMAPI features like tile rotation to loaded maps.</summary>
|
||||||
/// <remarks>This is separate to let mods like PyTK wrap it with their own functionality.</remarks>
|
/// <remarks>This is separate to let mods like PyTK wrap it with their own functionality.</remarks>
|
||||||
private IDisplayDevice GetMapDisplayDevice()
|
private IDisplayDevice GetMapDisplayDevice()
|
||||||
|
|
|
@ -46,6 +46,12 @@ copy all the settings, or you may cause bugs due to overridden changes in future
|
||||||
*/
|
*/
|
||||||
"AggressiveMemoryOptimizations": false,
|
"AggressiveMemoryOptimizations": false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to make SMAPI file APIs case-insensitive, even on Linux.
|
||||||
|
* This is experimental, and the initial implementation may impact load times.
|
||||||
|
*/
|
||||||
|
"UseCaseInsensitivePaths": false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to use the experimental Pintail API proxying library, instead of the original
|
* Whether to use the experimental Pintail API proxying library, instead of the original
|
||||||
* proxying built into SMAPI itself.
|
* proxying built into SMAPI itself.
|
||||||
|
|
Loading…
Reference in New Issue