From 691310d16e6873b83c55f62a59d5010dd8bb7e98 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 24 Feb 2018 16:52:38 -0500 Subject: add content pack support to log parser --- src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 23 ++++++++++++++++++++++ .../Framework/LogParsing/Models/ModInfo.cs | 3 +++ 2 files changed, 26 insertions(+) (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 1c3b5671..23a1baa4 100644 --- a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs +++ b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs @@ -31,6 +31,12 @@ namespace StardewModdingAPI.Web.Framework.LogParsing /// A regex pattern matching an entry in SMAPI's mod list. private readonly Regex ModListEntryPattern = new Regex(@"^ (?.+) (?.+) by (?.+) \| (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /// A regex pattern matching the start of SMAPI's content pack list. + private readonly Regex ContentPackListStartPattern = new Regex(@"^Loaded \d+ content packs:$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// A regex pattern matching an entry in SMAPI's content pack list. + private readonly Regex ContentPackListEntryPattern = new Regex(@"^ (?.+) (?.+) by (?.+) \| for (?.+?) \| (?.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /********* ** Public methods @@ -62,6 +68,7 @@ namespace StardewModdingAPI.Web.Framework.LogParsing LogModInfo smapiMod = new LogModInfo { Name = "SMAPI", Author = "Pathoschild", Description = "" }; IDictionary mods = new Dictionary(); bool inModList = false; + bool inContentPackList = false; foreach (LogMessage message in log.Messages) { // collect stats @@ -79,6 +86,8 @@ namespace StardewModdingAPI.Web.Framework.LogParsing // update flags if (inModList && !this.ModListEntryPattern.IsMatch(message.Text)) inModList = false; + if (inContentPackList && !this.ContentPackListEntryPattern.IsMatch(message.Text)) + inContentPackList = false; // mod list if (!inModList && message.Level == LogLevel.Info && this.ModListStartPattern.IsMatch(message.Text)) @@ -93,6 +102,20 @@ namespace StardewModdingAPI.Web.Framework.LogParsing mods[name] = new LogModInfo { Name = name, Author = author, Version = version, Description = description }; } + // content pack list + else if (!inContentPackList && message.Level == LogLevel.Info && this.ContentPackListStartPattern.IsMatch(message.Text)) + inContentPackList = true; + else if (inContentPackList) + { + Match match = this.ContentPackListEntryPattern.Match(message.Text); + string name = match.Groups["name"].Value; + string version = match.Groups["version"].Value; + 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 }; + } + // platform info line else if (message.Level == LogLevel.Info && this.InfoLinePattern.IsMatch(message.Text)) { diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs index 2005e61f..8c84ab38 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs @@ -18,6 +18,9 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// 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