using System.Collections.Generic; using System.IO; using System.Linq; using StardewModdingAPI.Toolkit.Serialisation.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 manifest. public Manifest Manifest { get; } /// The error which occurred parsing the manifest, if any. public string ManifestParseError { get; } /********* ** Public methods *********/ /// Construct an instance. /// The root folder containing mods. /// The folder containing the mod's manifest.json. /// The mod manifest. /// The error which occurred parsing the manifest, if any. public ModFolder(DirectoryInfo root, DirectoryInfo directory, Manifest manifest, string manifestParseError = null) { // save info this.Directory = directory; this.Manifest = manifest; this.ManifestParseError = manifestParseError; // 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 ?? new string[0]) .Where(p => !string.IsNullOrWhiteSpace(p)) .ToArray(); } } }