/[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 98 - (show annotations) (download)
Wed May 9 23:10:12 2012 UTC (8 years, 9 months ago) by william
File size: 3346 byte(s)

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.Debug.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.Debug.WriteLine(" adding process {0} ", proc_name);
46 }
47 catch (Exception ex)
48 {
49 //throw;
50 logger.Debug.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 }

  ViewVC Help
Powered by ViewVC 1.1.22