Jelajahi Sumber

Updated plugins to store their assemblies directly in the plugins folder

LukePulverenti Luke Pulverenti luke pulverenti 12 tahun lalu
induk
melakukan
31357d3298

+ 0 - 1
MediaBrowser.Api/HttpHandlers/PluginsHandler.cs

@@ -18,7 +18,6 @@ namespace MediaBrowser.Api.HttpHandlers
             {
             {
                 return new PluginInfo()
                 return new PluginInfo()
                 {
                 {
-                    Path = p.Path,
                     Name = p.Name,
                     Name = p.Name,
                     Enabled = p.Enabled,
                     Enabled = p.Enabled,
                     DownloadToUI = p.DownloadToUI,
                     DownloadToUI = p.DownloadToUI,

+ 4 - 1
MediaBrowser.Api/MediaBrowser.Api.csproj

@@ -29,6 +29,9 @@
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
+  <PropertyGroup>
+    <RunPostBuildEvent>Always</RunPostBuildEvent>
+  </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.Composition" />
@@ -97,7 +100,7 @@
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>
+    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\" /y</PostBuildEvent>
   </PropertyGroup>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.

+ 1 - 1
MediaBrowser.Api/Plugin.cs

@@ -18,7 +18,7 @@ namespace MediaBrowser.Api
             get { return "WebAPI"; }
             get { return "WebAPI"; }
         }
         }
 
 
-        public override void Init()
+        protected override void InitializeInternal()
         {
         {
             var httpServer = Kernel.Instance.HttpServer;
             var httpServer = Kernel.Instance.HttpServer;
 
 

+ 21 - 0
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;
         private string _logDirectoryPath;
         /// <summary>
         /// <summary>
         /// Gets the path to the log directory
         /// Gets the path to the log directory

+ 12 - 17
MediaBrowser.Common/Kernel/BaseKernel.cs

@@ -50,9 +50,9 @@ namespace MediaBrowser.Common.Kernel
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Gets the kernel context. The UI kernel will have to override this.
+        /// Gets the kernel context. Subclasses will have to override.
         /// </summary>
         /// </summary>
-        protected KernelContext KernelContext { get { return KernelContext.Server; } }
+        public abstract KernelContext KernelContext { get; }
 
 
         public BaseKernel()
         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
             // 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
             // 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)));
             var catalog = new AggregateCatalog(pluginAssemblies.Select(a => new AssemblyCatalog(a)));
 
 
@@ -144,20 +144,7 @@ namespace MediaBrowser.Common.Kernel
         {
         {
             foreach (BasePlugin plugin in Plugins)
             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;
                 return GetType().Assembly.GetName().Version;
             }
             }
         }
         }
+
+        BaseApplicationPaths IKernel.ApplicationPaths
+        {
+            get { return ApplicationPaths; }
+        }
     }
     }
 
 
     public interface IKernel
     public interface IKernel
     {
     {
+        BaseApplicationPaths ApplicationPaths { get; }
+        KernelContext KernelContext { get; }
+
         Task Init(IProgress<TaskProgress> progress);
         Task Init(IProgress<TaskProgress> progress);
         void Dispose();
         void Dispose();
     }
     }

+ 59 - 17
MediaBrowser.Common/Plugins/BasePlugin.cs

