ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.PluginFramework/Core/ConfigPlugin.cs
Revision: 99
Committed: Wed May 9 23:23:38 2012 UTC (11 years ago) by william
File size: 3367 byte(s)
Log Message:
+ add logging options:
* VERBOSE_DEBUG and VERBOSE_ERROR : for debug and error messages that are very 'chatty'

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using RomCheater.PluginFramework.Interfaces;
6 using System.Diagnostics;
7 using libWin32.Win32.Threading;
8 using RomCheater.Logging;
9
10 namespace RomCheater.PluginFramework.Core
11 {
12 /// <summary>
13 /// Base class for all configuration plugins
14 /// </summary>
15 public abstract class ConfigPlugin : PluginBase, IConfigPlugin
16 {
17 public ConfigPlugin() : this(false) { }
18 public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); }
19
20 public override void Reload()
21 {
22 logger.Debug.WriteLine(" Loading config for {0}...", this.ToString());
23 init();
24 logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString());
25 }
26 private void init()
27 {
28 List<ProcContainer> proc_list = new List<ProcContainer>();
29 foreach (Process proc in Process.GetProcesses())
30 {
31 try
32 {
33 bool isSystem = false;
34 string proc_name = proc.ProcessName.ToLower();
35 string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower();
36 if (isSystem)
37 {
38 logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name);
39 continue;
40 }
41 ProcContainer container = null;
42 try
43 {
44 container = new ProcContainer(proc);
45 logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name);
46 }
47 catch (Exception ex)
48 {
49 //throw;
50 logger.VerboseDebug.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.Message);
51 continue;
52 }
53 proc_list.Add(container);
54 }
55 catch (System.ComponentModel.Win32Exception)
56 {
57 continue;
58 }
59 catch (Exception)
60 {
61 continue;
62 }
63 }
64 proc_list = proc_list.OrderBy(p => p.Name).ToList();
65 Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess);
66 proc_list.RemoveAll(predicate);
67 ValidProcessesForPlugin = proc_list;
68 }
69
70 protected abstract bool IsNotValidProcess(ProcContainer p);
71
72 #region IConfigPlugin Members
73 public List<ProcContainer> ValidProcessesForPlugin { get; protected set; }
74 public override Guid ID
75 {
76 get { return new Guid(); }
77 }
78 public override string Name
79 {
80 get
81 {
82 return "Unknown Config Plugin";
83 }
84 }
85 public override string Description
86 {
87 get
88 {
89 return "";
90 }
91 }
92 #endregion
93 }
94 }