diff options
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/Content/AssetName.cs | 16 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModResolver.cs | 14 | ||||
-rw-r--r-- | src/SMAPI/Framework/Translator.cs | 3 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs index 4c691b9a..148354a1 100644 --- a/src/SMAPI/Framework/Content/AssetName.cs +++ b/src/SMAPI/Framework/Content/AssetName.cs @@ -119,25 +119,27 @@ namespace StardewModdingAPI.Framework.Content if (prefix is null) return false; + string rawTrimmed = prefix.Trim(); + // asset keys can't have a leading slash, but NormalizeAssetName will trim them - { - string trimmed = prefix.TrimStart(); - if (trimmed.StartsWith('/') || trimmed.StartsWith('\\')) - return false; - } + if (rawTrimmed.StartsWith('/') || rawTrimmed.StartsWith('\\')) + return false; // normalize prefix { string normalized = PathUtilities.NormalizeAssetName(prefix); - string trimmed = prefix.TrimEnd(); - if (trimmed.EndsWith('/') || trimmed.EndsWith('\\')) + // keep trailing slash + if (rawTrimmed.EndsWith('/') || rawTrimmed.EndsWith('\\')) normalized += PathUtilities.PreferredAssetSeparator; prefix = normalized; } // compare + if (prefix.Length == 0) + return true; + return this.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) && ( diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index 4a02e90d..74e7cb32 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -56,9 +56,10 @@ namespace StardewModdingAPI.Framework.ModLoading /// <param name="mods">The mod manifests to validate.</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="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", "ConditionIsAlwaysTrueOrFalse", Justification = "Manifest values may be null before they're validated.")] - public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion, Func<string, string?> getUpdateUrl) + public void ValidateManifests(IEnumerable<IModMetadata> mods, ISemanticVersion apiVersion, Func<string, string?> getUpdateUrl, bool validateFilesExist = true) { mods = mods.ToArray(); @@ -141,11 +142,14 @@ namespace StardewModdingAPI.Framework.ModLoading } // file doesn't exist - string fileName = CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath).GetFilePath(mod.Manifest.EntryDll!); - if (!File.Exists(Path.Combine(mod.DirectoryPath, fileName))) + if (validateFilesExist) { - mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its DLL '{mod.Manifest.EntryDll}' doesn't exist."); - continue; + string fileName = CaseInsensitivePathLookup.GetCachedFor(mod.DirectoryPath).GetFilePath(mod.Manifest.EntryDll!); + if (!File.Exists(Path.Combine(mod.DirectoryPath, fileName))) + { + mod.SetStatus(ModMetadataStatus.Failed, ModFailReason.InvalidManifest, $"its DLL '{mod.Manifest.EntryDll}' doesn't exist."); + continue; + } } } diff --git a/src/SMAPI/Framework/Translator.cs b/src/SMAPI/Framework/Translator.cs index b230a727..3beee250 100644 --- a/src/SMAPI/Framework/Translator.cs +++ b/src/SMAPI/Framework/Translator.cs @@ -51,7 +51,8 @@ namespace StardewModdingAPI.Framework foreach (string key in this.GetAllKeysRaw()) { string? text = this.GetRaw(key, locale, withFallback: true); - this.ForLocale.Add(key, new Translation(this.Locale, key, text)); + if (text != null) + this.ForLocale.Add(key, new Translation(this.Locale, key, text)); } } |