summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-09 13:59:56 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-09 13:59:56 -0400
commit650af7ef1ac1957919ab19ec3d06af97792c54f8 (patch)
tree626ba6caf86d400616121a7520e33f5b8bbad7b4 /src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs
parentad4d065fe748b4f3f32a8bf03e9a96132e1a0c79 (diff)
downloadSMAPI-650af7ef1ac1957919ab19ec3d06af97792c54f8.tar.gz
SMAPI-650af7ef1ac1957919ab19ec3d06af97792c54f8.tar.bz2
SMAPI-650af7ef1ac1957919ab19ec3d06af97792c54f8.zip
enable nullable annotations in log parser (#837)
Diffstat (limited to 'src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs')
-rw-r--r--src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs71
1 files changed, 58 insertions, 13 deletions
diff --git a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs
index 349312df..a6b9165c 100644
--- a/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs
+++ b/src/SMAPI.Web/Framework/LogParsing/Models/LogModInfo.cs
@@ -1,4 +1,4 @@
-#nullable disable
+using System.Diagnostics.CodeAnalysis;
namespace StardewModdingAPI.Web.Framework.LogParsing.Models
{
@@ -9,36 +9,81 @@ namespace StardewModdingAPI.Web.Framework.LogParsing.Models
** Accessors
*********/
/// <summary>The mod name.</summary>
- public string Name { get; set; }
+ public string Name { get; }
/// <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; }
+ public string Author { get; }
/// <summary>The mod version.</summary>
- public string Version { get; set; }
+ public string Version { get; private set; }
/// <summary>The mod description.</summary>
- public string Description { get; set; }
+ public string Description { get; }
+
+ /// <summary>The update version.</summary>
+ public string? UpdateVersion { get; private set; }
+
+ /// <summary>The update link.</summary>
+ public string? UpdateLink { get; private set; }
/// <summary>The name of the mod for which this is a content pack (if applicable).</summary>
- public string ContentPackFor { get; set; }
+ public string? ContentPackFor { get; }
/// <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; }
+ public bool Loaded { get; }
/// <summary>Whether the mod has an update available.</summary>
+ [MemberNotNullWhen(true, nameof(LogModInfo.UpdateVersion), nameof(LogModInfo.UpdateLink))]
public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion;
/// <summary>Whether the mod is a content pack for another mod.</summary>
+ [MemberNotNullWhen(true, nameof(LogModInfo.ContentPackFor))]
public bool IsContentPack => !string.IsNullOrWhiteSpace(this.ContentPackFor);
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="name">The mod name.</param>
+ /// <param name="author">The mod author.</param>
+ /// <param name="version">The mod version.</param>
+ /// <param name="description">The mod description.</param>
+ /// <param name="updateVersion">The update version.</param>
+ /// <param name="updateLink">The update link.</param>
+ /// <param name="contentPackFor">The name of the mod for which this is a content pack (if applicable).</param>
+ /// <param name="errors">The number of errors logged by this mod.</param>
+ /// <param name="loaded">Whether the mod was loaded into the game.</param>
+ public LogModInfo(string name, string author, string version, string description, string? updateVersion = null, string? updateLink = null, string? contentPackFor = null, int errors = 0, bool loaded = true)
+ {
+ this.Name = name;
+ this.Author = author;
+ this.Version = version;
+ this.Description = description;
+ this.UpdateVersion = updateVersion;
+ this.UpdateLink = updateLink;
+ this.ContentPackFor = contentPackFor;
+ this.Errors = errors;
+ this.Loaded = loaded;
+ }
+
+ /// <summary>Add an update alert for this mod.</summary>
+ /// <param name="updateVersion">The update version.</param>
+ /// <param name="updateLink">The update link.</param>
+ public void SetUpdate(string updateVersion, string updateLink)
+ {
+ this.UpdateVersion = updateVersion;
+ this.UpdateLink = updateLink;
+ }
+
+ /// <summary>Override the version number, for cases like SMAPI itself where the version is only known later during parsing.</summary>
+ /// <param name="version">The new mod version.</param>
+ public void OverrideVersion(string version)
+ {
+ this.Version = version;
+ }
}
}