using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; namespace MediaBrowser.Common.Plugins { /// /// Provides a common base class for all plugins. /// public abstract class BasePlugin : IPlugin, IPluginAssembly { /// /// Gets the name of the plugin. /// /// The name. public abstract string Name { get; } /// /// Gets the description. /// /// The description. public virtual string Description => string.Empty; /// /// Gets the unique id. /// /// The unique id. public virtual Guid Id { get; private set; } /// /// Gets the plugin version. /// /// The version. public Version Version { get; private set; } /// /// Gets the path to the assembly file. /// /// The assembly file path. public string AssemblyFilePath { get; private set; } /// /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed. /// /// The data folder path. public string DataFolderPath { get; private set; } /// /// Gets a value indicating whether the plugin can be uninstalled. /// public bool CanUninstall => !Path.GetDirectoryName(AssemblyFilePath) .Equals(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), StringComparison.InvariantCulture); /// /// Gets the plugin info. /// /// PluginInfo. public virtual PluginInfo GetPluginInfo() { var info = new PluginInfo( Name, Version, Description, Id, CanUninstall); return info; } /// /// Called just before the plugin is uninstalled from the server. /// public virtual void OnUninstalling() { } /// public void SetAttributes(string assemblyFilePath, string dataFolderPath, Version assemblyVersion) { AssemblyFilePath = assemblyFilePath; DataFolderPath = dataFolderPath; Version = assemblyVersion; } /// public void SetId(Guid assemblyId) { Id = assemblyId; } } }