/[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/05/09 18:13:51	85
+++ trunk/RomCheater.PluginFramework/Core/PluginLoader.cs	2012/06/22 08:33:51	415
@@ -1,4 +1,17 @@
-´╗┐using System;
+´╗┐#region Logging Defines
+// include this any class or method that required logging, and comment-out what is not needed
+
+#region Enabled logging levels
+#define LOGGING_ENABLE_INFO
+#define LOGGING_ENABLE_WARN
+#define LOGGING_ENABLE_DEBUG
+#define LOGGING_ENABLE_VERBOSEDEBUG
+#define LOGGING_ENABLE_ERROR
+#define LOGGING_ENABLE_VERBOSEERROR
+#define LOGGING_ENABLE_PROFILER
+#endregion
+#endregion
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -18,40 +31,92 @@
             LoadedWindowPlugins = new List<IWindowPlugin>();
         }
         #region IPluginLoader Members
-
-        public void LoadPlugins()
+        public void LoadPlugins() { LoadPlugins(false); }
+        public void LoadPlugins(bool silent)
         {
             try
             {
-                logger.Info.WriteLine("Loading Plugins...");
+                if (!silent)
+                    logger.Info.WriteLine("Loading Plugins...");
 
                 string PluginPath = string.Format(@"{0}\Plugins", typeof(PluginLoader).Assembly.Location.Replace(@"\RomCheater.PluginFramework.dll", ""));
-                logger.Debug.WriteLine("Plugins Path: {0}", PluginPath);
+                if (!silent)
+                    logger.Debug.WriteLine("Plugins Path: {0}", PluginPath);
                 List<string> dlls = new List<string>(Directory.GetFiles(PluginPath, "*.dll"));
-                logger.Debug.WriteLine("  Found: {0} plugin dlls", dlls.Count);
+                if (!silent)
+                    logger.Debug.WriteLine("  Found: {0} plugin dlls", dlls.Count);
                 foreach (string dll in dlls)
                 {
                     FileInfo fi = new FileInfo(dll);
-                    logger.Debug.WriteLine("    plugin[{0}]: {1}", dlls.IndexOf(dll), fi.Name);
+                    if (!silent)
+                        logger.Debug.WriteLine("    plugin[{0}]: {1}", dlls.IndexOf(dll), fi.Name);
                     GetConfigPluginsFromDll(fi);
                     GetInputPluginsFromDll(fi);
                     GetWindowPluginsFromDll(fi);
                 }
 
-                logger.Info.WriteLine("  Loaded {0} config plugins", LoadedConfigPlugins.Count);
-                logger.Info.WriteLine("  Loaded {0} input plugins", LoadedInputPlugins.Count);
-                logger.Info.WriteLine("  Loaded {0} window plugins", LoadedWindowPlugins.Count);
-
-                logger.Info.WriteLine("Plugins Loaded.");
+                if (!silent)
+                    logger.Info.WriteLine("  Loaded {0} config plugins", LoadedConfigPlugins.Count);
+                if (!silent)
+                    logger.Info.WriteLine("  Loaded {0} input plugins", LoadedInputPlugins.Count);
+                if (!silent)
+                    logger.Info.WriteLine("  Loaded {0} window plugins", LoadedWindowPlugins.Count);
+                if (!silent)
+                    logger.Info.WriteLine("Plugins Loaded.");
+            }
+            catch (ReflectionTypeLoadException ex)
+            {
+                StringBuilder builder = new StringBuilder();
+                if (ex.LoaderExceptions.Count() > 0)
+                {
+                    foreach (Exception c in ex.LoaderExceptions)
+                    {
+                        builder.AppendLine(c.ToString());
+                    }
+                }
+                if (!silent)
+                    logger.Error.WriteLine("Failed to load one or more plugins{0}Possible Reason:{0}{1}", System.Environment.NewLine, builder.ToString());
             }
             catch (Exception ex)
             {
-                logger.Error.WriteLine("Failed to load one or more plugins{0}Possible Reason:{0}{1}", System.Environment.NewLine, ex.ToString());
+                if (!silent)
+                    logger.Error.WriteLine("Failed to load one or more plugins{0}Possible Reason:{0}{1}", System.Environment.NewLine, ex.ToString());
             }
         }
         public List<IConfigPlugin> LoadedConfigPlugins { get; private set; }
         public List<IInputPlugin> LoadedInputPlugins { get; private set; }
         public List<IWindowPlugin> LoadedWindowPlugins { get; private set; }
+
+        public IConfigPlugin GetConfigPlugin(string t)
+        {
+            foreach (IConfigPlugin c in LoadedConfigPlugins) { if (c.ToString().ToLower() == t.ToLower()) { return c; } }
+            return GetGenericConfigPlugin();
+        }
+        private IConfigPlugin GetGenericConfigPlugin()
+        {
+            foreach (IConfigPlugin c in LoadedConfigPlugins) { if (c.ID.ToString().ToLower() == "478e225b-c3e8-9280-57ca-384b884fc4cc".ToLower()) { return c; } }
+            return null;
+        }
+        public IInputPlugin GetInputPlugin(string t)
+        {
+            foreach (IInputPlugin c in LoadedInputPlugins) { if (c.ToString().ToLower() == t.ToLower()) { return c; } }
+            return GetGenericInputPlugin();
+        }
+        private IInputPlugin GetGenericInputPlugin()
+        {
+            foreach (IInputPlugin c in LoadedInputPlugins) { }
+            return null;
+        }
+        public IWindowPlugin GetWindowPlugin(string t)
+        {
+            foreach (IWindowPlugin c in LoadedWindowPlugins) { if (c.ToString().ToLower() == t.ToLower()) { return c; } }
+            return GetGenericWindowPlugin();
+        }
+        private IWindowPlugin GetGenericWindowPlugin()
+        {
+            foreach (IWindowPlugin c in LoadedWindowPlugins) { }
+            return null;
+        }
         #endregion
 
         private void GetConfigPluginsFromDll(FileInfo dll)
@@ -64,7 +129,7 @@
                 if (type.BaseType == typeof(ConfigPlugin))
                 {
                     ConstructorInfo ci = null;
-                    ci = type.GetConstructor(new Type[] {});
+                    ci = type.GetConstructor(new Type[] { });
                     if (ci == null)
                     {
                         throw new NullReferenceException(string.Format("Unable to bind to constructor for type: {0}", type.Name));

 

  ViewVC Help
Powered by ViewVC 1.1.22