@@ -35,10 +35,12 @@ namespace MediaBrowser.Common.Plugins
     /// </summary>
     /// </summary>
     public abstract class BasePlugin : IDisposable
     public abstract class BasePlugin : IDisposable
     {
     {
+        private IKernel Kernel { get; set; }
+
         /// <summary>
         /// <summary>
         /// Gets or sets the plugin's current context
         /// Gets or sets the plugin's current context
         /// </summary>
         /// </summary>
-        public KernelContext Context { get; set; }
+        protected KernelContext Context { get { return Kernel.KernelContext; } }
 
 
         /// <summary>
         /// <summary>
         /// Gets the name of the plugin
         /// Gets the name of the plugin
@@ -51,41 +53,66 @@ namespace MediaBrowser.Common.Plugins
         protected abstract Type ConfigurationType { get; }
         protected abstract Type ConfigurationType { get; }
 
 
         /// <summary>
         /// <summary>
-        /// Gets or sets the path to the plugin's folder
+        /// Gets the plugin version
         /// </summary>
         /// </summary>
-        public string Path { get; set; }
+        public Version Version
+        {
+            get
+            {
+                return GetType().Assembly.GetName().Version;
+            }
+        }
 
 
         /// <summary>
         /// <summary>
-        /// Gets or sets the plugin version
+        /// Gets or sets the current plugin configuration
         /// </summary>
         /// </summary>
-        public Version Version { get; set; }
+        public BasePluginConfiguration Configuration { get; protected set; }
 
 
         /// <summary>
         /// <summary>
-        /// Gets or sets the current plugin configuration
+        /// Gets the name of the configuration file. Subclasses should override
         /// </summary>
         /// </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
             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
             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
             get
             {
             {
-                return Configuration.DateLastModified;
+                return Configuration.Enabled;
             }
             }
         }
         }
 
 
@@ -103,7 +130,22 @@ namespace MediaBrowser.Common.Plugins
         /// <summary>
         /// <summary>
         /// Starts the plugin.
         /// Starts the plugin.
         /// </summary>
         /// </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()
         public void ReloadConfiguration()
         {
         {
-            if (!File.Exists(ConfigurationPath))
+            if (!File.Exists(ConfigurationFilePath))
             {
             {
                 Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration;
                 Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration;
             }
             }
             else
             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);
             }
             }
         }
         }
     }
     }

+ 2 - 0
MediaBrowser.Common/UI/BaseApplication.cs

@@ -5,6 +5,8 @@ using System.Windows.Media.Imaging;
 using MediaBrowser.Common.Kernel;
 using MediaBrowser.Common.Kernel;
 using MediaBrowser.Common.Logging;
 using MediaBrowser.Common.Logging;
 using MediaBrowser.Model.Progress;
 using MediaBrowser.Model.Progress;
+using System.Runtime.InteropServices;
+using System.Security;
 
 
 namespace MediaBrowser.Common.UI
 namespace MediaBrowser.Common.UI
 {
 {

+ 9 - 4
MediaBrowser.Controller/Kernel.cs

@@ -40,12 +40,17 @@ namespace MediaBrowser.Controller
             }
             }
         }
         }
 
 
+        public override KernelContext KernelContext
+        {
+            get { return KernelContext.Server; }
+        }
+
         /// <summary>
         /// <summary>
         /// Gets the list of currently registered metadata prvoiders
         /// Gets the list of currently registered metadata prvoiders
         /// </summary>
         /// </summary>
         [ImportMany(typeof(BaseMetadataProvider))]
         [ImportMany(typeof(BaseMetadataProvider))]
         private IEnumerable<BaseMetadataProvider> MetadataProvidersEnumerable { get; set; }
         private IEnumerable<BaseMetadataProvider> MetadataProvidersEnumerable { get; set; }
-        
+
         /// <summary>
         /// <summary>
         /// Once MEF has loaded the resolvers, sort them by priority and store them in this array
         /// Once MEF has loaded the resolvers, sort them by priority and store them in this array
         /// Given the sheer number of times they'll be iterated over it'll be faster to loop through an array
         /// Given the sheer number of times they'll be iterated over it'll be faster to loop through an array
@@ -102,7 +107,7 @@ namespace MediaBrowser.Controller
 
 
             // Sort the resolvers by priority
             // Sort the resolvers by priority
             EntityResolvers = EntityResolversEnumerable.OrderBy(e => e.Priority).ToArray();
             EntityResolvers = EntityResolversEnumerable.OrderBy(e => e.Priority).ToArray();
-            
+
             // Sort the providers by priority
             // Sort the providers by priority
             MetadataProviders = MetadataProvidersEnumerable.OrderBy(e => e.Priority).ToArray();
             MetadataProviders = MetadataProvidersEnumerable.OrderBy(e => e.Priority).ToArray();
 
 
