ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.PluginFramework/Core/ConfigPlugin.cs
Revision: 177
Committed: Mon May 28 09:37:16 2012 UTC (11 years, 6 months ago) by william
File size: 5224 byte(s)
Log Message:

File Contents

# Content
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()
25 {
26 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
27 init();
28 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
29 }
30 private void init()
31 {
32 // loggerflags flags = logger.GetLoggingFlags();
33
34 //#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST
35 // ushort performance_flags = flags.Value;
36 // if (flags.HasFlag(loggerflags.VERBOSE_DEBUG))
37 // {
38 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value);
39 // }
40 // if (flags.HasFlag(loggerflags.VERBOSE_ERROR))
41 // {
42 // performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value);
43 // }
44 //#endif
45 // logger.SetLoggingFlags(performance_flags);
46
47 List<ProcContainer> proc_list = new List<ProcContainer>();
48 foreach (Process proc in Process.GetProcesses())
49 {
50 string proc_name = proc.ProcessName.ToLower();
51 try
52 {
53 bool isSystem = false;
54 string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
55 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
56 if (isSystem)
57 {
58 #if !DISALLOW_VERBOSE_LOGGING
59 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
60 #endif
61 continue;
62 }
63 #endif
64 ProcContainer container = null;
65 try
66 {
67 container = new ProcContainer(proc);
68 #if !DISALLOW_VERBOSE_LOGGING
69 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
70 #endif
71 proc_list.Add(container);
72 }
73 catch (FileNotFoundException) { }
74 catch (Exception)
75 {
76 //throw;
77 #if !DISALLOW_VERBOSE_LOGGING
78 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
79 #endif
80 //continue;
81 }
82 }
83 catch (System.ComponentModel.Win32Exception ex)
84 {
85 if (!((uint)ex.ErrorCode == 0x80004005))
86 {
87 #if !DISALLOW_VERBOSE_LOGGING
88 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
89 #endif
90 }
91 //continue;
92 }
93 catch (Exception)
94 {
95 #if !DISALLOW_VERBOSE_LOGGING
96 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
97 #endif
98 //continue;
99 }
100 }
101 proc_list = proc_list.OrderBy(p => p.Name).ToList();
102 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
103 proc_list.RemoveAll(predicate);
104 ValidProcessesForPlugin = proc_list;
105 //logger.SetLoggingFlags(flags); // reset flags
106 }
107
108 protected abstract bool IsNotValidProcess(ProcContainer p);
109
110 #region IConfigPlugin Members
111 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
112 public override Guid ID
113 {
114 get { return new Guid(); }
115 }
116 public override string Name
117 {
118 get
119 {
120 return "Unknown Config Plugin";
121 }
122 }
123 public override string Description
124 {
125 get
126 {
127 return "";
128 }
129 }
130 #endregion
131 }
132 }