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