summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels/LogParserModel.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-01 11:07:29 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-01 11:07:29 -0400
commit60b41195778af33fd609eab66d9ae3f1d1165e8f (patch)
tree7128b906d40e94c56c34ed6058f27bc31c31a08b /src/SMAPI.Web/ViewModels/LogParserModel.cs
parentb9bc1a6d17cafa0a97b46ffecda432cfc2f23b51 (diff)
parent52cf953f685c65b2b6814e375ec9a5ffa03c440a (diff)
downloadSMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.gz
SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.tar.bz2
SMAPI-60b41195778af33fd609eab66d9ae3f1d1165e8f.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Web/ViewModels/LogParserModel.cs')
-rw-r--r--src/SMAPI.Web/ViewModels/LogParserModel.cs57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs
index 8c026536..df36ca73 100644
--- a/src/SMAPI.Web/ViewModels/LogParserModel.cs
+++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs
@@ -1,3 +1,6 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.RegularExpressions;
using StardewModdingAPI.Web.Framework.LogParsing.Models;
namespace StardewModdingAPI.Web.ViewModels
@@ -6,6 +9,13 @@ namespace StardewModdingAPI.Web.ViewModels
public class LogParserModel
{
/*********
+ ** Properties
+ *********/
+ /// <summary>A regex pattern matching characters to remove from a mod name to create the slug ID.</summary>
+ private readonly Regex SlugInvalidCharPattern = new Regex("[^a-z0-9]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+
+
+ /*********
** Accessors
*********/
/// <summary>The root URL for the log parser controller.</summary>
@@ -17,6 +27,15 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>The parsed log info.</summary>
public ParsedLog ParsedLog { get; set; }
+ /// <summary>Whether to show the raw unparsed log.</summary>
+ public bool ShowRaw { get; set; }
+
+ /// <summary>An error which occurred while uploading the log to Pastebin.</summary>
+ public string UploadError { get; set; }
+
+ /// <summary>An error which occurred while parsing the log file.</summary>
+ public string ParseError => this.ParsedLog?.Error;
+
/*********
** Public methods
@@ -27,12 +46,46 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>Construct an instance.</summary>
/// <param name="sectionUrl">The root URL for the log parser controller.</param>
/// <param name="pasteID">The paste ID.</param>
- /// <param name="parsedLog">The parsed log info.</param>
- public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog)
+ public LogParserModel(string sectionUrl, string pasteID)
{
this.SectionUrl = sectionUrl;
this.PasteID = pasteID;
+ this.ParsedLog = null;
+ this.ShowRaw = false;
+ }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="sectionUrl">The root URL for the log parser controller.</param>
+ /// <param name="pasteID">The paste ID.</param>
+ /// <param name="parsedLog">The parsed log info.</param>
+ /// <param name="showRaw">Whether to show the raw unparsed log.</param>
+ public LogParserModel(string sectionUrl, string pasteID, ParsedLog parsedLog, bool showRaw)
+ : this(sectionUrl, pasteID)
+ {
this.ParsedLog = parsedLog;
+ this.ShowRaw = showRaw;
+ }
+
+ /// <summary>Get all content packs in the log grouped by the mod they're for.</summary>
+ public IDictionary<string, LogModInfo[]> GetContentPacksByMod()
+ {
+ // get all mods & content packs
+ LogModInfo[] mods = this.ParsedLog?.Mods;
+ if (mods == null || !mods.Any())
+ return new Dictionary<string, LogModInfo[]>();
+
+ // group by mod
+ return mods
+ .Where(mod => mod.ContentPackFor != null)
+ .GroupBy(mod => mod.ContentPackFor)
+ .ToDictionary(group => group.Key, group => group.ToArray());
+ }
+
+ /// <summary>Get a sanitised mod name that's safe to use in anchors, attributes, and URLs.</summary>
+ /// <param name="modName">The mod name.</param>
+ public string GetSlug(string modName)
+ {
+ return this.SlugInvalidCharPattern.Replace(modName, "");
}
}
}