You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jellyfin/MediaBrowser.Common/Plugins/BasePlugin.cs

96 lines
2.8 KiB

using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using MediaBrowser.Common.Configuration;
6 years ago
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Common.Plugins
{
/// <summary>
/// Provides a common base class for all plugins.
/// </summary>
6 years ago
public abstract class BasePlugin : IPlugin, IPluginAssembly
{
/// <summary>
/// Gets the name of the plugin.
6 years ago
/// </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;
6 years ago
/// <summary>
/// Gets the unique id.
/// </summary>
/// <value>The unique id.</value>
public virtual Guid Id { get; private set; }
/// <summary>
/// Gets the plugin version.
6 years ago
/// </summary>
/// <value>The version.</value>
public Version Version { get; private set; }
/// <summary>
/// Gets the path to the assembly file.
6 years ago
/// </summary>
/// <value>The assembly file path.</value>
public string AssemblyFilePath { get; private set; }
/// <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)
.Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.InvariantCulture);
6 years ago
/// <summary>
/// Gets the plugin info.
/// </summary>
/// <returns>PluginInfo.</returns>
public virtual PluginInfo GetPluginInfo()
{
4 years ago
var info = new PluginInfo(
Name,
Version,
Description,
Id,
CanUninstall);
6 years ago
return info;
}
/// <summary>
/// Called just before the plugin is uninstalled from the server.
6 years ago
/// </summary>
public virtual void OnUninstalling()
{
}
/// <inheritdoc />
6 years ago
public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion)
{
AssemblyFilePath = assemblyFilePath;
DataFolderPath = dataFolderPath;
Version = assemblyVersion;
}
/// <inheritdoc />
6 years ago
public void SetId(Guid assemblyId)
{
Id = assemblyId;
}
}
}