| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | using System; |
| | | 4 | | using System.IO; |
| | | 5 | | using System.Reflection; |
| | | 6 | | using MediaBrowser.Model.Plugins; |
| | | 7 | | |
| | | 8 | | namespace MediaBrowser.Common.Plugins |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Provides a common base class for all plugins. |
| | | 12 | | /// </summary> |
| | | 13 | | public abstract class BasePlugin : IPlugin, IPluginAssembly |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Gets the name of the plugin. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <value>The name.</value> |
| | | 19 | | public abstract string Name { get; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the description. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <value>The description.</value> |
| | 0 | 25 | | public virtual string Description => string.Empty; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets the unique id. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <value>The unique id.</value> |
| | | 31 | | public virtual Guid Id { get; private set; } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets the plugin version. |
| | | 35 | | /// </summary> |
| | | 36 | | /// <value>The version.</value> |
| | | 37 | | public Version Version { get; private set; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the path to the assembly file. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <value>The assembly file path.</value> |
| | | 43 | | public string AssemblyFilePath { get; private set; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed. |
| | | 47 | | /// </summary> |
| | | 48 | | /// <value>The data folder path.</value> |
| | | 49 | | public string DataFolderPath { get; private set; } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets a value indicating whether the plugin can be uninstalled. |
| | | 53 | | /// </summary> |
| | 7 | 54 | | public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath) |
| | 7 | 55 | | .Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.Ordinal); |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Gets the plugin info. |
| | | 59 | | /// </summary> |
| | | 60 | | /// <returns>PluginInfo.</returns> |
| | | 61 | | public virtual PluginInfo GetPluginInfo() |
| | | 62 | | { |
| | 7 | 63 | | var info = new PluginInfo( |
| | 7 | 64 | | Name, |
| | 7 | 65 | | Version, |
| | 7 | 66 | | Description, |
| | 7 | 67 | | Id, |
| | 7 | 68 | | CanUninstall); |
| | | 69 | | |
| | 7 | 70 | | return info; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Called just before the plugin is uninstalled from the server. |
| | | 75 | | /// </summary> |
| | | 76 | | public virtual void OnUninstalling() |
| | | 77 | | { |
| | 0 | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <inheritdoc /> |
| | | 81 | | public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion) |
| | | 82 | | { |
| | 147 | 83 | | AssemblyFilePath = assemblyFilePath; |
| | 147 | 84 | | DataFolderPath = dataFolderPath; |
| | 147 | 85 | | Version = assemblyVersion; |
| | 147 | 86 | | } |
| | | 87 | | |
| | | 88 | | /// <inheritdoc /> |
| | | 89 | | public void SetId(Guid assemblyId) |
| | | 90 | | { |
| | 0 | 91 | | Id = assemblyId; |
| | 0 | 92 | | } |
| | | 93 | | } |
| | | 94 | | } |