From 248ba90b75df31a657978c17ad4c6dff26210c96 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 9 Jun 2018 19:46:12 -0400 Subject: add metadata dump option for troubleshooting --- src/SMAPI/Framework/Models/ModFolderExport.cs | 21 +++++++++++++++++++++ src/SMAPI/Framework/Models/SConfig.cs | 3 +++ src/SMAPI/Program.cs | 16 +++++++++++++++- src/SMAPI/StardewModdingAPI.config.json | 6 ++++++ src/SMAPI/StardewModdingAPI.csproj | 1 + 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/SMAPI/Framework/Models/ModFolderExport.cs (limited to 'src') diff --git a/src/SMAPI/Framework/Models/ModFolderExport.cs b/src/SMAPI/Framework/Models/ModFolderExport.cs new file mode 100644 index 00000000..3b8d451a --- /dev/null +++ b/src/SMAPI/Framework/Models/ModFolderExport.cs @@ -0,0 +1,21 @@ +namespace StardewModdingAPI.Framework.Models +{ + /// Metadata exported to the mod folder. + internal class ModFolderExport + { + /// When the export was generated. + public string Exported { get; set; } + + /// The absolute path of the mod folder. + public string ModFolderPath { get; set; } + + /// The game version which last loaded the mods. + public string GameVersion { get; set; } + + /// The SMAPI version which last loaded the mods. + public string ApiVersion { get; set; } + + /// The detected mods. + public IModMetadata[] Mods { get; set; } + } +} diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index 98614933..15671af4 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -26,6 +26,9 @@ namespace StardewModdingAPI.Framework.Models /// Whether SMAPI should log more information about the game context. public bool VerboseLogging { get; set; } + /// Whether to generate a file in the mods folder with detailed metadata about the detected mods. + public bool DumpMetadata { get; set; } + /// The console color scheme to use. public MonitorColorScheme ColorScheme { get; set; } diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 4ede45d5..350a6195 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -428,6 +428,20 @@ namespace StardewModdingAPI // load mods this.LoadMods(mods, this.JsonHelper, this.ContentCore, modDatabase); + // write metadata file + if (this.Settings.DumpMetadata) + { + ModFolderExport export = new ModFolderExport + { + Exported = DateTime.UtcNow.ToString("O"), + ApiVersion = Constants.ApiVersion.ToString(), + GameVersion = Constants.GameVersion.ToString(), + ModFolderPath = Constants.ModPath, + Mods = mods + }; + this.JsonHelper.WriteJsonFile(Path.Combine(Constants.LogDir, $"{Constants.LogNamePrefix}.metadata-dump.json"), export); + } + // check for updates this.CheckForUpdatesAsync(mods); } @@ -1276,7 +1290,7 @@ namespace StardewModdingAPI if (!logsDir.Exists) return; - foreach (FileInfo logFile in logsDir.EnumerateFiles("*.txt")) + foreach (FileInfo logFile in logsDir.EnumerateFiles()) { if (logFile.Name.StartsWith(Constants.LogNamePrefix, StringComparison.InvariantCultureIgnoreCase)) { diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index 7aac6e4c..115997ba 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -44,6 +44,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha */ "VerboseLogging": false, + /** + * Whether to generate a 'SMAPI-latest.metadata-dump.json' file in the logs folder with the full mod + * metadata for detected mods. This is only needed when troubleshooting some cases. + */ + "DumpMetadata": false, + /** * The console color theme to use. The possible values are: * - AutoDetect: SMAPI will assume a light background on Mac, and detect the background color automatically on Linux or Windows. diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 2df3e63f..8e3ad83b 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -107,6 +107,7 @@ + -- cgit