jellyfin/MediaBrowser.Common/Plugins/BasePlugin.cs

95 lines
2.7 KiB
C#
Raw Normal View History

#nullable disable
using System;
using System.IO;
using System.Reflection;
2018-12-28 00:27:57 +01:00
using MediaBrowser.Model.Plugins;
namespace MediaBrowser.Common.Plugins
{
2019-12-11 00:13:57 +01:00
/// <summary>
/// Provides a common base class for all plugins.
/// </summary>
2018-12-28 00:27:57 +01:00
public abstract class BasePlugin : IPlugin, IPluginAssembly
{
/// <summary>
2019-12-11 00:13:57 +01:00
/// Gets the name of the plugin.
2018-12-28 00:27:57 +01:00
/// </summary>
/// <value>The name.</value>
public abstract string Name { get; }
/// <summary>
/// Gets the description.
/// </summary>
/// <value>The description.</value>
public virtual string Description => string.Empty;
2018-12-28 00:27:57 +01:00
/// <summary>
/// Gets the unique id.
/// </summary>
/// <value>The unique id.</value>
public virtual Guid Id { get; private set; }
/// <summary>
2019-12-11 00:13:57 +01:00
/// Gets the plugin version.
2018-12-28 00:27:57 +01:00
/// </summary>
/// <value>The version.</value>
public Version Version { get; private set; }
/// <summary>
2019-12-11 00:13:57 +01:00
/// Gets the path to the assembly file.
2018-12-28 00:27:57 +01:00
/// </summary>
/// <value>The assembly file path.</value>
public string AssemblyFilePath { get; private set; }
2019-12-11 00:13:57 +01:00
/// <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>
public string DataFolderPath { get; private set; }
/// <summary>
/// Gets a value indicating whether the plugin can be uninstalled.
/// </summary>
public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath)
2021-03-09 05:57:38 +01:00
.Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.Ordinal);
2018-12-28 00:27:57 +01:00
/// <summary>
/// Gets the plugin info.
/// </summary>
/// <returns>PluginInfo.</returns>
public virtual PluginInfo GetPluginInfo()
{
2020-12-07 00:48:54 +01:00
var info = new PluginInfo(
Name,
Version,
Description,
Id,
CanUninstall);
2018-12-28 00:27:57 +01:00
return info;
}
/// <summary>
/// Called just before the plugin is uninstalled from the server.
2018-12-28 00:27:57 +01:00
/// </summary>
public virtual void OnUninstalling()
{
}
2019-12-11 00:13:57 +01:00
/// <inheritdoc />
2018-12-28 00:27:57 +01:00
public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion)
{
AssemblyFilePath = assemblyFilePath;
DataFolderPath = dataFolderPath;
Version = assemblyVersion;
}
2019-12-11 00:13:57 +01:00
/// <inheritdoc />
2018-12-28 00:27:57 +01:00
public void SetId(Guid assemblyId)
{
Id = assemblyId;
}
}
}