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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 590 - (hide annotations) (download)
Thu Jun 6 10:08:17 2013 UTC (8 years, 1 month ago) by william
File size: 7071 byte(s)

1 william 414 #region Logging Defines
2     // include this any class or method that required logging, and comment-out what is not needed
3 william 415
4 william 414 #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 william 174 #define ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED // when defined system processes will be included in process list
17 william 150 using System;
18 william 79 using System.Collections.Generic;
19     using System.Linq;
20     using System.Text;
21 william 83 using RomCheater.PluginFramework.Interfaces;
22     using System.Diagnostics;
23 william 88 using libWin32.Win32.Threading;
24 william 98 using RomCheater.Logging;
25 william 101 using System.IO;
26 william 79
27     namespace RomCheater.PluginFramework.Core
28     {
29     /// <summary>
30     /// Base class for all configuration plugins
31     /// </summary>
32 william 389 public abstract class ConfigPlugin : PluginBase, IConfigPlugin, IAcceptsReadOnlyMemoryRange
33 william 79 {
34 william 92 public ConfigPlugin() : this(false) { }
35 william 389 public ConfigPlugin(bool doinit) : base() { SetupConfig(); if (doinit) init(); }
36 william 88
37 william 389 private void SetupConfig()
38     {
39     this.ValidProcessesForPlugin = new List<ProcContainer>();
40     MemoryRangeStart = 0;
41     MemoryRangeSize = int.MaxValue;
42     }
43    
44 william 329 public override void Reload(bool silent)
45 william 92 {
46 william 329 if (!silent)
47     logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
48 william 330 init(silent);
49 william 329 if (!silent)
50     logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
51 william 92 }
52 william 330 private void init() { init(false); }
53     private void init(bool silent)
54 william 88 {
55 william 329 // loggerflags flags = logger.GetLoggingFlags();
56 william 150
57 william 329 //#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 william 150
70 william 88 List<ProcContainer> proc_list = new List<ProcContainer>();
71     foreach (Process proc in Process.GetProcesses())
72     {
73 william 101 string proc_name = proc.ProcessName.ToLower();
74 william 88 try
75     {
76     bool isSystem = false;
77     string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
78 william 174 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
79 william 88 if (isSystem)
80     {
81 william 151 #if !DISALLOW_VERBOSE_LOGGING
82 william 330 if(!silent)
83 william 99 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
84 william 151 #endif
85 william 88 continue;
86     }
87 william 174 #endif
88 william 88 ProcContainer container = null;
89     try
90 william 101 {
91 william 88 container = new ProcContainer(proc);
92 william 329 #if !DISALLOW_VERBOSE_LOGGING
93 william 330 if(!silent)
94 william 99 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
95 william 151 #endif
96 william 101 proc_list.Add(container);
97 william 88 }
98 william 101 catch (FileNotFoundException) { }
99 william 329 #if !DISALLOW_VERBOSE_LOGGING
100 william 300 catch (Exception ex)
101 william 88 {
102 william 98 //throw;
103 william 330 if(!silent)
104 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
105     //continue;
106 william 88 }
107 william 329 #else
108     catch (Exception) { }
109     #endif
110 william 88 }
111 william 101 catch (System.ComponentModel.Win32Exception ex)
112 william 88 {
113 william 101 if (!((uint)ex.ErrorCode == 0x80004005))
114     {
115 william 329 #if !DISALLOW_VERBOSE_LOGGING
116 william 330 if(!silent)
117 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
118 william 151 #endif
119 william 329 }
120 william 101 //continue;
121 william 88 }
122 william 329 #if !DISALLOW_VERBOSE_LOGGING
123 william 300 catch (Exception ex)
124 william 88 {
125 william 330 if(!silent)
126 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
127     //continue;
128 william 88 }
129 william 329 #else
130     catch (Exception) { }
131     #endif
132 william 88 }
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 william 151 //logger.SetLoggingFlags(flags); // reset flags
138 william 88 }
139    
140     protected abstract bool IsNotValidProcess(ProcContainer p);
141    
142 william 83 #region IConfigPlugin Members
143 william 88 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
144 william 94 public override Guid ID
145 william 86 {
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 william 590 public virtual bool IsGenericConfig { get { return false; } }
163 william 83 #endregion
164 william 389 #region IAcceptsReadOnlyMemoryRange members
165 william 590 public virtual ulong MemoryRangeStart { get; protected set; }
166     public virtual ulong MemoryRangeSize { get; protected set; }
167 william 389 #endregion
168 william 399
169     #region ISearchInProgress members
170     private ISearchInProgress sip = null;
171     public bool SearchInProgess { get { return (sip == null) ? false : sip.SearchInProgess; } }
172 william 444 public Guid SearchGuid { get { return (sip == null) ? Guid.Empty : sip.SearchGuid; } }
173 william 399 #endregion
174    
175     #region IAcceptsMemorySearch Members
176     public void SetMemorySearchReference(ISearchInProgress sip)
177     {
178     this.sip = sip;
179     }
180     #endregion
181 william 79 }
182     }

  ViewVC Help
Powered by ViewVC 1.1.22