From e0ef8a20a5e7ccf1de32ff1a06f1aa62e37eb1db Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 19 Jun 2022 17:21:53 -0400 Subject: fix mod count in log parser metadata --- src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 4 ++-- .../Framework/LogParsing/Models/LogModInfo.cs | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src/SMAPI.Web/Framework/LogParsing') diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs index 55272b23..7fc8f958 100644 --- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs +++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs @@ -77,8 +77,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing }; // parse log messages - LogModInfo smapiMod = new(name: "SMAPI", author: "Pathoschild", version: "", description: "", loaded: true); - LogModInfo gameMod = new(name: "game", author: "", version: "", description: "", loaded: true); + LogModInfo smapiMod = new(name: "SMAPI", author: "Pathoschild", version: "", description: "", loaded: true, isMod: false); + LogModInfo gameMod = new(name: "game", author: "", version: "", description: "", loaded: true, isMod: false); IDictionary> mods = new Dictionary>(); bool inModList = false; bool inContentPackList = false; diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs index a6b9165c..4b80a830 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs @@ -39,9 +39,15 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models [MemberNotNullWhen(true, nameof(LogModInfo.UpdateVersion), nameof(LogModInfo.UpdateLink))] public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion; - /// Whether the mod is a content pack for another mod. + /// Whether this is an actual mod (rather than a special entry for SMAPI or the game itself). + public bool IsMod { get; } + + /// Whether this is a C# code mod. + public bool IsCodeMod { get; } + + /// Whether this is a content pack for another mod. [MemberNotNullWhen(true, nameof(LogModInfo.ContentPackFor))] - public bool IsContentPack => !string.IsNullOrWhiteSpace(this.ContentPackFor); + public bool IsContentPack { get; } /********* @@ -57,7 +63,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// The name of the mod for which this is a content pack (if applicable). /// The number of errors logged by this mod. /// Whether the mod was loaded into the game. - public LogModInfo(string name, string author, string version, string description, string? updateVersion = null, string? updateLink = null, string? contentPackFor = null, int errors = 0, bool loaded = true) + /// Whether this is an actual mod (instead of a special entry for SMAPI or the game). + public LogModInfo(string name, string author, string version, string description, string? updateVersion = null, string? updateLink = null, string? contentPackFor = null, int errors = 0, bool loaded = true, bool isMod = true) { this.Name = name; this.Author = author; @@ -68,6 +75,13 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models this.ContentPackFor = contentPackFor; this.Errors = errors; this.Loaded = loaded; + + if (isMod) + { + this.IsMod = true; + this.IsContentPack = !string.IsNullOrWhiteSpace(this.ContentPackFor); + this.IsCodeMod = !this.IsContentPack; + } } /// Add an update alert for this mod. -- cgit From 0ba4fd1785fc6a6aa931f18552261f33c2a2c0ef Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 5 Jul 2022 22:09:46 -0400 Subject: detect missing/outdated Error Handler for 'suggested fixes' section --- docs/release-notes.md | 1 + src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 2 + .../Framework/LogParsing/Models/LogModInfo.cs | 32 +++++- .../Framework/LogParsing/Models/ParsedLog.cs | 3 + src/SMAPI.Web/Views/LogParser/Index.cshtml | 120 ++++++++++++--------- 5 files changed, 105 insertions(+), 53 deletions(-) (limited to 'src/SMAPI.Web/Framework/LogParsing') diff --git a/docs/release-notes.md b/docs/release-notes.md index 3bc8724b..8361a780 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -18,6 +18,7 @@ * The [FluentHttpClient package](https://github.com/Pathoschild/FluentHttpClient#readme) is now loaded by SMAPI. * For the web UI: + * The log parser now detects a missing or outdated Error Handler mod for its 'suggested fixes' section. * Updated the JSON validator/schema for Content Patcher 1.27.0. * Fixed the mod count in the log parser metadata. diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs index 7fc8f958..0efa62c5 100644 --- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs +++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs @@ -200,6 +200,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing log.GameVersion = match.Groups["gameVersion"].Value; log.OperatingSystem = match.Groups["os"].Value; smapiMod.OverrideVersion(log.ApiVersion); + + log.ApiVersionParsed = smapiMod.GetParsedVersion(); } // mod path line diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs index 4b80a830..557f08ff 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs @@ -1,10 +1,19 @@ +using System; using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework.LogParsing.Models { /// Metadata about a mod or content pack in the log. public class LogModInfo { + /********* + ** Private fields + *********/ + /// The parsed mod version, if valid. + private Lazy ParsedVersionImpl; + + /********* ** Accessors *********/ @@ -68,7 +77,6 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models { this.Name = name; this.Author = author; - this.Version = version; this.Description = description; this.UpdateVersion = updateVersion; this.UpdateLink = updateLink; @@ -82,6 +90,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models this.IsContentPack = !string.IsNullOrWhiteSpace(this.ContentPackFor); this.IsCodeMod = !this.IsContentPack; } + + this.OverrideVersion(version); } /// Add an update alert for this mod. @@ -95,9 +105,29 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// Override the version number, for cases like SMAPI itself where the version is only known later during parsing. /// The new mod version. + [MemberNotNull(nameof(LogModInfo.Version), nameof(LogModInfo.ParsedVersionImpl))] public void OverrideVersion(string version) { this.Version = version; + this.ParsedVersionImpl = new Lazy(this.ParseVersion); + } + + /// Get the semantic version for this mod, if it's valid. + public ISemanticVersion? GetParsedVersion() + { + return this.ParsedVersionImpl.Value; + } + + + /********* + ** Private methods + *********/ + /// Get the semantic version for this mod, if it's valid. + public ISemanticVersion? ParseVersion() + { + return !string.IsNullOrWhiteSpace(this.Version) && SemanticVersion.TryParse(this.Version, out ISemanticVersion? version) + ? version + : null; } } } diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs index 6951e434..3f649199 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ParsedLog.cs @@ -28,6 +28,9 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// The SMAPI version. public string? ApiVersion { get; set; } + /// The parsed SMAPI version, if it's valid. + public ISemanticVersion? ApiVersionParsed { get; set; } + /// The game version. public string? GameVersion { get; set; } diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 33239a2b..8bf5d86d 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -8,24 +8,29 @@ @{ ViewData["Title"] = "SMAPI log parser"; + // get log info ParsedLog? log = Model!.ParsedLog; - IDictionary contentPacks = Model.GetContentPacksByMod(); + ISet screenIds = new HashSet(log?.Messages.Select(p => p.ScreenId) ?? Array.Empty()); + + // detect suggested fixes + LogModInfo[] outdatedMods = log?.Mods.Where(mod => mod.HasUpdate).ToArray() ?? Array.Empty(); + LogModInfo? errorHandler = log?.Mods.FirstOrDefault(p => p.IsCodeMod && p.Name == "Error Handler"); + bool hasOlderErrorHandler = errorHandler?.GetParsedVersion() is not null && log?.ApiVersionParsed is not null && log.ApiVersionParsed.IsNewerThan(errorHandler.GetParsedVersion()); + + // get filters IDictionary defaultFilters = Enum .GetValues() .ToDictionary(level => level.ToString().ToLower(), level => level != LogLevel.Trace); - IDictionary logLevels = Enum .GetValues() .ToDictionary(level => (int)level, level => level.ToString().ToLower()); - IDictionary logSections = Enum .GetValues() .ToDictionary(section => (int)section, section => section.ToString()); + // get form string curPageUrl = this.Url.PlainAction("Index", "LogParser", new { id = Model.PasteID }, absoluteUrl: true)!; - - ISet screenIds = new HashSet(log?.Messages.Select(p => p.ScreenId) ?? Array.Empty()); } @section Head { @@ -69,7 +74,7 @@ } - +