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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 101 - (show annotations) (download)
Thu May 10 09:53:16 2012 UTC (8 years, 6 months ago) by william
File size: 3849 byte(s)

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using RomCheater.PluginFramework.Interfaces;
6 using System.Diagnostics;
7 using libWin32.Win32.Threading;
8 using RomCheater.Logging;
9 using System.IO;
10
11 namespace RomCheater.PluginFramework.Core
12 {
13 /// <summary>
14 /// Base class for all configuration plugins
15 /// </summary>
16 public abstract class ConfigPlugin : PluginBase, IConfigPlugin
17 {
18 public ConfigPlugin() : this(false) { }
19 public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); }
20
21 public override void Reload()
22 {
23 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
24 init();
25 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
26 }
27 private void init()
28 {
29 List<ProcContainer> proc_list = new List<ProcContainer>();
30 foreach (Process proc in Process.GetProcesses())
31 {
32 string proc_name = proc.ProcessName.ToLower();
33 try
34 {
35 bool isSystem = false;
36 string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
37 if (isSystem)
38 {
39 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
40 continue;
41 }
42 ProcContainer container = null;
43 try
44 {
45 container = new ProcContainer(proc);
46 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
47 proc_list.Add(container);
48 }
49 catch (FileNotFoundException) { }
50 catch (Exception ex)
51 {
52 //throw;
53 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
54 //continue;
55 }
56 }
57 catch (System.ComponentModel.Win32Exception ex)
58 {
59 if (!((uint)ex.ErrorCode == 0x80004005))
60 {
61 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
62 }
63 //continue;
64 }
65 catch (Exception ex)
66 {
67 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
68 //continue;
69 }
70 }
71 proc_list = proc_list.OrderBy(p => p.Name).ToList();
72 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
73 proc_list.RemoveAll(predicate);
74 ValidProcessesForPlugin = proc_list;
75 }
76
77 protected abstract bool IsNotValidProcess(ProcContainer p);
78
79 #region IConfigPlugin Members
80 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
81 public override Guid ID
82 {
83 get { return new Guid(); }
84 }
85 public override string Name
86 {
87 get
88 {
89 return "Unknown Config Plugin";
90 }
91 }
92 public override string Description
93 {
94 get
95 {
96 return "";
97 }
98 }
99 #endregion
100 }
101 }

  ViewVC Help
Powered by ViewVC 1.1.22