/[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 330 - (show annotations) (download)
Thu Jun 7 19:20:44 2012 UTC (9 years, 6 months ago) by william
File size: 5683 byte(s)
+ add init(bool silent)

1 //#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up
2 #define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons
3 #define ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED // when defined system processes will be included in process list
4 using System;
5 using System.Collections.Generic;
6 using System.Linq;
7 using System.Text;
8 using RomCheater.PluginFramework.Interfaces;
9 using System.Diagnostics;
10 using libWin32.Win32.Threading;
11 using RomCheater.Logging;
12 using System.IO;
13
14 namespace RomCheater.PluginFramework.Core
15 {
16 /// <summary>
17 /// Base class for all configuration plugins
18 /// </summary>
19 public abstract class ConfigPlugin : PluginBase, IConfigPlugin
20 {
21 public ConfigPlugin() : this(false) { }
22 public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if (doinit) init(); }
23
24 public override void Reload(bool silent)
25 {
26 if (!silent)
27 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
28 init(silent);
29 if (!silent)
30 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
31 }
32 private void init() { init(false); }
33 private void init(bool silent)
34 {
35 // loggerflags flags = logger.GetLoggingFlags();
36
37 //#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST
38 // ushort performance_flags = flags.Value;
39 // if (flags.HasFlag(loggerflags.VERBOSE_DEBUG))
40 // {
41 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value);
42 // }
43 // if (flags.HasFlag(loggerflags.VERBOSE_ERROR))
44 // {
45 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value);
46 // }
47 //#endif
48 // logger.SetLoggingFlags(performance_flags);
49
50 List<ProcContainer> proc_list = new List<ProcContainer>();
51 foreach (Process proc in Process.GetProcesses())
52 {
53 string proc_name = proc.ProcessName.ToLower();
54 try
55 {
56 bool isSystem = false;
57 string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
58 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
59 if (isSystem)
60 {
61 #if !DISALLOW_VERBOSE_LOGGING
62 if(!silent)
63 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
64 #endif
65 continue;
66 }
67 #endif
68 ProcContainer container = null;
69 try
70 {
71 container = new ProcContainer(proc);
72 #if !DISALLOW_VERBOSE_LOGGING
73 if(!silent)
74 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
75 #endif
76 proc_list.Add(container);
77 }
78 catch (FileNotFoundException) { }
79 #if !DISALLOW_VERBOSE_LOGGING
80 catch (Exception ex)
81 {
82 //throw;
83 if(!silent)
84 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
85 //continue;
86 }
87 #else
88 catch (Exception) { }
89 #endif
90 }
91 catch (System.ComponentModel.Win32Exception ex)
92 {
93 if (!((uint)ex.ErrorCode == 0x80004005))
94 {
95 #if !DISALLOW_VERBOSE_LOGGING
96 if(!silent)
97 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
98 #endif
99 }
100 //continue;
101 }
102 #if !DISALLOW_VERBOSE_LOGGING
103 catch (Exception ex)
104 {
105 if(!silent)
106 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
107 //continue;
108 }
109 #else
110 catch (Exception) { }
111 #endif
112 }
113 proc_list = proc_list.OrderBy(p => p.Name).ToList();
114 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
115 proc_list.RemoveAll(predicate);
116 ValidProcessesForPlugin = proc_list;
117 //logger.SetLoggingFlags(flags); // reset flags
118 }
119
120 protected abstract bool IsNotValidProcess(ProcContainer p);
121
122 #region IConfigPlugin Members
123 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
124 public override Guid ID
125 {
126 get { return new Guid(); }
127 }
128 public override string Name
129 {
130 get
131 {
132 return "Unknown Config Plugin";
133 }
134 }
135 public override string Description
136 {
137 get
138 {
139 return "";
140 }
141 }
142 #endregion
143 }
144 }

  ViewVC Help
Powered by ViewVC 1.1.22