From a23261106ea454ab2e264007f27ca11ddbb7e44b Mon Sep 17 00:00:00 2001 From: danvolchek Date: Sun, 17 Feb 2019 20:39:36 -0600 Subject: add update info in suggested fixes section --- src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 49 ++++++++++++++++++++-- .../Framework/LogParsing/Models/LogModInfo.cs | 39 +++++++++++++++++ .../Framework/LogParsing/Models/ModInfo.cs | 27 ------------ 3 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs delete mode 100644 src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs (limited to 'src/SMAPI.Web/Framework') diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs index 6f848469..5cdc501f 100644 --- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs +++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs @@ -39,6 +39,15 @@ namespace StardewModdingAPI.Web.Framework.LogParsing /// A regex pattern matching an entry in SMAPI's content pack list. private readonly Regex ContentPackListEntryPattern = new Regex(@"^ (?.+) (?.+) by (?.+) \| for (?.+?)(?: \| (?.+))?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /// A regex pattern matching the start of SMAPI's mod update list. + private readonly Regex ModUpdateListStartPattern = new Regex(@"^You can update \d+ mods?:$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// A regex pattern matching an entry in SMAPI's mod update list. + private readonly Regex ModUpdateListEntryPattern = new Regex(@"^ (?.+?) (?" + SemanticVersion.UnboundedVersionPattern + @"): (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// A regex pattern matching SMAPI's update line. + private readonly Regex SMAPIUpdatePattern = new Regex(@"^You can update SMAPI to (?" + SemanticVersion.UnboundedVersionPattern + @"): (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /********* ** Public methods @@ -69,11 +78,12 @@ namespace StardewModdingAPI.Web.Framework.LogParsing }; // parse log messages - LogModInfo smapiMod = new LogModInfo { Name = "SMAPI", Author = "Pathoschild", Description = "" }; - LogModInfo gameMod = new LogModInfo { Name = "game", Author = "", Description = "" }; + LogModInfo smapiMod = new LogModInfo { Name = "SMAPI", Author = "Pathoschild", Description = "", Loaded = true}; + LogModInfo gameMod = new LogModInfo { Name = "game", Author = "", Description = "", Loaded = true }; IDictionary mods = new Dictionary(); bool inModList = false; bool inContentPackList = false; + bool inModUpdateList = false; foreach (LogMessage message in log.Messages) { // collect stats @@ -106,6 +116,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing inModList = false; if (inContentPackList && !this.ContentPackListEntryPattern.IsMatch(message.Text)) inContentPackList = false; + if (inModUpdateList && !this.ModUpdateListEntryPattern.IsMatch(message.Text)) + inModUpdateList = false; // mod list if (!inModList && message.Level == LogLevel.Info && this.ModListStartPattern.IsMatch(message.Text)) @@ -117,7 +129,7 @@ namespace StardewModdingAPI.Web.Framework.LogParsing string version = match.Groups["version"].Value; string author = match.Groups["author"].Value; string description = match.Groups["description"].Value; - mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description }; + mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description, Loaded = true }; } // content pack list @@ -131,7 +143,36 @@ namespace StardewModdingAPI.Web.Framework.LogParsing string author = match.Groups["author"].Value; string description = match.Groups["description"].Value; string forMod = match.Groups["for"].Value; - mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description, ContentPackFor = forMod }; + mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description, ContentPackFor = forMod, Loaded = true }; + } + + // mod update list + else if (!inModUpdateList && message.Level == LogLevel.Alert && this.ModUpdateListStartPattern.IsMatch(message.Text)) + inModUpdateList = true; + else if (inModUpdateList) + { + Match match = this.ModUpdateListEntryPattern.Match(message.Text); + string name = match.Groups["name"].Value; + string version = match.Groups["version"].Value; + string link = match.Groups["link"].Value; + if (mods.ContainsKey(name)) + { + mods[name].UpdateLink = link; + mods[name].UpdateVersion = version; + } + else + { + mods[name] = new LogModInfo {Name = name, UpdateVersion = version, UpdateLink = link, Loaded = false}; + } + } + + else if(message.Level == LogLevel.Alert && this.SMAPIUpdatePattern.IsMatch(message.Text)) + { + Match match = this.SMAPIUpdatePattern.Match(message.Text); + string version = match.Groups["version"].Value; + string link = match.Groups["link"].Value; + smapiMod.UpdateVersion = version; + smapiMod.UpdateLink = link; } // platform info line diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs new file mode 100644 index 00000000..067e4df4 --- /dev/null +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs @@ -0,0 +1,39 @@ +namespace StardewModdingAPI.Web.Framework.LogParsing.Models +{ + /// Metadata about a mod or content pack in the log. + public class LogModInfo + { + /********* + ** Accessors + *********/ + /// The mod name. + public string Name { get; set; } + + /// The mod author. + public string Author { get; set; } + + /// The update version. + public string UpdateVersion { get; set; } + + /// The update link. + public string UpdateLink { get; set; } + + /// The mod version. + public string Version { get; set; } + + /// The mod description. + public string Description { get; set; } + + /// The name of the mod for which this is a content pack (if applicable). + public string ContentPackFor { get; set; } + + /// The number of errors logged by this mod. + public int Errors { get; set; } + + /// Whether the mod was loaded into the game. + public bool Loaded { get; set; } + + /// Whether the mod has an update available. + public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion; + } +} diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs deleted file mode 100644 index 8c84ab38..00000000 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace StardewModdingAPI.Web.Framework.LogParsing.Models -{ - /// Metadata about a mod or content pack in the log. - public class LogModInfo - { - /********* - ** Accessors - *********/ - /// The mod name. - public string Name { get; set; } - - /// The mod author. - public string Author { get; set; } - - /// The mod version. - public string Version { get; set; } - - /// The mod description. - public string Description { get; set; } - - /// The name of the mod for which this is a content pack (if applicable). - public string ContentPackFor { get; set; } - - /// The number of errors logged by this mod. - public int Errors { get; set; } - } -} -- cgit