From 7dec51923418b269e111a266edb319ff3b0cb118 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 16 Apr 2022 18:29:52 -0400 Subject: fix broken unit tests --- src/SMAPI/Framework/Content/AssetName.cs | 16 +++++++++------- src/SMAPI/Framework/ModLoading/ModResolver.cs | 14 +++++++++----- src/SMAPI/Framework/Translator.cs | 3 ++- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src/SMAPI') 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 /// The mod manifests to validate. /// The current SMAPI version. /// Get an update URL for an update key (if valid). + /// Whether to validate that files referenced in the manifest (like ) exist on disk. This can be disabled to only validate the manifest itself. [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 mods, ISemanticVersion apiVersion, Func getUpdateUrl) + public void ValidateManifests(IEnumerable mods, ISemanticVersion apiVersion, Func 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)); } } -- cgit