using IPA.Loader.Features;
using IPA.Utilities;
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Version = SemVer.Version;
#if NET3
using Net3_Proxy;
using Path = Net3_Proxy.Path;
#endif
namespace IPA.Loader
{
///
/// A class which describes a loaded plugin.
///
public class PluginMetadata
{
///
/// The assembly the plugin was loaded from.
///
/// the loaded Assembly that contains the plugin main type
public Assembly Assembly { get; internal set; }
///
/// The TypeDefinition for the main type of the plugin.
///
/// the Cecil definition for the plugin main type
public TypeDefinition PluginType { get; internal set; }
///
/// The human readable name of the plugin.
///
/// the name of the plugin
public string Name { get; internal set; }
///
/// The BeatMods ID of the plugin, or null if it doesn't have one.
///
/// the updater ID of the plugin
public string Id { get; internal set; }
///
/// The name of the author that wrote this plugin.
///
/// the name of the plugin's author
public string Author { get; private set; }
///
/// The version of the plugin.
///
/// the version of the plugin
public Version Version { get; internal set; }
///
/// The file the plugin was loaded from.
///
/// the file the plugin was loaded from
public FileInfo File { get; internal set; }
// ReSharper disable once UnusedAutoPropertyAccessor.Global
///
/// The features this plugin requests.
///
/// the list of features requested by the plugin
public IReadOnlyList Features => InternalFeatures;
internal readonly List InternalFeatures = new List();
///
/// A list of files (that aren't ) that are associated with this plugin.
///
/// a list of associated files
public IReadOnlyList AssociatedFiles { get; private set; } = new List();
///
/// The name of the resource in the plugin assembly containing the plugin's icon.
///
/// the name of the plugin's icon
public string IconName { get; private set; }
///
/// A link to this plugin's home page, if any.
///
/// the of the plugin's home page
public Uri PluginHomeLink { get; private set; }
///
/// A link to this plugin's source code, if avaliable.
///
/// the of the plugin's source code
public Uri PluginSourceLink { get; private set; }
///
/// A link to a donate page for the author of this plugin, if avaliable.
///
/// the of the author's donate page
public Uri DonateLink { get; private set; }
internal bool IsSelf;
///
/// Whether or not this metadata object represents a bare manifest.
///
/// if it is bare, otherwise
public bool IsBare { get; internal set; }
private PluginManifest manifest;
internal HashSet Dependencies { get; } = new HashSet();
internal PluginManifest Manifest
{
get => manifest;
set
{
manifest = value;
Name = value.Name;
Version = value.Version;
Id = value.Id;
Author = value.Author;
IconName = value.IconPath;
PluginHomeLink = value.Links.ProjectHome;
PluginSourceLink = value.Links.ProjectSource;
DonateLink = value.Links.Donate;
AssociatedFiles = value.Files
.Select(f => Path.Combine(UnityGame.InstallPath, f))
.Select(p => new FileInfo(p)).ToList();
}
}
///
/// The that the plugin specified in its .
///
public RuntimeOptions RuntimeOptions { get; internal set; }
///
/// Gets all of the metadata as a readable string.
///
/// the readable printable metadata string
public override string ToString() => $"{Name}({Id}@{Version})({PluginType?.FullName}) from '{Utils.GetRelativePath(File?.FullName, UnityGame.InstallPath)}'";
}
}