diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-03-01 14:10:46 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-03-01 14:10:46 -0500 |
commit | 10c7192bb9f06ff96b9b98a812d9f72a8d77ac76 (patch) | |
tree | 7d4c4ed3498d53e4e8a1c3167fa3937d51b25ecb /src/SMAPI.Web/Framework/LogParsing | |
parent | 84b9f4336d5b0c7f269a7bfbb94042360574bbaa (diff) | |
parent | 460b440c2ef4f8c7e2015375fa603095146d1f11 (diff) | |
download | SMAPI-10c7192bb9f06ff96b9b98a812d9f72a8d77ac76.tar.gz SMAPI-10c7192bb9f06ff96b9b98a812d9f72a8d77ac76.tar.bz2 SMAPI-10c7192bb9f06ff96b9b98a812d9f72a8d77ac76.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Web/Framework/LogParsing')
-rw-r--r-- | src/SMAPI.Web/Framework/LogParsing/LogParser.cs | 51 | ||||
-rw-r--r-- | src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs (renamed from src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs) | 12 |
2 files changed, 57 insertions, 6 deletions
diff --git a/src/SMAPI.Web/Framework/LogParsing/LogParser.cs b/src/SMAPI.Web/Framework/LogParsing/LogParser.cs index 6f848469..fdc19404 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 /// <summary>A regex pattern matching an entry in SMAPI's content pack list.</summary> private readonly Regex ContentPackListEntryPattern = new Regex(@"^ (?<name>.+) (?<version>.+) by (?<author>.+) \| for (?<for>.+?)(?: \| (?<description>.+))?$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + /// <summary>A regex pattern matching the start of SMAPI's mod update list.</summary> + private readonly Regex ModUpdateListStartPattern = new Regex(@"^You can update \d+ mods?:$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// <summary>A regex pattern matching an entry in SMAPI's mod update list.</summary> + private readonly Regex ModUpdateListEntryPattern = new Regex(@"^ (?<name>.+?) (?<version>" + SemanticVersion.UnboundedVersionPattern + @"): (?<link>.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + + /// <summary>A regex pattern matching SMAPI's update line.</summary> + private readonly Regex SMAPIUpdatePattern = new Regex(@"^You can update SMAPI to (?<version>" + SemanticVersion.UnboundedVersionPattern + @"): (?<link>.+)$", 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<string, LogModInfo> mods = new Dictionary<string, LogModInfo>(); bool inModList = false; bool inContentPackList = false; + bool inModUpdateList = false; foreach (LogMessage message in log.Messages) { // collect stats @@ -90,11 +100,9 @@ namespace StardewModdingAPI.Web.Framework.LogParsing break; default: - { if (mods.ContainsKey(message.Mod)) mods[message.Mod].Errors++; break; - } } } @@ -106,6 +114,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 +127,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 +141,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/ModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs index 8c84ab38..067e4df4 100644 --- a/src/SMAPI.Web/Framework/LogParsing/Models/ModInfo.cs +++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs @@ -12,6 +12,12 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// <summary>The mod author.</summary> public string Author { get; set; } + /// <summary>The update version.</summary> + public string UpdateVersion { get; set; } + + /// <summary>The update link.</summary> + public string UpdateLink { get; set; } + /// <summary>The mod version.</summary> public string Version { get; set; } @@ -23,5 +29,11 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models /// <summary>The number of errors logged by this mod.</summary> public int Errors { get; set; } + + /// <summary>Whether the mod was loaded into the game.</summary> + public bool Loaded { get; set; } + + /// <summary>Whether the mod has an update available.</summary> + public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion; } } |