using System; using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; namespace Artemis.Core; /// /// Represents basic info about a plugin and contains a reference to the instance of said plugin /// public class PluginInfo : IPrerequisitesSubject { [JsonConstructor] internal PluginInfo() { } /// /// The plugins GUID /// [JsonRequired] [JsonInclude] public Guid Guid { get; internal init; } /// /// The name of the plugin /// [JsonRequired] [JsonInclude] public string Name { get; internal init; } = null!; /// /// The version of the plugin /// [JsonRequired] [JsonInclude] public string Version { get; internal init; } = null!; /// /// The main entry DLL, should contain a class implementing Plugin /// [JsonRequired] [JsonInclude] public string Main { get; internal init; } = null!; /// /// A short description of the plugin /// [JsonInclude] public string? Description { get; internal init; } /// /// Gets or sets the author of this plugin /// [JsonInclude] public string? Author { get; internal init; } /// /// Gets or sets the website of this plugin or its author /// [JsonInclude] public Uri? Website { get; internal init; } /// /// Gets or sets the repository of this plugin /// [JsonInclude] public Uri? Repository { get; internal init; } /// /// Gets or sets the help page of this plugin /// [JsonInclude] public Uri? HelpPage { get; internal init; } /// /// Gets or sets the help page of this plugin /// [JsonInclude] public Uri? License { get; internal init; } /// /// Gets or sets the author of this plugin /// [JsonInclude] public string? LicenseName { get; internal init; } /// /// The plugins display icon that's shown in the settings see for /// available icons /// [JsonInclude] public string? Icon { get; internal init; } /// /// Gets a boolean indicating whether this plugin requires elevated admin privileges /// [JsonInclude] public bool RequiresAdmin { get; internal init; } /// /// Gets or sets a boolean indicating whether hot reloading this plugin is supported /// [JsonInclude] public bool HotReloadSupported { get; internal init; } = true; /// /// Gets /// [JsonInclude] public PluginPlatform? Platforms { get; internal init; } /// /// Gets the API version the plugin was built for /// [JsonInclude] public Version? Api { get; internal init; } = new(1, 0, 0); /// /// Gets the minimum version of Artemis required by this plugin /// public Version? MinimumVersion { get; internal init; } = new(1, 0, 0); /// /// Gets the plugin this info is associated with /// [JsonIgnore] public Plugin Plugin { get; internal set; } = null!; /// /// Gets a string representing either a full path pointing to an svg or the markdown icon /// [JsonIgnore] public string? ResolvedIcon => Icon == null ? null : Icon.Contains('.') ? Plugin.ResolveRelativePath(Icon) : Icon; /// /// Gets a boolean indicating whether this plugin is compatible with the current operating system and API version /// [JsonIgnore] public bool IsCompatible => Platforms.MatchesCurrentOperatingSystem() && Api != null && Api.Major >= Constants.PluginApiVersion && MatchesMinimumVersion(); /// [JsonIgnore] public List Prerequisites { get; } = new(); /// [JsonIgnore] public IEnumerable PlatformPrerequisites => Prerequisites.Where(p => p.AppliesToPlatform()); [JsonIgnore] internal string PreferredPluginDirectory => $"{Main.Split(".dll")[0].Replace("/", "").Replace("\\", "")}-{Guid.ToString().Substring(0, 8)}"; /// public bool ArePrerequisitesMet() { return PlatformPrerequisites.All(p => p.IsMet()); } /// public override string ToString() { return $"{Name} v{Version} - {Guid}"; } private bool MatchesMinimumVersion() { if (Constants.CurrentVersion == "local") return true; Version currentVersion = new(Constants.CurrentVersion); return currentVersion >= MinimumVersion; } /// /// Returns a boolean indicating whether this plugin info matches the provided search string /// /// The search string to match /// A boolean indicating whether this plugin info matches the provided search string public bool MatchesSearch(string search) { return Name.Contains(search, StringComparison.InvariantCultureIgnoreCase) || (Description != null && Description.Contains(search, StringComparison.InvariantCultureIgnoreCase)); } }