From c68e922853560dd192edf63004ea4f8f8faf6fba Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 30 Apr 2023 13:41:43 -0400 Subject: fix ModFolder not being JSON-serializable --- .../Framework/ModScanning/ModFolder.cs | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs index da2a3c85..106e3622 100644 --- a/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs +++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModFolder.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Newtonsoft.Json; using StardewModdingAPI.Toolkit.Serialization.Models; using StardewModdingAPI.Toolkit.Utilities; @@ -9,14 +10,25 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning /// The info about a mod read from its folder. public class ModFolder { + /********* + ** Fields + *********/ + /// The backing field for . + private DirectoryInfo? DirectoryImpl; + + /********* ** Accessors *********/ /// A suggested display name for the mod folder. public string DisplayName { get; } + /// The folder path containing the mod's manifest.json. + public string DirectoryPath { get; } + /// The folder containing the mod's manifest.json. - public DirectoryInfo Directory { get; } + [JsonIgnore] + public DirectoryInfo Directory => this.DirectoryImpl ??= new DirectoryInfo(this.DirectoryPath); /// The mod type. public ModType Type { get; } @@ -52,7 +64,8 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning public ModFolder(DirectoryInfo root, DirectoryInfo directory, ModType type, Manifest? manifest, ModParseError manifestParseError, string? manifestParseErrorText) { // save info - this.Directory = directory; + this.DirectoryImpl = directory; + this.DirectoryPath = directory.FullName; this.Type = type; this.Manifest = manifest; this.ManifestParseError = manifestParseError; @@ -64,6 +77,24 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning : PathUtilities.GetRelativePath(root.FullName, directory.FullName); } + /// Construct an instance. + /// A suggested display name for the mod folder. + /// The folder path containing the mod's manifest.json. + /// The mod type. + /// The mod manifest. + /// The error which occurred parsing the manifest, if any. + /// A human-readable message for the , if any. + [JsonConstructor] + public ModFolder(string displayName, string directoryPath, ModType type, Manifest? manifest, ModParseError manifestParseError, string? manifestParseErrorText) + { + this.DisplayName = displayName; + this.DirectoryPath = directoryPath; + this.Type = type; + this.Manifest = manifest; + this.ManifestParseError = manifestParseError; + this.ManifestParseErrorText = manifestParseErrorText; + } + /// Get the update keys for a mod. /// The mod manifest. public IEnumerable GetUpdateKeys(Manifest manifest) -- cgit