aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Plugins/LocalPlugin.cs
diff options
context:
space:
mode:
authorGreenback <jimcartlidge@yahoo.co.uk>2020-12-06 23:48:54 +0000
committerGreenback <jimcartlidge@yahoo.co.uk>2020-12-14 16:14:39 +0000
commit7986465cf785ca385fd1765326887e550bced033 (patch)
tree8859e9b336326081b9dfdc8d550d7f7d6d6652b7 /MediaBrowser.Common/Plugins/LocalPlugin.cs
parentf2c2beca0f9a249edd7cc967c328d32ebdc30092 (diff)
Initial upload
Diffstat (limited to 'MediaBrowser.Common/Plugins/LocalPlugin.cs')
-rw-r--r--MediaBrowser.Common/Plugins/LocalPlugin.cs94
1 files changed, 61 insertions, 33 deletions
diff --git a/MediaBrowser.Common/Plugins/LocalPlugin.cs b/MediaBrowser.Common/Plugins/LocalPlugin.cs
index c97e75a3b..ef9ab7a7d 100644
--- a/MediaBrowser.Common/Plugins/LocalPlugin.cs
+++ b/MediaBrowser.Common/Plugins/LocalPlugin.cs
@@ -1,6 +1,9 @@
+#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Reflection;
+using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
@@ -9,36 +12,48 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
public class LocalPlugin : IEquatable<LocalPlugin>
{
+ private readonly bool _supported;
+ private Version? _version;
+
/// <summary>
/// Initializes a new instance of the <see cref="LocalPlugin"/> class.
/// </summary>
- /// <param name="id">The plugin id.</param>
- /// <param name="name">The plugin name.</param>
- /// <param name="version">The plugin version.</param>
/// <param name="path">The plugin path.</param>
- public LocalPlugin(Guid id, string name, Version version, string path)
+ /// <param name="isSupported"><b>True</b> if Jellyfin supports this version of the plugin.</param>
+ /// <param name="manifest">The manifest record for this plugin, or null if one does not exist.</param>
+ public LocalPlugin(string path, bool isSupported, PluginManifest manifest)
{
- Id = id;
- Name = name;
- Version = version;
Path = path;
DllFiles = new List<string>();
+ _supported = isSupported;
+ Manifest = manifest;
}
/// <summary>
/// Gets the plugin id.
/// </summary>
- public Guid Id { get; }
+ public Guid Id => Manifest.Guid;
/// <summary>
/// Gets the plugin name.
/// </summary>
- public string Name { get; }
+ public string Name => Manifest.Name;
/// <summary>
/// Gets the plugin version.
/// </summary>
- public Version Version { get; }
+ public Version Version
+ {
+ get
+ {
+ if (_version == null)
+ {
+ _version = Version.Parse(Manifest.Version);
+ }
+
+ return _version;
+ }
+ }
/// <summary>
/// Gets the plugin path.
@@ -51,26 +66,24 @@ namespace MediaBrowser.Common.Plugins
public List<string> DllFiles { get; }
/// <summary>
- /// == operator.
+ /// Gets or sets the instance of this plugin.
/// </summary>
- /// <param name="left">Left item.</param>
- /// <param name="right">Right item.</param>
- /// <returns>Comparison result.</returns>
- public static bool operator ==(LocalPlugin left, LocalPlugin right)
- {
- return left.Equals(right);
- }
+ public IPlugin? Instance { get; set; }
/// <summary>
- /// != operator.
+ /// Gets a value indicating whether Jellyfin supports this version of the plugin, and it's enabled.
/// </summary>
- /// <param name="left">Left item.</param>
- /// <param name="right">Right item.</param>
- /// <returns>Comparison result.</returns>
- public static bool operator !=(LocalPlugin left, LocalPlugin right)
- {
- return !left.Equals(right);
- }
+ public bool IsEnabledAndSupported => _supported && Manifest.Status >= PluginStatus.Active;
+
+ /// <summary>
+ /// Gets a value indicating whether the plugin has a manifest.
+ /// </summary>
+ public PluginManifest Manifest { get; }
+
+ /// <summary>
+ /// Gets or sets a value indicating the assembly of the plugin.
+ /// </summary>
+ public Assembly? Assembly { get; set; }
/// <summary>
/// Compare two <see cref="LocalPlugin"/>.
@@ -80,10 +93,15 @@ namespace MediaBrowser.Common.Plugins
/// <returns>Comparison result.</returns>
public static int Compare(LocalPlugin a, LocalPlugin b)
{
+ if (a == null || b == null)
+ {
+ throw new ArgumentNullException(a == null ? nameof(a) : nameof(b));
+ }
+
var compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture);
// Id is not equal but name is.
- if (a.Id != b.Id && compare == 0)
+ if (!a.Id.Equals(b.Id) && compare == 0)
{
compare = a.Id.CompareTo(b.Id);
}
@@ -91,8 +109,20 @@ namespace MediaBrowser.Common.Plugins
return compare == 0 ? a.Version.CompareTo(b.Version) : compare;
}
+ /// <summary>
+ /// Returns the plugin information.
+ /// </summary>
+ /// <returns>A <see cref="PluginInfo"/> instance containing the information.</returns>
+ public PluginInfo GetPluginInfo()
+ {
+ var inst = Instance?.GetPluginInfo() ?? new PluginInfo(Manifest.Name, Version, Manifest.Description, Manifest.Guid, true);
+ inst.Status = Manifest.Status;
+ inst.HasImage = !string.IsNullOrEmpty(Manifest.ImageUrl);
+ return inst;
+ }
+
/// <inheritdoc />
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is LocalPlugin other && this.Equals(other);
}
@@ -104,16 +134,14 @@ namespace MediaBrowser.Common.Plugins
}
/// <inheritdoc />
- public bool Equals(LocalPlugin other)
+ public bool Equals(LocalPlugin? other)
{
- // Do not use == or != for comparison as this class overrides the operators.
- if (object.ReferenceEquals(other, null))
+ if (other == null)
{
return false;
}
- return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase)
- && Id.Equals(other.Id);
+ return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) && Id.Equals(other.Id) && Version.Equals(other.Version);
}
}
}