/[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 172 - (hide annotations) (download)
Mon May 28 09:15:17 2012 UTC (9 years ago) by william
File size: 5067 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22