| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using MediaBrowser.Model.Plugins; |
| | | 4 | | |
| | | 5 | | namespace MediaBrowser.Common.Plugins |
| | | 6 | | { |
| | | 7 | | /// <summary> |
| | | 8 | | /// Local plugin class. |
| | | 9 | | /// </summary> |
| | | 10 | | public class LocalPlugin : IEquatable<LocalPlugin> |
| | | 11 | | { |
| | | 12 | | private readonly bool _supported; |
| | | 13 | | private Version? _version; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="LocalPlugin"/> class. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="path">The plugin path.</param> |
| | | 19 | | /// <param name="isSupported"><b>True</b> if Jellyfin supports this version of the plugin.</param> |
| | | 20 | | /// <param name="manifest">The manifest record for this plugin, or null if one does not exist.</param> |
| | | 21 | | public LocalPlugin(string path, bool isSupported, PluginManifest manifest) |
| | | 22 | | { |
| | | 23 | | Path = path; |
| | 169 | 24 | | DllFiles = Array.Empty<string>(); |
| | 169 | 25 | | _supported = isSupported; |
| | | 26 | | Manifest = manifest; |
| | 169 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets the plugin id. |
| | | 31 | | /// </summary> |
| | 3604 | 32 | | public Guid Id => Manifest.Id; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the plugin name. |
| | | 36 | | /// </summary> |
| | 219 | 37 | | public string Name => Manifest.Name; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the plugin version. |
| | | 41 | | /// </summary> |
| | | 42 | | public Version Version |
| | | 43 | | { |
| | | 44 | | get |
| | | 45 | | { |
| | 161 | 46 | | if (_version is null) |
| | | 47 | | { |
| | 147 | 48 | | _version = Version.Parse(Manifest.Version); |
| | | 49 | | } |
| | | 50 | | |
| | 161 | 51 | | return _version; |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets the plugin path. |
| | | 57 | | /// </summary> |
| | | 58 | | public string Path { get; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets the list of dll files for this plugin. |
| | | 62 | | /// </summary> |
| | | 63 | | public IReadOnlyList<string> DllFiles { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets or sets the instance of this plugin. |
| | | 67 | | /// </summary> |
| | | 68 | | public IPlugin? Instance { get; set; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Gets a value indicating whether Jellyfin supports this version of the plugin, and it's enabled. |
| | | 72 | | /// </summary> |
| | 3 | 73 | | public bool IsEnabledAndSupported => _supported && Manifest.Status >= PluginStatus.Active; |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Gets a value indicating whether the plugin has a manifest. |
| | | 77 | | /// </summary> |
| | | 78 | | public PluginManifest Manifest { get; } |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Compare two <see cref="LocalPlugin"/>. |
| | | 82 | | /// </summary> |
| | | 83 | | /// <param name="a">The first item.</param> |
| | | 84 | | /// <param name="b">The second item.</param> |
| | | 85 | | /// <returns>Comparison result.</returns> |
| | | 86 | | public static int Compare(LocalPlugin a, LocalPlugin b) |
| | | 87 | | { |
| | 0 | 88 | | if (a is null || b is null) |
| | | 89 | | { |
| | 0 | 90 | | throw new ArgumentNullException(a is null ? nameof(a) : nameof(b)); |
| | | 91 | | } |
| | | 92 | | |
| | 0 | 93 | | var compare = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase); |
| | | 94 | | |
| | | 95 | | // Id is not equal but name is. |
| | 0 | 96 | | if (!a.Id.Equals(b.Id) && compare == 0) |
| | | 97 | | { |
| | 0 | 98 | | compare = a.Id.CompareTo(b.Id); |
| | | 99 | | } |
| | | 100 | | |
| | 0 | 101 | | return compare == 0 ? a.Version.CompareTo(b.Version) : compare; |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | /// <summary> |
| | | 105 | | /// Returns the plugin information. |
| | | 106 | | /// </summary> |
| | | 107 | | /// <returns>A <see cref="PluginInfo"/> instance containing the information.</returns> |
| | | 108 | | public PluginInfo GetPluginInfo() |
| | | 109 | | { |
| | 7 | 110 | | var inst = Instance?.GetPluginInfo() ?? new PluginInfo(Manifest.Name, Version, Manifest.Description, Manifes |
| | 7 | 111 | | inst.Status = Manifest.Status; |
| | 7 | 112 | | inst.HasImage = !string.IsNullOrEmpty(Manifest.ImagePath); |
| | 7 | 113 | | return inst; |
| | | 114 | | } |
| | | 115 | | |
| | | 116 | | /// <inheritdoc /> |
| | | 117 | | public override bool Equals(object? obj) |
| | | 118 | | { |
| | 0 | 119 | | return obj is LocalPlugin other && this.Equals(other); |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | /// <inheritdoc /> |
| | | 123 | | public override int GetHashCode() |
| | | 124 | | { |
| | 0 | 125 | | return Name.GetHashCode(StringComparison.OrdinalIgnoreCase); |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | /// <inheritdoc /> |
| | | 129 | | public bool Equals(LocalPlugin? other) |
| | | 130 | | { |
| | 0 | 131 | | if (other is null) |
| | | 132 | | { |
| | 0 | 133 | | return false; |
| | | 134 | | } |
| | | 135 | | |
| | 0 | 136 | | return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) && Id.Equals(other.Id) && Version.Equals( |
| | | 137 | | } |
| | | 138 | | } |
| | | 139 | | } |