/[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 415 - (show annotations) (download)
Fri Jun 22 08:33:51 2012 UTC (7 years, 7 months ago) by william
File size: 6902 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 RomCheater.PluginFramework.Interfaces;
22 using System.Diagnostics;
23 using libWin32.Win32.Threading;
24 using RomCheater.Logging;
25 using System.IO;
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 void SetupConfig()
38 {
39 this.ValidProcessesForPlugin = new List<ProcContainer>();
40 MemoryRangeStart = 0;
41 MemoryRangeSize = int.MaxValue;
42 }
43
44 public override void Reload(bool silent)
45 {
46 if (!silent)
47 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
48 init(silent);
49 if (!silent)
50 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
51 }
52 private void init() { init(false); }
53 private void init(bool silent)
54 {
55 // loggerflags flags = logger.GetLoggingFlags();
56
57 //#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST
58 // ushort performance_flags = flags.Value;
59 // if (flags.HasFlag(loggerflags.VERBOSE_DEBUG))
60 // {
61 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value);
62 // }
63 // if (flags.HasFlag(loggerflags.VERBOSE_ERROR))
64 // {
65 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value);
66 // }
67 //#endif
68 // logger.SetLoggingFlags(performance_flags);
69
70 List<ProcContainer> proc_list = new List<ProcContainer>();
71 foreach (Process proc in Process.GetProcesses())
72 {
73 string proc_name = proc.ProcessName.ToLower();
74 try
75 {
76 bool isSystem = false;
77 string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
78 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
79 if (isSystem)
80 {
81 #if !DISALLOW_VERBOSE_LOGGING
82 if(!silent)
83 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
84 #endif
85 continue;
86 }
87 #endif
88 ProcContainer container = null;
89 try
90 {
91 container = new ProcContainer(proc);
92 #if !DISALLOW_VERBOSE_LOGGING
93 if(!silent)
94 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
95 #endif
96 proc_list.Add(container);
97 }
98 catch (FileNotFoundException) { }
99 #if !DISALLOW_VERBOSE_LOGGING
100 catch (Exception ex)
101 {
102 //throw;
103 if(!silent)
104 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
105 //continue;
106 }
107 #else
108 catch (Exception) { }
109 #endif
110 }
111 catch (System.ComponentModel.Win32Exception ex)
112 {
113 if (!((uint)ex.ErrorCode == 0x80004005))
114 {
115 #if !DISALLOW_VERBOSE_LOGGING
116 if(!silent)
117 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
118 #endif
119 }
120 //continue;
121 }
122 #if !DISALLOW_VERBOSE_LOGGING
123 catch (Exception ex)
124 {
125 if(!silent)
126 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
127 //continue;
128 }
129 #else
130 catch (Exception) { }
131 #endif
132 }
133 proc_list = proc_list.OrderBy(p => p.Name).ToList();
134 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
135 proc_list.RemoveAll(predicate);
136 ValidProcessesForPlugin = proc_list;
137 //logger.SetLoggingFlags(flags); // reset flags
138 }
139
140 protected abstract bool IsNotValidProcess(ProcContainer p);
141
142 #region IConfigPlugin Members
143 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
144 public override Guid ID
145 {
146 get { return new Guid(); }
147 }
148 public override string Name
149 {
150 get
151 {
152 return "Unknown Config Plugin";
153 }
154 }
155 public override string Description
156 {
157 get
158 {
159 return "";
160 }
161 }
162 #endregion
163 #region IAcceptsReadOnlyMemoryRange members
164 public virtual uint MemoryRangeStart { get; protected set; }
165 public virtual uint MemoryRangeSize { get; protected set; }
166 #endregion
167
168 #region ISearchInProgress members
169 private ISearchInProgress sip = null;
170 public bool SearchInProgess { get { return (sip == null) ? false : sip.SearchInProgess; } }
171 #endregion
172
173 #region IAcceptsMemorySearch Members
174 public void SetMemorySearchReference(ISearchInProgress sip)
175 {
176 this.sip = sip;
177 }
178 #endregion
179 }
180 }

  ViewVC Help
Powered by ViewVC 1.1.22