1 |
william |
79 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Linq; |
4 |
|
|
using System.Text; |
5 |
william |
83 |
using RomCheater.PluginFramework.Interfaces; |
6 |
|
|
using System.Diagnostics; |
7 |
william |
88 |
using libWin32.Win32.Threading; |
8 |
william |
98 |
using RomCheater.Logging; |
9 |
william |
79 |
|
10 |
|
|
namespace RomCheater.PluginFramework.Core |
11 |
|
|
{ |
12 |
|
|
/// <summary> |
13 |
|
|
/// Base class for all configuration plugins |
14 |
|
|
/// </summary> |
15 |
william |
83 |
public abstract class ConfigPlugin : PluginBase, IConfigPlugin |
16 |
william |
79 |
{ |
17 |
william |
92 |
public ConfigPlugin() : this(false) { } |
18 |
|
|
public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); } |
19 |
william |
88 |
|
20 |
william |
92 |
public override void Reload() |
21 |
|
|
{ |
22 |
william |
98 |
logger.Debug.WriteLine(" Loading config for {0}...", this.ToString()); |
23 |
william |
92 |
init(); |
24 |
william |
98 |
logger.Debug.WriteLine(" Loaded config for {0}.", this.ToString()); |
25 |
william |
92 |
} |
26 |
william |
88 |
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 |
william |
98 |
logger.Debug.WriteLine(" not adding process {0} because it is a system process", proc_name); |
39 |
william |
88 |
continue; |
40 |
|
|
} |
41 |
|
|
ProcContainer container = null; |
42 |
|
|
try |
43 |
william |
98 |
{ |
44 |
william |
88 |
container = new ProcContainer(proc); |
45 |
william |
98 |
logger.Debug.WriteLine(" adding process {0} ", proc_name); |
46 |
william |
88 |
} |
47 |
william |
98 |
catch (Exception ex) |
48 |
william |
88 |
{ |
49 |
william |
98 |
//throw; |
50 |
|
|
logger.Debug.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.Message); |
51 |
|
|
continue; |
52 |
william |
88 |
} |
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 |
william |
83 |
#region IConfigPlugin Members |
73 |
william |
88 |
public List<ProcContainer> ValidProcessesForPlugin { get; protected set; } |
74 |
william |
94 |
public override Guid ID |
75 |
william |
86 |
{ |
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 |
william |
83 |
#endregion |
93 |
william |
79 |
} |
94 |
|
|
} |