diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-09-11 17:25:38 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-09-11 17:25:38 -0400 |
commit | 1abc76a2240543e24e944d077271f3dfda9f4d97 (patch) | |
tree | bda3fc856e7a6bbb75f631236fcb2be5070fae18 /src/SMAPI.ModBuildConfig | |
parent | 5433f9023ed174366c8bf450785aafbdb077d29d (diff) | |
download | SMAPI-1abc76a2240543e24e944d077271f3dfda9f4d97.tar.gz SMAPI-1abc76a2240543e24e944d077271f3dfda9f4d97.tar.bz2 SMAPI-1abc76a2240543e24e944d077271f3dfda9f4d97.zip |
improve logging in mod build package
Diffstat (limited to 'src/SMAPI.ModBuildConfig')
-rw-r--r-- | src/SMAPI.ModBuildConfig/DeployModTask.cs | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/src/SMAPI.ModBuildConfig/DeployModTask.cs b/src/SMAPI.ModBuildConfig/DeployModTask.cs index c47c8ec4..9ee6be12 100644 --- a/src/SMAPI.ModBuildConfig/DeployModTask.cs +++ b/src/SMAPI.ModBuildConfig/DeployModTask.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -55,6 +56,14 @@ namespace StardewModdingAPI.ModBuildConfig /// <returns>true if the task successfully executed; otherwise, false.</returns> public override bool Execute() { + // log build settings + { + var properties = this + .GetPropertiesToLog() + .Select(p => $"{p.Key}: {p.Value}"); + this.Log.LogMessage(MessageImportance.High, $"[mod build package] Handling build with options {string.Join(", ", properties)}"); + } + if (!this.EnableModDeploy && !this.EnableModZip) return true; // nothing to do @@ -70,15 +79,18 @@ namespace StardewModdingAPI.ModBuildConfig if (this.EnableModDeploy) { string outputPath = Path.Combine(this.GameModsDir, this.EscapeInvalidFilenameCharacters(this.ModFolderName)); - this.Log.LogMessage(MessageImportance.High, $"The mod build package is copying the mod files to {outputPath}..."); + this.Log.LogMessage(MessageImportance.High, $"[mod build package] Copying the mod files to {outputPath}..."); this.CreateModFolder(package.GetFiles(), outputPath); } // create release zip if (this.EnableModZip) { - this.Log.LogMessage(MessageImportance.High, $"The mod build package is generating a release zip at {this.ModZipPath} for {this.ModFolderName}..."); - this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, package.GetManifestVersion(), this.ModZipPath); + string zipName = this.EscapeInvalidFilenameCharacters($"{this.ModFolderName} {package.GetManifestVersion()}.zip"); + string zipPath = Path.Combine(this.ModZipPath, zipName); + + this.Log.LogMessage(MessageImportance.High, $"[mod build package] Generating the release zip at {zipPath}..."); + this.CreateReleaseZip(package.GetFiles(), this.ModFolderName, zipPath); } return true; @@ -90,7 +102,7 @@ namespace StardewModdingAPI.ModBuildConfig } catch (Exception ex) { - this.Log.LogError($"The mod build package failed trying to deploy the mod.\n{ex}"); + this.Log.LogError($"[mod build package] Failed trying to deploy the mod.\n{ex}"); return false; } } @@ -99,6 +111,29 @@ namespace StardewModdingAPI.ModBuildConfig /********* ** Private methods *********/ + /// <summary>Get the properties to write to the log.</summary> + private IEnumerable<KeyValuePair<string, string>> GetPropertiesToLog() + { + var properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + foreach (PropertyInfo property in properties.OrderBy(p => p.Name)) + { + if (property.Name == nameof(this.IgnoreModFilePatterns) && string.IsNullOrWhiteSpace(this.IgnoreModFilePatterns)) + continue; + + string name = property.Name; + + string value = property.GetValue(this)?.ToString(); + if (value == null) + value = "null"; + else if (property.PropertyType == typeof(bool)) + value = value.ToLower(); + else + value = $"'{value}'"; + + yield return new KeyValuePair<string, string>(name, value); + } + } + /// <summary>Get the custom ignore patterns provided by the user.</summary> private IEnumerable<Regex> GetCustomIgnorePatterns() { @@ -114,7 +149,7 @@ namespace StardewModdingAPI.ModBuildConfig } catch (Exception ex) { - this.Log.LogWarning($"Ignored invalid <{nameof(this.IgnoreModFilePatterns)}> pattern {raw}:\n{ex}"); + this.Log.LogWarning($"[mod build package] Ignored invalid <{nameof(this.IgnoreModFilePatterns)}> pattern {raw}:\n{ex}"); continue; } @@ -142,17 +177,14 @@ namespace StardewModdingAPI.ModBuildConfig /// <summary>Create a release zip in the recommended format for uploading to mod sites.</summary> /// <param name="files">The files to include.</param> /// <param name="modName">The name of the mod.</param> - /// <param name="modVersion">The mod version string.</param> - /// <param name="outputFolderPath">The absolute or relative path to the folder which should contain the generated zip file.</param> - private void CreateReleaseZip(IDictionary<string, FileInfo> files, string modName, string modVersion, string outputFolderPath) + /// <param name="zipPath">The absolute path to the zip file to create.</param> + private void CreateReleaseZip(IDictionary<string, FileInfo> files, string modName, string zipPath) { - // get names - string zipName = this.EscapeInvalidFilenameCharacters($"{modName} {modVersion}.zip"); + // get folder name within zip string folderName = this.EscapeInvalidFilenameCharacters(modName); - string zipPath = Path.Combine(outputFolderPath, zipName); // create zip file - Directory.CreateDirectory(outputFolderPath); + Directory.CreateDirectory(Path.GetDirectoryName(zipPath)!); using Stream zipStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write); using ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create); |