From 4b07e1052027947186b6a7d4de489b5dc6a9d4f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 21 Jul 2020 13:51:11 -0400 Subject: [PATCH] ignore more content file types when detecting mods --- docs/release-notes.md | 1 + .../Framework/ModScanning/ModScanner.cs | 49 +++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 837f31db..07905180 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -9,6 +9,7 @@ ## Upcoming release * For players: + * SMAPI now ignores more content file types when detecting mods (`.doc`, `.docx`, `.rar`, and `.zip`). * Fixed launcher's fallback logic on Linux when no compatible terminal was found (thanks to jlaw!). * For the Console Commands mod: diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs index f4857c7d..a7c87cbb 100644 --- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs +++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs @@ -18,18 +18,44 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning private readonly JsonHelper JsonHelper; /// A list of filesystem entry names to ignore when checking whether a folder should be treated as a mod. - private readonly HashSet IgnoreFilesystemEntries = new HashSet + private readonly HashSet IgnoreFilesystemNames = new HashSet { - // OS metadata files new Regex(@"^__folder_managed_by_vortex$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Vortex mod manager new Regex(@"(?:^\._|^\.DS_Store$|^__MACOSX$|^mcs$)", RegexOptions.Compiled | RegexOptions.IgnoreCase), // MacOS - new Regex(@"^(?:desktop\.ini|Thumbs\.db)$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Windows - new Regex(@"\.(?:url|lnk)$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // Windows shortcut files + new Regex(@"^(?:desktop\.ini|Thumbs\.db)$", RegexOptions.Compiled | RegexOptions.IgnoreCase) // Windows + }; - // other - new Regex(@"\.(?:bmp|gif|jpeg|jpg|png|psd|tif)$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // image files - new Regex(@"\.(?:md|rtf|txt)$", RegexOptions.Compiled | RegexOptions.IgnoreCase), // text files - new Regex(@"\.(?:backup|bak|old)$", RegexOptions.Compiled | RegexOptions.IgnoreCase) // backup file + /// A list of file extensions to ignore when searching for mod files. + private readonly HashSet IgnoreFileExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) + { + // text + ".doc", + ".docx", + ".md", + ".rtf", + ".txt", + + // images + ".bmp", + ".gif", + ".jpeg", + ".jpg", + ".png", + ".psd", + ".tif", + + // archives + ".rar", + ".zip", + + // backup files + ".backup", + ".bak", + ".old", + + // Windows shortcut files + ".url", + ".lnk" }; /// The extensions for files which an XNB mod may contain. If a mod doesn't have a manifest.json and contains *only* these file extensions, it should be considered an XNB mod. @@ -258,7 +284,12 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning /// The file or folder. private bool IsRelevant(FileSystemInfo entry) { - return !this.IgnoreFilesystemEntries.Any(p => p.IsMatch(entry.Name)); + // ignored file extension + if (entry is FileInfo file && this.IgnoreFileExtensions.Contains(file.Extension)) + return false; + + // ignored entry name + return !this.IgnoreFilesystemNames.Any(p => p.IsMatch(entry.Name)); } /// Get whether a file is potentially part of an XNB mod.