aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Plugins
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Plugins')
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs220
-rw-r--r--MediaBrowser.Common/Plugins/BasePluginOfT.cs208
-rw-r--r--MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs27
-rw-r--r--MediaBrowser.Common/Plugins/IPlugin.cs40
-rw-r--r--MediaBrowser.Common/Plugins/IPluginManager.cs86
-rw-r--r--MediaBrowser.Common/Plugins/LocalPlugin.cs91
-rw-r--r--MediaBrowser.Common/Plugins/PluginManifest.cs110
7 files changed, 496 insertions, 286 deletions
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 084e91d50..e228ae7ec 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -1,5 +1,3 @@
-#pragma warning disable SA1402
-
using System;
using System.IO;
using System.Reflection;
@@ -7,7 +5,6 @@ using System.Runtime.InteropServices;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
-using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
{
@@ -64,14 +61,12 @@ namespace MediaBrowser.Common.Plugins
/// <returns>PluginInfo.</returns>
public virtual PluginInfo GetPluginInfo()
{
- var info = new PluginInfo
- {
- Name = Name,
- Version = Version.ToString(),
- Description = Description,
- Id = Id.ToString(),
- CanUninstall = CanUninstall
- };
+ var info = new PluginInfo(
+ Name,
+ Version,
+ Description,
+ Id,
+ CanUninstall);
return info;
}
@@ -97,207 +92,4 @@ namespace MediaBrowser.Common.Plugins
Id = assemblyId;
}
}
-
- /// <summary>
- /// Provides a common base class for all plugins.
- /// </summary>
- /// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
- public abstract class BasePlugin<TConfigurationType> : BasePlugin, IHasPluginConfiguration
- where TConfigurationType : BasePluginConfiguration
- {
- /// <summary>
- /// The configuration sync lock.
- /// </summary>
- private readonly object _configurationSyncLock = new object();
-
- /// <summary>
- /// The configuration save lock.
- /// </summary>
- private readonly object _configurationSaveLock = new object();
-
- private Action<string> _directoryCreateFn;
-
- /// <summary>
- /// The configuration.
- /// </summary>
- private TConfigurationType _configuration;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="BasePlugin{TConfigurationType}" /> class.
- /// </summary>
- /// <param name="applicationPaths">The application paths.</param>
- /// <param name="xmlSerializer">The XML serializer.</param>
- protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
- {
- ApplicationPaths = applicationPaths;
- XmlSerializer = xmlSerializer;
- if (this is IPluginAssembly assemblyPlugin)
- {
- var assembly = GetType().Assembly;
- var assemblyName = assembly.GetName();
- var assemblyFilePath = assembly.Location;
-
- var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
-
- assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version);
-
- var idAttributes = assembly.GetCustomAttributes(typeof(GuidAttribute), true);
- if (idAttributes.Length > 0)
- {
- var attribute = (GuidAttribute)idAttributes[0];
- var assemblyId = new Guid(attribute.Value);
-
- assemblyPlugin.SetId(assemblyId);
- }
- }
-
- if (this is IHasPluginConfiguration hasPluginConfiguration)
- {
- hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s));
- }
- }
-
- /// <summary>
- /// Gets the application paths.
- /// </summary>
- /// <value>The application paths.</value>
- protected IApplicationPaths ApplicationPaths { get; private set; }
-
- /// <summary>
- /// Gets the XML serializer.
- /// </summary>
- /// <value>The XML serializer.</value>
- protected IXmlSerializer XmlSerializer { get; private set; }
-
- /// <summary>
- /// Gets the type of configuration this plugin uses.
- /// </summary>
- /// <value>The type of the configuration.</value>
- public Type ConfigurationType => typeof(TConfigurationType);
-
- /// <summary>
- /// Gets or sets the event handler that is triggered when this configuration changes.
- /// </summary>
- public EventHandler<BasePluginConfiguration> ConfigurationChanged { get; set; }
-
- /// <summary>
- /// Gets the name the assembly file.
- /// </summary>
- /// <value>The name of the assembly file.</value>
- protected string AssemblyFileName => Path.GetFileName(AssemblyFilePath);
-
- /// <summary>
- /// Gets or sets the plugin configuration.
- /// </summary>
- /// <value>The configuration.</value>
- public TConfigurationType Configuration
- {
- get
- {
- // Lazy load
- if (_configuration == null)
- {
- lock (_configurationSyncLock)
- {
- if (_configuration == null)
- {
- _configuration = LoadConfiguration();
- }
- }
- }
-
- return _configuration;
- }
-
- protected set => _configuration = value;
- }
-
- /// <summary>
- /// Gets the name of the configuration file. Subclasses should override.
- /// </summary>
- /// <value>The name of the configuration file.</value>
- public virtual string ConfigurationFileName => Path.ChangeExtension(AssemblyFileName, ".xml");
-
- /// <summary>
- /// Gets the full path to the configuration file.
- /// </summary>
- /// <value>The configuration file path.</value>
- public string ConfigurationFilePath => Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
-
- /// <summary>
- /// Gets the plugin configuration.
- /// </summary>
- /// <value>The configuration.</value>
- BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration;
-
- /// <inheritdoc />
- public void SetStartupInfo(Action<string> directoryCreateFn)
- {
- // hack alert, until the .net core transition is complete
- _directoryCreateFn = directoryCreateFn;
- }
-
- private TConfigurationType LoadConfiguration()
- {
- var path = ConfigurationFilePath;
-
- try
- {
- return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path);
- }
- catch
- {
- var config = (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
- SaveConfiguration(config);
- return config;
- }
- }
-
- /// <summary>
- /// Saves the current configuration to the file system.
- /// </summary>
- /// <param name="config">Configuration to save.</param>
- public virtual void SaveConfiguration(TConfigurationType config)
- {
- lock (_configurationSaveLock)
- {
- _directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath));
-
- XmlSerializer.SerializeToFile(config, ConfigurationFilePath);
- }
- }
-
- /// <summary>
- /// Saves the current configuration to the file system.
- /// </summary>
- public virtual void SaveConfiguration()
- {
- SaveConfiguration(Configuration);
- }
-
- /// <inheritdoc />
- public virtual void UpdateConfiguration(BasePluginConfiguration configuration)
- {
- if (configuration == null)
- {
- throw new ArgumentNullException(nameof(configuration));
- }
-
- Configuration = (TConfigurationType)configuration;
-
- SaveConfiguration(Configuration);
-
- ConfigurationChanged?.Invoke(this, configuration);
- }
-
- /// <inheritdoc />
- public override PluginInfo GetPluginInfo()
- {
- var info = base.GetPluginInfo();
-
- info.ConfigurationFileName = ConfigurationFileName;
-
- return info;
- }
- }
}
diff --git a/MediaBrowser.Common/Plugins/BasePluginOfT.cs b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
new file mode 100644
index 000000000..d5c780851
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/BasePluginOfT.cs
@@ -0,0 +1,208 @@
+#pragma warning disable SA1649 // File name should match first type name
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Model.Plugins;
+using MediaBrowser.Model.Serialization;
+
+namespace MediaBrowser.Common.Plugins
+{
+ /// <summary>
+ /// Provides a common base class for all plugins.
+ /// </summary>
+ /// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
+ public abstract class BasePlugin<TConfigurationType> : BasePlugin, IHasPluginConfiguration
+ where TConfigurationType : BasePluginConfiguration
+ {
+ /// <summary>
+ /// The configuration sync lock.
+ /// </summary>
+ private readonly object _configurationSyncLock = new object();
+
+ /// <summary>
+ /// The configuration save lock.
+ /// </summary>
+ private readonly object _configurationSaveLock = new object();
+
+ /// <summary>
+ /// The configuration.
+ /// </summary>
+ private TConfigurationType _configuration;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BasePlugin{TConfigurationType}" /> class.
+ /// </summary>
+ /// <param name="applicationPaths">The application paths.</param>
+ /// <param name="xmlSerializer">The XML serializer.</param>
+ protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
+ {
+ ApplicationPaths = applicationPaths;
+ XmlSerializer = xmlSerializer;
+ if (this is IPluginAssembly assemblyPlugin)
+ {
+ var assembly = GetType().Assembly;
+ var assemblyName = assembly.GetName();
+ var assemblyFilePath = assembly.Location;
+
+ var dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(assemblyFilePath));
+ if (!Directory.Exists(dataFolderPath) && Version != null)
+ {
+ // Try again with the version number appended to the folder name.
+ dataFolderPath = dataFolderPath + "_" + Version.ToString();
+ }
+
+ assemblyPlugin.SetAttributes(assemblyFilePath, dataFolderPath, assemblyName.Version);
+
+ var idAttributes = assembly.GetCustomAttributes(typeof(GuidAttribute), true);
+ if (idAttributes.Length > 0)
+ {
+ var attribute = (GuidAttribute)idAttributes[0];
+ var assemblyId = new Guid(attribute.Value);
+
+ assemblyPlugin.SetId(assemblyId);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets the application paths.
+ /// </summary>
+ /// <value>The application paths.</value>
+ protected IApplicationPaths ApplicationPaths { get; private set; }
+
+ /// <summary>
+ /// Gets the XML serializer.
+ /// </summary>
+ /// <value>The XML serializer.</value>
+ protected IXmlSerializer XmlSerializer { get; private set; }
+
+ /// <summary>
+ /// Gets the type of configuration this plugin uses.
+ /// </summary>
+ /// <value>The type of the configuration.</value>
+ public Type ConfigurationType => typeof(TConfigurationType);
+
+ /// <summary>
+ /// Gets or sets the event handler that is triggered when this configuration changes.
+ /// </summary>
+ public EventHandler<BasePluginConfiguration> ConfigurationChanged { get; set; }
+
+ /// <summary>
+ /// Gets the name the assembly file.
+ /// </summary>
+ /// <value>The name of the assembly file.</value>
+ protected string AssemblyFileName => Path.GetFileName(AssemblyFilePath);
+
+ /// <summary>
+ /// Gets or sets the plugin configuration.
+ /// </summary>
+ /// <value>The configuration.</value>
+ public TConfigurationType Configuration
+ {
+ get
+ {
+ // Lazy load
+ if (_configuration == null)
+ {
+ lock (_configurationSyncLock)
+ {
+ if (_configuration == null)
+ {
+ _configuration = LoadConfiguration();
+ }
+ }
+ }
+
+ return _configuration;
+ }
+
+ protected set => _configuration = value;
+ }
+
+ /// <summary>
+ /// Gets the name of the configuration file. Subclasses should override.
+ /// </summary>
+ /// <value>The name of the configuration file.</value>
+ public virtual string ConfigurationFileName => Path.ChangeExtension(AssemblyFileName, ".xml");
+
+ /// <summary>
+ /// Gets the full path to the configuration file.
+ /// </summary>
+ /// <value>The configuration file path.</value>
+ public string ConfigurationFilePath => Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName);
+
+ /// <summary>
+ /// Gets the plugin configuration.
+ /// </summary>
+ /// <value>The configuration.</value>
+ BasePluginConfiguration IHasPluginConfiguration.Configuration => Configuration;
+
+ /// <summary>
+ /// Saves the current configuration to the file system.
+ /// </summary>
+ /// <param name="config">Configuration to save.</param>
+ public virtual void SaveConfiguration(TConfigurationType config)
+ {
+ lock (_configurationSaveLock)
+ {
+ var folder = Path.GetDirectoryName(ConfigurationFilePath);
+ if (!Directory.Exists(folder))
+ {
+ Directory.CreateDirectory(folder);
+ }
+
+ XmlSerializer.SerializeToFile(config, ConfigurationFilePath);
+ }
+ }
+
+ /// <summary>
+ /// Saves the current configuration to the file system.
+ /// </summary>
+ public virtual void SaveConfiguration()
+ {
+ SaveConfiguration(Configuration);
+ }
+
+ /// <inheritdoc />
+ public virtual void UpdateConfiguration(BasePluginConfiguration configuration)
+ {
+ if (configuration == null)
+ {
+ throw new ArgumentNullException(nameof(configuration));
+ }
+
+ Configuration = (TConfigurationType)configuration;
+
+ SaveConfiguration(Configuration);
+
+ ConfigurationChanged?.Invoke(this, configuration);
+ }
+
+ /// <inheritdoc />
+ public override PluginInfo GetPluginInfo()
+ {
+ var info = base.GetPluginInfo();
+
+ info.ConfigurationFileName = ConfigurationFileName;
+
+ return info;
+ }
+
+ private TConfigurationType LoadConfiguration()
+ {
+ var path = ConfigurationFilePath;
+
+ try
+ {
+ return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path);
+ }
+ catch
+ {
+ var config = (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
+ SaveConfiguration(config);
+ return config;
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs
new file mode 100644
index 000000000..af9272caa
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/IHasPluginConfiguration.cs
@@ -0,0 +1,27 @@
+using System;
+using MediaBrowser.Model.Plugins;
+
+namespace MediaBrowser.Common.Plugins
+{
+ /// <summary>
+ /// Defines the <see cref="IHasPluginConfiguration" />.
+ /// </summary>
+ public interface IHasPluginConfiguration
+ {
+ /// <summary>
+ /// Gets the type of configuration this plugin uses.
+ /// </summary>
+ Type ConfigurationType { get; }
+
+ /// <summary>
+ /// Gets the plugin's configuration.
+ /// </summary>
+ BasePluginConfiguration Configuration { get; }
+
+ /// <summary>
+ /// Completely overwrites the current configuration with a new copy.
+ /// </summary>
+ /// <param name="configuration">The configuration.</param>
+ void UpdateConfiguration(BasePluginConfiguration configuration);
+ }
+}
diff --git a/MediaBrowser.Common/Plugins/IPlugin.cs b/MediaBrowser.Common/Plugins/IPlugin.cs
index d583a5887..b2ba1179c 100644
--- a/MediaBrowser.Common/Plugins/IPlugin.cs
+++ b/MediaBrowser.Common/Plugins/IPlugin.cs
@@ -1,44 +1,36 @@
-#pragma warning disable CS1591
-
using System;
using MediaBrowser.Model.Plugins;
-using Microsoft.Extensions.DependencyInjection;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
- /// Interface IPlugin.
+ /// Defines the <see cref="IPlugin" />.
/// </summary>
public interface IPlugin
{
/// <summary>
/// Gets the name of the plugin.
/// </summary>
- /// <value>The name.</value>
string Name { get; }
/// <summary>
- /// Gets the description.
+ /// Gets the Description.
/// </summary>
- /// <value>The description.</value>
string Description { get; }
/// <summary>
/// Gets the unique id.
/// </summary>
- /// <value>The unique id.</value>
Guid Id { get; }
/// <summary>
/// Gets the plugin version.
/// </summary>
- /// <value>The version.</value>
Version Version { get; }
/// <summary>
/// Gets the path to the assembly file.
/// </summary>
- /// <value>The assembly file path.</value>
string AssemblyFilePath { get; }
/// <summary>
@@ -49,11 +41,10 @@ namespace MediaBrowser.Common.Plugins
/// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed.
/// </summary>
- /// <value>The data folder path.</value>
string DataFolderPath { get; }
/// <summary>
- /// Gets the plugin info.
+ /// Gets the <see cref="PluginInfo"/>.
/// </summary>
/// <returns>PluginInfo.</returns>
PluginInfo GetPluginInfo();
@@ -63,29 +54,4 @@ namespace MediaBrowser.Common.Plugins
/// </summary>
void OnUninstalling();
}
-
- public interface IHasPluginConfiguration
- {
- /// <summary>
- /// Gets the type of configuration this plugin uses.
- /// </summary>
- /// <value>The type of the configuration.</value>
- Type ConfigurationType { get; }
-
- /// <summary>
- /// Gets the plugin's configuration.
- /// </summary>
- /// <value>The configuration.</value>
- BasePluginConfiguration Configuration { get; }
-
- /// <summary>
- /// Completely overwrites the current configuration with a new copy
- /// Returns true or false indicating success or failure.
- /// </summary>
- /// <param name="configuration">The configuration.</param>
- /// <exception cref="ArgumentNullException"><c>configuration</c> is <c>null</c>.</exception>
- void UpdateConfiguration(BasePluginConfiguration configuration);
-
- void SetStartupInfo(Action<string> directoryCreateFn);
- }
}
diff --git a/MediaBrowser.Common/Plugins/IPluginManager.cs b/MediaBrowser.Common/Plugins/IPluginManager.cs
new file mode 100644
index 000000000..3da34d8bb
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/IPluginManager.cs
@@ -0,0 +1,86 @@
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace MediaBrowser.Common.Plugins
+{
+ /// <summary>
+ /// Defines the <see cref="IPluginManager" />.
+ /// </summary>
+ public interface IPluginManager
+ {
+ /// <summary>
+ /// Gets the Plugins.
+ /// </summary>
+ IList<LocalPlugin> Plugins { get; }
+
+ /// <summary>
+ /// Creates the plugins.
+ /// </summary>
+ void CreatePlugins();
+
+ /// <summary>
+ /// Returns all the assemblies.
+ /// </summary>
+ /// <returns>An IEnumerable{Assembly}.</returns>
+ IEnumerable<Assembly> LoadAssemblies();
+
+ /// <summary>
+ /// Registers the plugin's services with the DI.
+ /// Note: DI is not yet instantiated yet.
+ /// </summary>
+ /// <param name="serviceCollection">A <see cref="ServiceCollection"/> instance.</param>
+ void RegisterServices(IServiceCollection serviceCollection);
+
+ /// <summary>
+ /// Saves the manifest back to disk.
+ /// </summary>
+ /// <param name="manifest">The <see cref="PluginManifest"/> to save.</param>
+ /// <param name="path">The path where to save the manifest.</param>
+ /// <returns>True if successful.</returns>
+ bool SaveManifest(PluginManifest manifest, string path);
+
+ /// <summary>
+ /// Imports plugin details from a folder.
+ /// </summary>
+ /// <param name="folder">Folder of the plugin.</param>
+ void ImportPluginFrom(string folder);
+
+ /// <summary>
+ /// Disable the plugin.
+ /// </summary>
+ /// <param name="assembly">The <see cref="Assembly"/> of the plug to disable.</param>
+ void FailPlugin(Assembly assembly);
+
+ /// <summary>
+ /// Disable the plugin.
+ /// </summary>
+ /// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
+ void DisablePlugin(LocalPlugin plugin);
+
+ /// <summary>
+ /// Enables the plugin, disabling all other versions.
+ /// </summary>
+ /// <param name="plugin">The <see cref="LocalPlugin"/> of the plug to disable.</param>
+ void EnablePlugin(LocalPlugin plugin);
+
+ /// <summary>
+ /// Attempts to find the plugin with and id of <paramref name="id"/>.
+ /// </summary>
+ /// <param name="id">Id of plugin.</param>
+ /// <param name="version">The version of the plugin to locate.</param>
+ /// <returns>A <see cref="LocalPlugin"/> if located, or null if not.</returns>
+ LocalPlugin? GetPlugin(Guid id, Version? version = null);
+
+ /// <summary>
+ /// Removes the plugin.
+ /// </summary>
+ /// <param name="plugin">The plugin.</param>
+ /// <returns>Outcome of the operation.</returns>
+ bool RemovePlugin(LocalPlugin plugin);
+ }
+}
diff --git a/MediaBrowser.Common/Plugins/LocalPlugin.cs b/MediaBrowser.Common/Plugins/LocalPlugin.cs
index c97e75a3b..23b6cfa81 100644
--- a/MediaBrowser.Common/Plugins/LocalPlugin.cs
+++ b/MediaBrowser.Common/Plugins/LocalPlugin.cs
@@ -1,6 +1,7 @@
+#nullable enable
using System;
using System.Collections.Generic;
-using System.Globalization;
+using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
@@ -9,36 +10,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.Id;
/// <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 +64,19 @@ 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>
/// Compare two <see cref="LocalPlugin"/>.
@@ -80,10 +86,15 @@ namespace MediaBrowser.Common.Plugins
/// <returns>Comparison result.</returns>
public static int Compare(LocalPlugin a, LocalPlugin b)
{
- var compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture);
+ if (a == null || b == null)
+ {
+ throw new ArgumentNullException(a == null ? nameof(a) : nameof(b));
+ }
+
+ var compare = string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase);
// 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 +102,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.Id, true);
+ inst.Status = Manifest.Status;
+ inst.HasImage = !string.IsNullOrEmpty(Manifest.ImagePath);
+ 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 +127,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);
}
}
}
diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs
new file mode 100644
index 000000000..4c724f694
--- /dev/null
+++ b/MediaBrowser.Common/Plugins/PluginManifest.cs
@@ -0,0 +1,110 @@
+#nullable enable
+
+using System;
+using System.Text.Json.Serialization;
+using MediaBrowser.Model.Plugins;
+
+namespace MediaBrowser.Common.Plugins
+{
+ /// <summary>
+ /// Defines a Plugin manifest file.
+ /// </summary>
+ public class PluginManifest
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PluginManifest"/> class.
+ /// </summary>
+ public PluginManifest()
+ {
+ Category = string.Empty;
+ Changelog = string.Empty;
+ Description = string.Empty;
+ Id = Guid.Empty;
+ Name = string.Empty;
+ Owner = string.Empty;
+ Overview = string.Empty;
+ TargetAbi = string.Empty;
+ Version = string.Empty;
+ }
+
+ /// <summary>
+ /// Gets or sets the category of the plugin.
+ /// </summary>
+ [JsonPropertyName("category")]
+ public string Category { get; set; }
+
+ /// <summary>
+ /// Gets or sets the changelog information.
+ /// </summary>
+ [JsonPropertyName("changelog")]
+ public string Changelog { get; set; }
+
+ /// <summary>
+ /// Gets or sets the description of the plugin.
+ /// </summary>
+ [JsonPropertyName("description")]
+ public string Description { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Global Unique Identifier for the plugin.
+ /// </summary>
+ [JsonPropertyName("guid")]
+ public Guid Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Name of the plugin.
+ /// </summary>
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+
+ /// <summary>
+ /// Gets or sets an overview of the plugin.
+ /// </summary>
+ [JsonPropertyName("overview")]
+ public string Overview { get; set; }
+
+ /// <summary>
+ /// Gets or sets the owner of the plugin.
+ /// </summary>
+ [JsonPropertyName("owner")]
+ public string Owner { get; set; }
+
+ /// <summary>
+ /// Gets or sets the compatibility version for the plugin.
+ /// </summary>
+ [JsonPropertyName("targetAbi")]
+ public string TargetAbi { get; set; }
+
+ /// <summary>
+ /// Gets or sets the timestamp of the plugin.
+ /// </summary>
+ [JsonPropertyName("timestamp")]
+ public DateTime Timestamp { get; set; }
+
+ /// <summary>
+ /// Gets or sets the Version number of the plugin.
+ /// </summary>
+ [JsonPropertyName("version")]
+ public string Version { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating the operational status of this plugin.
+ /// </summary>
+ [JsonPropertyName("status")]
+ public PluginStatus Status { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this plugin should automatically update.
+ /// </summary>
+ [JsonPropertyName("autoUpdate")]
+ public bool AutoUpdate { get; set; } = true; // DO NOT MOVE THIS INTO THE CONSTRUCTOR.
+
+ /// <summary>
+ /// Gets or sets the ImagePath
+ /// Gets or sets a value indicating whether this plugin has an image.
+ /// Image must be located in the local plugin folder.
+ /// </summary>
+ [JsonPropertyName("imagePath")]
+ public string? ImagePath { get; set; }
+ }
+}