/[RomCheater]/trunk/RomCheater.PluginFramework/Core/PluginLoader.cs
ViewVC logotype

Diff of /trunk/RomCheater.PluginFramework/Core/PluginLoader.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.PluginFramework/Core/PluginLoader.cs	2012/06/22 08:33:51	415
+++ trunk/RomCheater.PluginFramework/Core/PluginLoader.cs	2013/05/28 18:08:23	437
@@ -29,6 +29,7 @@
             LoadedConfigPlugins = new List<IConfigPlugin>();
             LoadedInputPlugins = new List<IInputPlugin>();
             LoadedWindowPlugins = new List<IWindowPlugin>();
+            LoadedUserControlPlugins = new List<IUserControlPlugin>();
         }
         #region IPluginLoader Members
         public void LoadPlugins() { LoadPlugins(false); }
@@ -53,6 +54,7 @@
                     GetConfigPluginsFromDll(fi);
                     GetInputPluginsFromDll(fi);
                     GetWindowPluginsFromDll(fi);
+                    GetUserControlPluginsFromDll(fi);
                 }
 
                 if (!silent)
@@ -62,6 +64,8 @@
                 if (!silent)
                     logger.Info.WriteLine("  Loaded {0} window plugins", LoadedWindowPlugins.Count);
                 if (!silent)
+                    logger.Info.WriteLine("  Loaded {0} usercontrol plugins", LoadedUserControlPlugins.Count);
+                if (!silent)
                     logger.Info.WriteLine("Plugins Loaded.");
             }
             catch (ReflectionTypeLoadException ex)
@@ -86,6 +90,7 @@
         public List<IConfigPlugin> LoadedConfigPlugins { get; private set; }
         public List<IInputPlugin> LoadedInputPlugins { get; private set; }
         public List<IWindowPlugin> LoadedWindowPlugins { get; private set; }
+        public List<IUserControlPlugin> LoadedUserControlPlugins { get; private set; }
 
         public IConfigPlugin GetConfigPlugin(string t)
         {
@@ -117,6 +122,11 @@
             foreach (IWindowPlugin c in LoadedWindowPlugins) { }
             return null;
         }
+        private IUserControlPlugin GetUserControlPlugin()
+        {
+            foreach (IUserControlPlugin c in LoadedUserControlPlugins) { }
+            return null;
+        }
         #endregion
 
         private void GetConfigPluginsFromDll(FileInfo dll)
@@ -213,6 +223,38 @@
                         }
                     }
                 }
+            }
+        }
+        private void GetUserControlPluginsFromDll(FileInfo dll)
+        {
+            logger.Debug.WriteLine("  Getting UserControl plugins contained in {0}", dll.Name);
+            Assembly asm = Assembly.LoadFile(dll.FullName);
+            List<Type> types = new List<Type>(asm.GetTypes());
+            foreach (Type type in types)
+            {
+                if (type.BaseType == typeof(UserControlPlugin))
+                {
+                    ConstructorInfo ci = null;
+                    ci = type.GetConstructor(new Type[] { });
+                    if (ci == null)
+                    {
+                        throw new NullReferenceException(string.Format("Unable to bind to constructor for type: {0}", type.Name));
+                    }
+                    else
+                    {
+                        object o = ci.Invoke(new object[] { });
+                        IUserControlPlugin c = (IUserControlPlugin)o;
+                        if (c == null)
+                        {
+                            throw new NullReferenceException(string.Format("Failed to cast type {0} to IConfigPlugin", type.Name));
+                        }
+                        else
+                        {
+                            logger.Debug.WriteLine("    Loaded UserControl Plugin [name={0}] from {1}", c.Name, dll.Name);
+                            LoadedUserControlPlugins.Add(c);
+                        }
+                    }
+                }
             }
         }
     }

 

  ViewVC Help
Powered by ViewVC 1.1.22