aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Plugins/BasePlugin.cs
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-03 12:40:35 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-09-03 12:40:35 -0400
commit31357d3298baa8e0f540dfefc47eb39da8df128d (patch)
tree375a9f037ed5d1b3fa1ced03cfe460a682f2252e /MediaBrowser.Common/Plugins/BasePlugin.cs
parent9baf40becb21a248267a6a6c23061d7b3d3fe4e2 (diff)
Updated plugins to store their assemblies directly in the plugins folder
Diffstat (limited to 'MediaBrowser.Common/Plugins/BasePlugin.cs')
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs76
1 files changed, 59 insertions, 17 deletions
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
/// </summary>
public abstract class BasePlugin : IDisposable
{
+ private IKernel Kernel { get; set; }
+
/// <summary>
/// Gets or sets the plugin's current context
/// </summary>
- public KernelContext Context { get; set; }
+ protected KernelContext Context { get { return Kernel.KernelContext; } }
/// <summary>
/// Gets the name of the plugin
@@ -51,41 +53,66 @@ namespace MediaBrowser.Common.Plugins
protected abstract Type ConfigurationType { get; }
/// <summary>
- /// Gets or sets the path to the plugin's folder
+ /// Gets the plugin version
/// </summary>
- public string Path { get; set; }
+ public Version Version
+ {
+ get
+ {
+ return GetType().Assembly.GetName().Version;
+ }
+ }
/// <summary>
- /// Gets or sets the plugin version
+ /// Gets or sets the current plugin configuration
/// </summary>
- public Version Version { get; set; }
+ public BasePluginConfiguration Configuration { get; protected set; }
/// <summary>
- /// Gets or sets the current plugin configuration
+ /// Gets the name of the configuration file. Subclasses should override
/// </summary>
- public BasePluginConfiguration Configuration { get; protected set; }
+ public virtual string ConfigurationFileName { get { return Name + ".xml"; } }
- protected string ConfigurationPath
+ /// <summary>
+ /// Gets the full path to the configuration file
+ /// </summary>
+ 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;
+ /// <summary>
+ /// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed
+ /// </summary>
+ 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
/// <summary>
/// Starts the plugin.
/// </summary>
- public virtual void Init()
+ public void Initialize(IKernel kernel)
+ {
+ Kernel = kernel;
+
+ ReloadConfiguration();
+
+ if (Enabled)
+ {
+ InitializeInternal();
+ }
+ }
+
+ /// <summary>
+ /// Starts the plugin.
+ /// </summary>
+ 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);
}
}
}