-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginServices.cs
134 lines (101 loc) · 3.28 KB
/
PluginServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.IO;
using System.Reflection;
using PluginInterface;
namespace Horus {
public class PluginServices : IPluginHost {
public PluginServices() {
}
private AvailablePlugins colAvailablePlugins = new AvailablePlugins();
public AvailablePlugins AvailablePlugins {
get { return colAvailablePlugins; }
set { colAvailablePlugins = value; }
}
public void FindPlugins() {
FindPlugins(AppDomain.CurrentDomain.BaseDirectory);
}
public void FindPlugins(string Path) {
if (!Directory.Exists(Path)) {
Directory.CreateDirectory(Path);
}
colAvailablePlugins.Clear();
foreach (string fileOn in Directory.GetFiles(Path)) {
FileInfo file = new FileInfo(fileOn);
if (file.Extension.Equals(".dll")) {
this.AddPlugin(fileOn);
}
}
}
public void ClosePlugins() {
foreach (AvailablePlugin pluginOn in colAvailablePlugins) {
pluginOn.Instance.Dispose();
pluginOn.Instance = null;
}
colAvailablePlugins.Clear();
}
private void AddPlugin(string FileName) {
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
foreach (Type pluginType in pluginAssembly.GetTypes()) {
if (pluginType.IsPublic) {
if (!pluginType.IsAbstract) {
Type typeInterface = pluginType.GetInterface("PluginInterface.IPlugin", true);
if (typeInterface != null) {
AvailablePlugin newPlugin = new AvailablePlugin();
newPlugin.AssemblyPath = FileName;
newPlugin.Instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
newPlugin.Instance.Host = this;
newPlugin.Instance.Initialize();
this.colAvailablePlugins.Add(newPlugin);
newPlugin = null;
}
typeInterface = null;
}
}
}
pluginAssembly = null;
}
public void Feedback(string Feedback, IPlugin Plugin) {
System.Windows.Forms.Form newForm = null;
frmFeedback newFeedbackForm = new frmFeedback();
newFeedbackForm.PluginAuthor = "By: " + Plugin.Author;
newFeedbackForm.PluginDesc = Plugin.Description;
newFeedbackForm.PluginName = Plugin.Name;
newFeedbackForm.PluginVersion = Plugin.Version;
newFeedbackForm.Feedback = Feedback;
newForm = newFeedbackForm;
newForm.ShowDialog();
newFeedbackForm = null;
newForm = null;
}
}
public class AvailablePlugins : System.Collections.CollectionBase {
public void Add(AvailablePlugin pluginToAdd) {
this.List.Add(pluginToAdd);
}
public void Remove(AvailablePlugin pluginToRemove) {
this.List.Remove(pluginToRemove);
}
public AvailablePlugin Find(string pluginNameOrPath) {
AvailablePlugin toReturn = null;
foreach (AvailablePlugin pluginOn in this.List) {
if ((pluginOn.Instance.Name.Equals(pluginNameOrPath)) || pluginOn.AssemblyPath.Equals(pluginNameOrPath)) {
toReturn = pluginOn;
break;
}
}
return toReturn;
}
}
public class AvailablePlugin {
private IPlugin myInstance = null;
private string myAssemblyPath = "";
public IPlugin Instance {
get { return myInstance; }
set { myInstance = value; }
}
public string AssemblyPath {
get { return myAssemblyPath; }
set { myAssemblyPath = value; }
}
}
}