BasePlugin.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Runtime.InteropServices;
  5. using MediaBrowser.Common.Configuration;
  6. using MediaBrowser.Model.Plugins;
  7. using MediaBrowser.Model.Serialization;
  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. /// <summary>
  21. /// Gets the description.
  22. /// </summary>
  23. /// <value>The description.</value>
  24. public virtual string Description => string.Empty;
  25. /// <summary>
  26. /// Gets the unique id.
  27. /// </summary>
  28. /// <value>The unique id.</value>
  29. public virtual Guid Id { get; private set; }
  30. /// <summary>
  31. /// Gets the plugin version.
  32. /// </summary>
  33. /// <value>The version.</value>
  34. public Version Version { get; private set; }
  35. /// <summary>
  36. /// Gets the path to the assembly file.
  37. /// </summary>
  38. /// <value>The assembly file path.</value>
  39. public string AssemblyFilePath { get; private set; }
  40. /// <summary>
  41. /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed.
  42. /// </summary>
  43. /// <value>The data folder path.</value>
  44. public string DataFolderPath { get; private set; }
  45. /// <summary>
  46. /// Gets a value indicating whether the plugin can be uninstalled.
  47. /// </summary>
  48. public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath)
  49. .Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.InvariantCulture);
  50. /// <summary>
  51. /// Gets the plugin info.
  52. /// </summary>
  53. /// <returns>PluginInfo.</returns>
  54. public virtual PluginInfo GetPluginInfo()
  55. {
  56. var info = new PluginInfo(
  57. Name,
  58. Version,
  59. Description,
  60. Id,
  61. CanUninstall);
  62. return info;
  63. }
  64. /// <summary>
  65. /// Called just before the plugin is uninstalled from the server.
  66. /// </summary>
  67. public virtual void OnUninstalling()
  68. {
  69. }
  70. /// <inheritdoc />
  71. public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion)
  72. {
  73. AssemblyFilePath = assemblyFilePath;
  74. DataFolderPath = dataFolderPath;
  75. Version = assemblyVersion;
  76. }
  77. /// <inheritdoc />
  78. public void SetId(Guid assemblyId)
  79. {
  80. Id = assemblyId;
  81. }
  82. }
  83. }