BasePlugin.cs 2.7 KB

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