BasePlugin.cs 2.7 KB

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