summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
-rw-r--r--src/SMAPI.Web/ViewModels/LogParserModel.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs
index 8c026536..0fbd8ad5 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,12 @@ namespace StardewModdingAPI.Web.ViewModels
/// <summary>The parsed log info.</summary>
public ParsedLog ParsedLog { 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
@@ -34,5 +50,27 @@ namespace StardewModdingAPI.Web.ViewModels
this.PasteID = pasteID;
this.ParsedLog = parsedLog;
}
+
+ /// <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, "");
+ }
}
}