/[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 812 - (show annotations) (download)
Tue Apr 15 14:52:10 2014 UTC (5 years, 9 months ago) by william
File size: 7504 byte(s)
+ update logging to use Enterpise.Logging -- more work is still needed

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

  ViewVC Help
Powered by ViewVC 1.1.22