From 31357d3298baa8e0f540dfefc47eb39da8df128d Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 3 Sep 2012 12:40:35 -0400 Subject: Updated plugins to store their assemblies directly in the plugins folder --- MediaBrowser.Common/Plugins/BasePlugin.cs | 76 ++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 17 deletions(-) (limited to 'MediaBrowser.Common/Plugins/BasePlugin.cs') diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index e6ebfa551..4b6f9cba4 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -35,10 +35,12 @@ namespace MediaBrowser.Common.Plugins /// public abstract class BasePlugin : IDisposable { + private IKernel Kernel { get; set; } + /// /// Gets or sets the plugin's current context /// - public KernelContext Context { get; set; } + protected KernelContext Context { get { return Kernel.KernelContext; } } /// /// Gets the name of the plugin @@ -51,41 +53,66 @@ namespace MediaBrowser.Common.Plugins protected abstract Type ConfigurationType { get; } /// - /// Gets or sets the path to the plugin's folder + /// Gets the plugin version /// - public string Path { get; set; } + public Version Version + { + get + { + return GetType().Assembly.GetName().Version; + } + } /// - /// Gets or sets the plugin version + /// Gets or sets the current plugin configuration /// - public Version Version { get; set; } + public BasePluginConfiguration Configuration { get; protected set; } /// - /// Gets or sets the current plugin configuration + /// Gets the name of the configuration file. Subclasses should override /// - public BasePluginConfiguration Configuration { get; protected set; } + public virtual string ConfigurationFileName { get { return Name + ".xml"; } } - protected string ConfigurationPath + /// + /// Gets the full path to the configuration file + /// + public string ConfigurationFilePath { get { - return System.IO.Path.Combine(Path, "config.js"); + return Path.Combine(Kernel.ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName); } } - public bool Enabled + private string _DataFolderPath = null; + /// + /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed + /// + public string DataFolderPath { get { - return Configuration.Enabled; + if (_DataFolderPath == null) + { + // Give the folder name the same name as the config file name + // We can always make this configurable if/when needed + _DataFolderPath = Path.Combine(Kernel.ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName)); + + if (!Directory.Exists(_DataFolderPath)) + { + Directory.CreateDirectory(_DataFolderPath); + } + } + + return _DataFolderPath; } } - public DateTime ConfigurationDateLastModified + public bool Enabled { get { - return Configuration.DateLastModified; + return Configuration.Enabled; } } @@ -103,7 +130,22 @@ namespace MediaBrowser.Common.Plugins /// /// Starts the plugin. /// - public virtual void Init() + public void Initialize(IKernel kernel) + { + Kernel = kernel; + + ReloadConfiguration(); + + if (Enabled) + { + InitializeInternal(); + } + } + + /// + /// Starts the plugin. + /// + protected virtual void InitializeInternal() { } @@ -116,14 +158,14 @@ namespace MediaBrowser.Common.Plugins public void ReloadConfiguration() { - if (!File.Exists(ConfigurationPath)) + if (!File.Exists(ConfigurationFilePath)) { Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration; } else { - Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationPath) as BasePluginConfiguration; - Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath); + Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationFilePath) as BasePluginConfiguration; + Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationFilePath); } } } -- cgit v1.2.3