#nullable disable using System.Collections.Generic; using System.IO; using System.Linq; using StardewModdingAPI.Toolkit.Serialization.Models; using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingAPI.Toolkit.Framework.ModScanning { /// The info about a mod read from its folder. public class ModFolder { /********* ** Accessors *********/ /// A suggested display name for the mod folder. public string DisplayName { get; } /// The folder containing the mod's manifest.json. public DirectoryInfo Directory { get; } /// The mod type. public ModType Type { get; } /// The mod manifest. public Manifest Manifest { get; } /// The error which occurred parsing the manifest, if any. public ModParseError ManifestParseError { get; set; } /// A human-readable message for the , if any. public string ManifestParseErrorText { get; set; } /********* ** Public methods *********/ /// Construct an instance. /// The root folder containing mods. /// The folder containing the mod's manifest.json. /// The mod type. /// The mod manifest. public ModFolder(DirectoryInfo root, DirectoryInfo directory, ModType type, Manifest manifest) : this(root, directory, type, manifest, ModParseError.None, null) { } /// Construct an instance. /// The root folder containing mods. /// The folder 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. public ModFolder(DirectoryInfo root, DirectoryInfo directory, ModType type, Manifest manifest, ModParseError manifestParseError, string manifestParseErrorText) { // save info this.Directory = directory; this.Type = type; this.Manifest = manifest; this.ManifestParseError = manifestParseError; this.ManifestParseErrorText = manifestParseErrorText; // set display name this.DisplayName = manifest?.Name; if (string.IsNullOrWhiteSpace(this.DisplayName)) this.DisplayName = PathUtilities.GetRelativePath(root.FullName, directory.FullName); } /// Get the update keys for a mod. /// The mod manifest. public IEnumerable GetUpdateKeys(Manifest manifest) { return manifest.UpdateKeys .Where(p => !string.IsNullOrWhiteSpace(p)) .ToArray(); } } }