/[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 696 - (show annotations) (download)
Mon Jun 17 11:47:23 2013 UTC (8 years, 4 months ago) by william
File size: 7473 byte(s)

1 #region Logging Defines
2 // include this any class or method that required logging, and comment-out what is not needed
3
4 #region Enabled logging levels
5 #define LOGGING_ENABLE_INFO
6 #define LOGGING_ENABLE_WARN
7 #define LOGGING_ENABLE_DEBUG
8 //#define LOGGING_ENABLE_VERBOSEDEBUG
9 #define LOGGING_ENABLE_ERROR
10 //#define LOGGING_ENABLE_VERBOSEERROR
11 #define LOGGING_ENABLE_PROFILER
12 #endregion
13 #endregion
14 //#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up
15 //#define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons
16 #define ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED // when defined system processes will be included in process list
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using System.Diagnostics;
22 using libWin32.Win32.Threading;
23 using RomCheater.Logging;
24 using System.IO;
25 using RomCheater.Core;
26
27 namespace RomCheater.PluginFramework.Core
28 {
29 /// <summary>
30 /// Base class for all configuration plugins
31 /// </summary>
32 public abstract class ConfigPlugin : PluginBase, IConfigPlugin, IAcceptsReadOnlyMemoryRange
33 {
34 public ConfigPlugin() : this(false) { }
35 public ConfigPlugin(bool doinit) : base() { SetupConfig(); if (doinit) init(); }
36
37 private IWebBrowserProvider _WebBrowserProvider;
38 public IWebBrowserProvider WebBrowserProvider
39 {
40 get
41 {
42 return _WebBrowserProvider;
43 }
44 set
45 {
46 _WebBrowserProvider = value;
47 }
48 }
49 public override bool IsGenericPlugin { get { return false; } }
50 public override bool IsNullPlugin { get { return false; } }
51
52 private void SetupConfig()
53 {
54 this.ValidProcessesForPlugin = new List<ProcContainer>();
55 MemoryRangeStart = 0;
56 MemoryRangeSize = int.MaxValue;
57 }
58
59 public override void Reload(bool silent)
60 {
61 if (!silent)
62 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
63 init(silent);
64 if (!silent)
65 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
66 }
67 private void init() { init(false); }
68 private void init(bool silent)
69 {
70 // loggerflags flags = logger.GetLoggingFlags();
71
72 //#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST
73 // ushort performance_flags = flags.Value;
74 // if (flags.HasFlag(loggerflags.VERBOSE_DEBUG))
75 // {
76 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value);
77 // }
78 // if (flags.HasFlag(loggerflags.VERBOSE_ERROR))
79 // {
80 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value);
81 // }
82 //#endif
83 // logger.SetLoggingFlags(performance_flags);
84
85 List<ProcContainer> proc_list = new List<ProcContainer>();
86 foreach (Process proc in Process.GetProcesses())
87 {
88 string proc_name = proc.ProcessName.ToLower();
89 try
90 {
91 bool isSystem = false;
92 string proc_user = libWin32.Win32.Threading.ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
93 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
94 if (isSystem)
95 {
96 #if !DISALLOW_VERBOSE_LOGGING
97 if(!silent)
98 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
99 #endif
100 continue;
101 }
102 #endif
103 ProcContainer container = null;
104 try
105 {
106 container = new ProcContainer(proc);
107 #if !DISALLOW_VERBOSE_LOGGING
108 if(!silent)
109 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
110 #endif
111 proc_list.Add(container);
112 }
113 catch (FileNotFoundException) { }
114 #if !DISALLOW_VERBOSE_LOGGING
115 catch (Exception ex)
116 {
117 //throw;
118 if(!silent)
119 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
120 //continue;
121 }
122 #else
123 catch (Exception) { }
124 #endif
125 }
126 catch (System.ComponentModel.Win32Exception ex)
127 {
128 if (!((uint)ex.ErrorCode == 0x80004005))
129 {
130 #if !DISALLOW_VERBOSE_LOGGING
131 if(!silent)
132 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
133 #endif
134 }
135 //continue;
136 }
137 #if !DISALLOW_VERBOSE_LOGGING
138 catch (Exception ex)
139 {
140 if(!silent)
141 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
142 //continue;
143 }
144 #else
145 catch (Exception) { }
146 #endif
147 }
148 proc_list = proc_list.OrderBy(p => p.Name).ToList();
149 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
150 proc_list.RemoveAll(predicate);
151 ValidProcessesForPlugin = proc_list;
152 //logger.SetLoggingFlags(flags); // reset flags
153 }
154
155 protected abstract bool IsNotValidProcess(ProcContainer p);
156
157 #region IConfigPlugin Members
158 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
159 public override Guid ID
160 {
161 get { return new Guid(); }
162 }
163 public override string Name
164 {
165 get
166 {
167 return "Unknown Config Plugin";
168 }
169 }
170 public override string Description
171 {
172 get
173 {
174 return "";
175 }
176 }
177 #endregion
178 #region IAcceptsReadOnlyMemoryRange members
179 public virtual ulong MemoryRangeStart { get; protected set; }
180 public virtual ulong MemoryRangeSize { get; protected set; }
181 #endregion
182
183 #region ISearchInProgress members
184 private ISearchInProgress sip = null;
185 public bool SearchInProgess { get { return (sip == null) ? false : sip.SearchInProgess; } }
186 public Guid SearchGuid { get { return (sip == null) ? Guid.Empty : sip.SearchGuid; } }
187 #endregion
188
189 #region IAcceptsMemorySearch Members
190 public void SetMemorySearchReference(ISearchInProgress sip)
191 {
192 this.sip = sip;
193 }
194 #endregion
195 }
196 }

  ViewVC Help
Powered by ViewVC 1.1.22