-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEngine.cs
More file actions
149 lines (123 loc) · 5.17 KB
/
Copy pathPluginEngine.cs
File metadata and controls
149 lines (123 loc) · 5.17 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace netCommander
{
class PluginEngine
{
public event QueryPanelInfoEventHandler QueryActivePanel;
public event QueryPanelInfoEventHandler QueryPassivePanel;
private List<IPlugin> plugins_loaded = new List<IPlugin>();
private MenuItem parent_plugin_menu = null;
public void Init(MenuItem parent_menu)
{
parent_plugin_menu = parent_menu;
plugins_loaded.Clear();
//first get plugins dll
string[] plugins_dll = Directory.GetFiles
(Path.GetDirectoryName(Application.ExecutablePath),
"plugin_*.dll",
SearchOption.TopDirectoryOnly);
//iterate throw dlls
foreach (string plugin_dll in plugins_dll)
{
try
{
//load assembly
Assembly plugin_assembly = null;
plugin_assembly = Assembly.LoadFile(plugin_dll);
if (plugin_assembly == null)
{
continue;
}
Type[] plugin_types = plugin_assembly.GetTypes();
//iterate throw assembly types
foreach (Type one_type in plugin_types)
{
//continue if type is not class and not public public
if (!(one_type.IsClass && one_type.IsPublic))
{
continue;
}
//check if type implements IPlugin interface
Type plugin_interface_type = one_type.GetInterface("IPlugin", true);
if (plugin_interface_type == null)
{
continue;
}
//create plugin instance
IPlugin one_plugin = (IPlugin)plugin_assembly.CreateInstance(one_type.FullName);
//add to list
plugins_loaded.Add(one_plugin);
//bind to query callback
one_plugin.QueryHostInfo += new QueryHostInfoEventHandler(one_plugin_QueryHostInfo);
//call init
one_plugin.Init();
}
}//to next type
catch (Exception ex)
{
Messages.ShowException(ex, string.Format(Options.GetLiteral(Options.LANG_FAILED_TO_LOAD_PLUGIN_FROM_0), plugin_dll));
}
}//to next dll
}
void one_plugin_QueryHostInfo(object sender, QueryHostInfoEventArgs e)
{
//query panels
QueryPanelInfoEventArgs e_active = new QueryPanelInfoEventArgs();
QueryPanelInfoEventArgs e_passive = new QueryPanelInfoEventArgs();
on_query_active_panel(e_active);
on_query_passive_panel(e_passive);
//create args
string[] selected_files = new string[0];
if ((e_active.SelectedIndices.Length == 0) && (e_active.FocusedIndex >= 0))
{
selected_files = new string[] { e_active.ItemCollection.GetCommandlineTextLong(e_active.FocusedIndex) };
}
else
{
selected_files = new string[e_active.SelectedIndices.Length];
for (int i = 0; i < e_active.SelectedIndices.Length; i++)
{
selected_files[i] = e_active.ItemCollection.GetCommandlineTextLong(e_active.SelectedIndices[i]);
}
}
string active_directory = string.Empty;
if (e_active.ItemCollection is DirectoryList)
{
active_directory = ((DirectoryList)e_active.ItemCollection).DirectoryPath;
}
string passive_directory = string.Empty;
if (e_passive.ItemCollection is DirectoryList)
{
passive_directory = ((DirectoryList)e_passive.ItemCollection).DirectoryPath;
}
Form main_form = Program.MainWindow;
//and set event arg props
e.DirectoryActive = active_directory;
e.DirectoryPassive = passive_directory;
e.MainPluginMenuItem = parent_plugin_menu;
e.MainWindow = main_form;
e.SelectedEntries = selected_files;
}
private void on_query_active_panel(QueryPanelInfoEventArgs e)
{
if (QueryActivePanel == null)
{
return;
}
QueryActivePanel(this, e);
}
private void on_query_passive_panel(QueryPanelInfoEventArgs e)
{
if (QueryPassivePanel == null)
{
return;
}
QueryPassivePanel(this, e);
}
}
}