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