using System.Collections.Generic; using System.IO; using System.Linq; using StardewModdingAPI.Toolkit.Serialisation.Models; namespace StardewModdingAPI.Toolkit.Framework.ModScanning { /// The info about a mod read from its folder. public class ModFolder { /********* ** Accessors *********/ /// The Mods subfolder containing this mod. public DirectoryInfo SearchDirectory { get; } /// The folder containing manifest.json. public DirectoryInfo ActualDirectory { get; } /// The mod manifest. public Manifest Manifest { get; } /// The error which occurred parsing the manifest, if any. public string ManifestParseError { get; } /********* ** Public methods *********/ /// Construct an instance when a mod wasn't found in a folder. /// The directory that was searched. public ModFolder(DirectoryInfo searchDirectory) { this.SearchDirectory = searchDirectory; } /// Construct an instance. /// The Mods subfolder containing this mod. /// The folder containing manifest.json. /// The mod manifest. /// The error which occurred parsing the manifest, if any. public ModFolder(DirectoryInfo searchDirectory, DirectoryInfo actualDirectory, Manifest manifest, string manifestParseError = null) { this.SearchDirectory = searchDirectory; this.ActualDirectory = actualDirectory; this.Manifest = manifest; this.ManifestParseError = manifestParseError; } /// Get the update keys for a mod. /// The mod manifest. public IEnumerable GetUpdateKeys(Manifest manifest) { return (manifest.UpdateKeys ?? new string[0]) .Where(p => !string.IsNullOrWhiteSpace(p)) .ToArray(); } } }