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 --- docs/release-notes.md | 3 ++ .../Framework/ModScanning/ModFolder.cs | 35 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 8e8e1981..3fbfd990 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -16,6 +16,9 @@ * For mod authors: * Added support for [custom update manifests](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Update_checks#Custom_update_manifest) (thanks to Jamie Taylor!). +* For SMAPI toolkit users: + * Fixed `ModFolder` not being JSON-serializable. + ## 3.18.3 Released 09 April 2023 for Stardew Valley 1.5.6 or later. 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