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; }
/// Whether the mod should be loaded by default. This is false if it was found within a folder whose name starts with a dot.
public bool ShouldBeLoaded { 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.
/// Whether the mod should be loaded by default. This should be false if it was found within a folder whose name starts with a dot.
public ModFolder(DirectoryInfo root, DirectoryInfo directory, Manifest manifest, string manifestParseError = null, bool shouldBeLoaded = true)
{
// save info
this.Directory = directory;
this.Manifest = manifest;
this.ManifestParseError = manifestParseError;
this.ShouldBeLoaded = shouldBeLoaded;
// 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();
}
}
}