/[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 686 - (show annotations) (download)
Mon Jun 17 09:31:52 2013 UTC (8 years, 1 month ago) by william
File size: 7153 byte(s)
+ massive move of source files

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

  ViewVC Help
Powered by ViewVC 1.1.22