/[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 177 - (hide annotations) (download)
Mon May 28 09:37:16 2012 UTC (8 years, 5 months ago) by william
File size: 5224 byte(s)

1 william 151 //#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up
2 william 175 #define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons
3 william 174 #define ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED // when defined system processes will be included in process list
4 william 150 using System;
5 william 79 using System.Collections.Generic;
6     using System.Linq;
7     using System.Text;
8 william 83 using RomCheater.PluginFramework.Interfaces;
9     using System.Diagnostics;
10 william 88 using libWin32.Win32.Threading;
11 william 98 using RomCheater.Logging;
12 william 101 using System.IO;
13 william 79
14     namespace RomCheater.PluginFramework.Core
15     {
16     /// <summary>
17     /// Base class for all configuration plugins
18     /// </summary>
19 william 83 public abstract class ConfigPlugin : PluginBase, IConfigPlugin
20 william 79 {
21 william 92 public ConfigPlugin() : this(false) { }
22     public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); }
23 william 88
24 william 92 public override void Reload()
25     {
26 william 98 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
27 william 92 init();
28 william 98 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
29 william 92 }
30 william 88 private void init()
31     {
32 william 151 // loggerflags flags = logger.GetLoggingFlags();
33 william 150
34 william 151 //#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 william 150
47 william 88 List<ProcContainer> proc_list = new List<ProcContainer>();
48     foreach (Process proc in Process.GetProcesses())
49     {
50 william 101 string proc_name = proc.ProcessName.ToLower();
51 william 88 try
52     {
53     bool isSystem = false;
54     string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
55 william 174 #if !ALLOW_SYSTEM_PROCESSES_TO_BE_INLUCDED
56 william 88 if (isSystem)
57     {
58 william 151 #if !DISALLOW_VERBOSE_LOGGING
59 william 99 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
60 william 151 #endif
61 william 88 continue;
62     }
63 william 174 #endif
64 william 88 ProcContainer container = null;
65     try
66 william 101 {
67 william 88 container = new ProcContainer(proc);
68 william 151 #if !DISALLOW_VERBOSE_LOGGING
69 william 99 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
70 william 151 #endif
71 william 101 proc_list.Add(container);
72 william 88 }
73 william 101 catch (FileNotFoundException) { }
74 william 177 catch (Exception)
75 william 88 {
76 william 98 //throw;
77 william 151 #if !DISALLOW_VERBOSE_LOGGING
78 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
79 william 151 #endif
80 william 101 //continue;
81 william 88 }
82     }
83 william 101 catch (System.ComponentModel.Win32Exception ex)
84 william 88 {
85 william 101 if (!((uint)ex.ErrorCode == 0x80004005))
86     {
87 william 151 #if !DISALLOW_VERBOSE_LOGGING
88 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
89 william 151 #endif
90 william 101 }
91     //continue;
92 william 88 }
93 william 177 catch (Exception)
94 william 88 {
95 william 151 #if !DISALLOW_VERBOSE_LOGGING
96 william 101 logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString());
97 william 151 #endif
98 william 101 //continue;
99 william 88 }
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 william 151 //logger.SetLoggingFlags(flags); // reset flags
106 william 88 }
107    
108     protected abstract bool IsNotValidProcess(ProcContainer p);
109    
110 william 83 #region IConfigPlugin Members
111 william 88 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
112 william 94 public override Guid ID
113 william 86 {
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 william 83 #endregion
131 william 79 }
132     }

  ViewVC Help
Powered by ViewVC 1.1.22