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

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

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

--- trunk/RomCheater.PluginFramework/Core/ConfigPlugin.cs	2012/05/09 17:48:15	83
+++ trunk/RomCheater.PluginFramework/Core/ConfigPlugin.cs	2012/05/09 23:23:38	99
@@ -4,6 +4,8 @@
 using System.Text;
 using RomCheater.PluginFramework.Interfaces;
 using System.Diagnostics;
+using libWin32.Win32.Threading;
+using RomCheater.Logging;
 
 namespace RomCheater.PluginFramework.Core
 {
@@ -12,8 +14,81 @@
     /// </summary>
     public abstract class ConfigPlugin : PluginBase, IConfigPlugin
     {
+        public ConfigPlugin() : this(false) { }
+        public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); }
+
+        public override void Reload()
+        {
+            logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
+            init();
+            logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
+        }
+        private void init()
+        {
+            List<ProcContainer> proc_list = new List<ProcContainer>();
+            foreach (Process proc in Process.GetProcesses())
+            {
+                try
+                {
+                    bool isSystem = false;
+                    string proc_name = proc.ProcessName.ToLower();
+                    string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
+                    if (isSystem)
+                    {
+                        logger.VerboseDebug.WriteLine("    not adding process {0} because it is a system process", proc_name);
+                        continue;
+                    }
+                    ProcContainer container = null;
+                    try
+                    {                       
+                        container = new ProcContainer(proc);
+                        logger.VerboseDebug.WriteLine("  adding process {0} ", proc_name);
+                    }
+                    catch (Exception ex)
+                    {
+                        //throw;
+                        logger.VerboseDebug.WriteLine("    not adding process {0} because it thew an exception [{1}]", proc_name, ex.Message);
+                        continue;
+                    }
+                    proc_list.Add(container);
+                }
+                catch (System.ComponentModel.Win32Exception)
+                {
+                    continue;
+                }
+                catch (Exception)
+                {
+                    continue;
+                }
+            }
+            proc_list = proc_list.OrderBy(p => p.Name).ToList();
+            Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
+            proc_list.RemoveAll(predicate);
+            ValidProcessesForPlugin = proc_list;
+        }
+
+        protected abstract bool IsNotValidProcess(ProcContainer p);
+
         #region IConfigPlugin Members
-        public List<Process> ValidProcessesForPlugin { get; protected set; }
+        public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
+        public override Guid ID
+        {
+            get { return new Guid(); }
+        }
+        public override string Name
+        {
+            get
+            {
+                return "Unknown Config Plugin";
+            }
+        }
+        public override string Description
+        {
+            get
+            {
+                return "";
+            }
+        }
         #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22