/[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 329 - (show annotations) (download)
Thu Jun 7 19:18:31 2012 UTC (8 years, 3 months ago) by william
File size: 5443 byte(s)
+ add more logic for auto process refresh

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

  ViewVC Help
Powered by ViewVC 1.1.22