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 |
|
9 |
namespace RomCheater.PluginFramework.Core |
10 |
{ |
11 |
/// <summary> |
12 |
/// Base class for all configuration plugins |
13 |
/// </summary> |
14 |
public abstract class ConfigPlugin : PluginBase, IConfigPlugin |
15 |
{ |
16 |
public ConfigPlugin() : this(false) { } |
17 |
public ConfigPlugin(bool doinit) : base() { this.ValidProcessesForPlugin = new List<ProcContainer>(); if(doinit) init(); } |
18 |
|
19 |
public override void Reload() |
20 |
{ |
21 |
init(); |
22 |
} |
23 |
private void init() |
24 |
{ |
25 |
List<ProcContainer> proc_list = new List<ProcContainer>(); |
26 |
foreach (Process proc in Process.GetProcesses()) |
27 |
{ |
28 |
try |
29 |
{ |
30 |
bool isSystem = false; |
31 |
string proc_name = proc.ProcessName.ToLower(); |
32 |
string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower(); |
33 |
if (isSystem) |
34 |
{ |
35 |
continue; |
36 |
} |
37 |
ProcContainer container = null; |
38 |
try |
39 |
{ |
40 |
container = new ProcContainer(proc); |
41 |
} |
42 |
catch (Exception) |
43 |
{ |
44 |
throw; |
45 |
} |
46 |
proc_list.Add(container); |
47 |
} |
48 |
catch (System.ComponentModel.Win32Exception) |
49 |
{ |
50 |
continue; |
51 |
} |
52 |
catch (Exception) |
53 |
{ |
54 |
continue; |
55 |
} |
56 |
} |
57 |
proc_list = proc_list.OrderBy(p => p.Name).ToList(); |
58 |
Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess); |
59 |
proc_list.RemoveAll(predicate); |
60 |
ValidProcessesForPlugin = proc_list; |
61 |
} |
62 |
|
63 |
protected abstract bool IsNotValidProcess(ProcContainer p); |
64 |
|
65 |
#region IConfigPlugin Members |
66 |
public List<ProcContainer> ValidProcessesForPlugin { get; protected set; } |
67 |
public override Guid ID |
68 |
{ |
69 |
get { return new Guid(); } |
70 |
} |
71 |
public override string Name |
72 |
{ |
73 |
get |
74 |
{ |
75 |
return "Unknown Config Plugin"; |
76 |
} |
77 |
} |
78 |
public override string Description |
79 |
{ |
80 |
get |
81 |
{ |
82 |
return ""; |
83 |
} |
84 |
} |
85 |
#endregion |
86 |
} |
87 |
} |