/[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 150 - (show annotations) (download)
Sun May 27 23:59:22 2012 UTC (9 years, 6 months ago) by william
File size: 4644 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22