diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-16 17:34:31 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-11-28 00:01:48 -0500 |
commit | 217cc7af21a501daabea16dc7331401a19706bf4 (patch) | |
tree | cc1e5d0705fe21f03007052e889a30702ab0a39e | |
parent | 60c0e4fc31475847cbf94d201f0bd394c537d9c0 (diff) | |
download | SMAPI-217cc7af21a501daabea16dc7331401a19706bf4.tar.gz SMAPI-217cc7af21a501daabea16dc7331401a19706bf4.tar.bz2 SMAPI-217cc7af21a501daabea16dc7331401a19706bf4.zip |
add IgnoreModFilePaths option to package
-rw-r--r-- | docs/technical/mod-package.md | 17 | ||||
-rw-r--r-- | src/SMAPI.ModBuildConfig/DeployModTask.cs | 32 | ||||
-rw-r--r-- | src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs | 9 | ||||
-rw-r--r-- | src/SMAPI.ModBuildConfig/build/smapi.targets | 1 |
4 files changed, 53 insertions, 6 deletions
diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index a3ce8761..0fdd4c4a 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -225,6 +225,20 @@ project. </td> </tr> <tr> +<td><code>IgnoreModFilePaths</code></td> +<td> + +A comma-delimited list of literal file paths to ignore, relative to the mod's `bin` folder. Paths +are case-sensitive, but path delimiters are normalized automatically. For example, this ignores a +set of tilesheets: + +```xml +<IgnoreModFilePaths>assets/paths.png, assets/springobjects.png</IgnoreModFilePaths> +``` + +</td> +</tr> +<tr> <td><code>IgnoreModFilePatterns</code></td> <td> @@ -366,7 +380,8 @@ when you compile it. ## Release notes ## Upcoming release -* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **The older versions are no longer supported.** +* Updated for Stardew Valley 1.5.5 and SMAPI 3.13.0. **Older versions are no longer supported.** +* Added `IgnoreModFilePaths` option to ignore literal paths. * Improved analyzer performance by enabling parallel execution. ## 3.3.0 diff --git a/src/SMAPI.ModBuildConfig/DeployModTask.cs b/src/SMAPI.ModBuildConfig/DeployModTask.cs index 9ee6be12..0c64aed3 100644 --- a/src/SMAPI.ModBuildConfig/DeployModTask.cs +++ b/src/SMAPI.ModBuildConfig/DeployModTask.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using StardewModdingAPI.ModBuildConfig.Framework; +using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingAPI.ModBuildConfig { @@ -45,9 +46,12 @@ namespace StardewModdingAPI.ModBuildConfig [Required] public bool EnableModZip { get; set; } - /// <summary>Custom comma-separated regex patterns matching files to ignore when deploying or zipping the mod.</summary> + /// <summary>A comma-separated list of regex patterns matching files to ignore when deploying or zipping the mod.</summary> public string IgnoreModFilePatterns { get; set; } + /// <summary>A comma-separated list of relative file paths to ignore when deploying or zipping the mod.</summary> + public string IgnoreModFilePaths { get; set; } + /********* ** Public methods @@ -70,10 +74,11 @@ namespace StardewModdingAPI.ModBuildConfig try { // parse ignore patterns + string[] ignoreFilePaths = this.GetCustomIgnoreFilePaths().ToArray(); Regex[] ignoreFilePatterns = this.GetCustomIgnorePatterns().ToArray(); // get mod info - ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); + ModFileManager package = new ModFileManager(this.ProjectDir, this.TargetDir, ignoreFilePaths, ignoreFilePatterns, validateRequiredModFiles: this.EnableModDeploy || this.EnableModZip); // deploy mod files if (this.EnableModDeploy) @@ -157,6 +162,29 @@ namespace StardewModdingAPI.ModBuildConfig } } + /// <summary>Get the custom relative file paths provided by the user to ignore.</summary> + private IEnumerable<string> GetCustomIgnoreFilePaths() + { + if (string.IsNullOrWhiteSpace(this.IgnoreModFilePaths)) + yield break; + + foreach (string raw in this.IgnoreModFilePaths.Split(',')) + { + string path; + try + { + path = PathUtilities.NormalizePath(raw); + } + catch (Exception ex) + { + this.Log.LogWarning($"[mod build package] Ignored invalid <{nameof(this.IgnoreModFilePaths)}> path {raw}:\n{ex}"); + continue; + } + + yield return path; + } + } + /// <summary>Copy the mod files into the game's mod folder.</summary> /// <param name="files">The files to include.</param> /// <param name="modFolderPath">The folder path to create with the mod files.</param> diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index 3d9b206b..fbb91193 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -28,10 +28,11 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// <summary>Construct an instance.</summary> /// <param name="projectDir">The folder containing the project files.</param> /// <param name="targetDir">The folder containing the build output.</param> + /// <param name="ignoreFilePaths">The custom relative file paths provided by the user to ignore.</param> /// <param name="ignoreFilePatterns">Custom regex patterns matching files to ignore when deploying or zipping the mod.</param> /// <param name="validateRequiredModFiles">Whether to validate that required mod files like the manifest are present.</param> /// <exception cref="UserErrorException">The mod package isn't valid.</exception> - public ModFileManager(string projectDir, string targetDir, Regex[] ignoreFilePatterns, bool validateRequiredModFiles) + public ModFileManager(string projectDir, string targetDir, string[] ignoreFilePaths, Regex[] ignoreFilePatterns, bool validateRequiredModFiles) { this.Files = new Dictionary<string, FileInfo>(StringComparer.OrdinalIgnoreCase); @@ -47,7 +48,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework string relativePath = entry.Item1; FileInfo file = entry.Item2; - if (!this.ShouldIgnore(file, relativePath, ignoreFilePatterns)) + if (!this.ShouldIgnore(file, relativePath, ignoreFilePaths, ignoreFilePatterns)) this.Files[relativePath] = file; } @@ -149,8 +150,9 @@ namespace StardewModdingAPI.ModBuildConfig.Framework /// <summary>Get whether a build output file should be ignored.</summary> /// <param name="file">The file to check.</param> /// <param name="relativePath">The file's relative path in the package.</param> + /// <param name="ignoreFilePaths">The custom relative file paths provided by the user to ignore.</param> /// <param name="ignoreFilePatterns">Custom regex patterns matching files to ignore when deploying or zipping the mod.</param> - private bool ShouldIgnore(FileInfo file, string relativePath, Regex[] ignoreFilePatterns) + private bool ShouldIgnore(FileInfo file, string relativePath, string[] ignoreFilePaths, Regex[] ignoreFilePatterns) { bool IsAssemblyFile(string baseName) { @@ -181,6 +183,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework || this.EqualsInvariant(file.Name, "Thumbs.db") // custom ignore patterns + || ignoreFilePaths.Any(p => p == relativePath) || ignoreFilePatterns.Any(p => p.IsMatch(relativePath)); } diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 74ac56e6..b254dd7c 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -94,6 +94,7 @@ TargetDir="$(TargetDir)" GameModsDir="$(GameModsPath)" IgnoreModFilePatterns="$(IgnoreModFilePatterns)" + IgnoreModFilePaths="$(IgnoreModFilePaths)" /> </Target> </Project> |