@@ -233,7 +238,7 @@ namespace MediaBrowser.Controller
             user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b");
             user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b");
 
 
             list.Add(user);
             list.Add(user);
-            
+
             user = new User();
             user = new User();
             user.Name = "Test User 1";
             user.Name = "Test User 1";
             user.Id = Guid.NewGuid();
             user.Id = Guid.NewGuid();
@@ -263,7 +268,7 @@ namespace MediaBrowser.Controller
             user.Name = "Test User 6";
             user.Name = "Test User 6";
             user.Id = Guid.NewGuid();
             user.Id = Guid.NewGuid();
             list.Add(user);*/
             list.Add(user);*/
-            
+
             return list;
             return list;
         }
         }
 
 

+ 4 - 1
MediaBrowser.InternetProviders/MediaBrowser.InternetProviders.csproj

@@ -29,6 +29,9 @@
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
+  <PropertyGroup>
+    <RunPostBuildEvent>Always</RunPostBuildEvent>
+  </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.Composition" />
@@ -68,7 +71,7 @@
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>
+    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\" /y</PostBuildEvent>
   </PropertyGroup>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.

+ 3 - 6
MediaBrowser.Model/DTO/PluginInfo.cs

@@ -13,18 +13,15 @@ namespace MediaBrowser.Model.DTO
         public string Name { get; set; }
         public string Name { get; set; }
 
 
         [ProtoMember(2)]
         [ProtoMember(2)]
-        public string Path { get; set; }
-
-        [ProtoMember(3)]
         public bool Enabled { get; set; }
         public bool Enabled { get; set; }
 
 
-        [ProtoMember(4)]
+        [ProtoMember(3)]
         public bool DownloadToUI { get; set; }
         public bool DownloadToUI { get; set; }
 
 
-        [ProtoMember(5)]
+        [ProtoMember(4)]
         public DateTime ConfigurationDateLastModified { get; set; }
         public DateTime ConfigurationDateLastModified { get; set; }
 
 
-        [ProtoMember(6)]
+        [ProtoMember(5)]
         public Version Version { get; set; }
         public Version Version { get; set; }
     }
     }
 }
 }

+ 4 - 1
MediaBrowser.Movies/MediaBrowser.Movies.csproj

@@ -29,6 +29,9 @@
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
+  <PropertyGroup>
+    <RunPostBuildEvent>Always</RunPostBuildEvent>
+  </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.Composition" />
@@ -66,7 +69,7 @@
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>
+    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\" /y</PostBuildEvent>
   </PropertyGroup>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.

+ 4 - 1
MediaBrowser.TV/MediaBrowser.TV.csproj

@@ -29,6 +29,9 @@
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
+  <PropertyGroup>
+    <RunPostBuildEvent>Always</RunPostBuildEvent>
+  </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.Composition" />
@@ -72,7 +75,7 @@
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>
+    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\" /y</PostBuildEvent>
   </PropertyGroup>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.

+ 1 - 1
MediaBrowser.TV/Plugin.cs

@@ -16,7 +16,7 @@ namespace MediaBrowser.TV
             get { return "TV"; }
             get { return "TV"; }
         }
         }
 
 
-        public override void Init()
+        protected override void InitializeInternal()
         {
         {
             Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
             Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
         }
         }

+ 4 - 1
MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj

@@ -29,6 +29,9 @@
     <ErrorReport>prompt</ErrorReport>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
+  <PropertyGroup>
+    <RunPostBuildEvent>Always</RunPostBuildEvent>
+  </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
     <Reference Include="System.ComponentModel.Composition" />
@@ -55,7 +58,7 @@
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\$(ProjectName)\" /y</PostBuildEvent>
+    <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData\Plugins\" /y</PostBuildEvent>
   </PropertyGroup>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
        Other similar extension points exist, see Microsoft.Common.targets.