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

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

  ViewVC Help
Powered by ViewVC 1.1.22