aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Kernel/BaseApplicationPaths.cs21
-rw-r--r--MediaBrowser.Common/Kernel/BaseKernel.cs29
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs76
-rw-r--r--MediaBrowser.Common/UI/BaseApplication.cs2
4 files changed, 94 insertions, 34 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs b/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs
index 3c394680f6..798115ffaa 100644
--- a/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs
+++ b/MediaBrowser.Common/Kernel/BaseApplicationPaths.cs
@@ -47,6 +47,27 @@ namespace MediaBrowser.Common.Kernel
}
}
+ private string _pluginConfigurationsPath;
+ /// <summary>
+ /// Gets the path to the plugin configurations directory
+ /// </summary>
+ public string PluginConfigurationsPath
+ {
+ get
+ {
+ if (_pluginConfigurationsPath == null)
+ {
+ _pluginConfigurationsPath = Path.Combine(PluginsPath, "configurations");
+ if (!Directory.Exists(_pluginConfigurationsPath))
+ {
+ Directory.CreateDirectory(_pluginConfigurationsPath);
+ }
+ }
+
+ return _pluginConfigurationsPath;
+ }
+ }
+
private string _logDirectoryPath;
/// <summary>
/// Gets the path to the log directory
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index cdde17b24a..4f1bdae6b2 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -50,9 +50,9 @@ namespace MediaBrowser.Common.Kernel
}
/// <summary>
- /// Gets the kernel context. The UI kernel will have to override this.
+ /// Gets the kernel context. Subclasses will have to override.
/// </summary>
- protected KernelContext KernelContext { get { return KernelContext.Server; } }
+ public abstract KernelContext KernelContext { get; }
public BaseKernel()
{
@@ -104,7 +104,7 @@ namespace MediaBrowser.Common.Kernel
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
- IEnumerable<Assembly> pluginAssemblies = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f))));
+ IEnumerable<Assembly> pluginAssemblies = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly).Select(f => Assembly.Load(File.ReadAllBytes((f))));
var catalog = new AggregateCatalog(pluginAssemblies.Select(a => new AssemblyCatalog(a)));
@@ -144,20 +144,7 @@ namespace MediaBrowser.Common.Kernel
{
foreach (BasePlugin plugin in Plugins)
{
- Assembly assembly = plugin.GetType().Assembly;
- AssemblyName assemblyName = assembly.GetName();
-
- plugin.Version = assemblyName.Version;
- plugin.Path = Path.Combine(ApplicationPaths.PluginsPath, assemblyName.Name);
-
- plugin.Context = KernelContext;
-
- plugin.ReloadConfiguration();
-
- if (plugin.Enabled)
- {
- plugin.Init();
- }
+ plugin.Initialize(this);
}
}
@@ -276,10 +263,18 @@ namespace MediaBrowser.Common.Kernel
return GetType().Assembly.GetName().Version;
}
}
+
+ BaseApplicationPaths IKernel.ApplicationPaths
+ {
+ get { return ApplicationPaths; }
+ }
}
public interface IKernel
{
+ BaseApplicationPaths ApplicationPaths { get; }
+ KernelContext KernelContext { get; }
+
Task Init(IProgress<TaskProgress> progress);
void Dispose();
}
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index e6ebfa5518..4b6f9cba48 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);
}
}
}
diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs
index a45faca503..b19be3d7fd 100644
--- a/MediaBrowser.Common/UI/BaseApplication.cs
+++ b/MediaBrowser.Common/UI/BaseApplication.cs
@@ -5,6 +5,8 @@ using System.Windows.Media.Imaging;
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Logging;
using MediaBrowser.Model.Progress;
+using System.Runtime.InteropServices;
+using System.Security;
namespace MediaBrowser.Common.UI
{