Use correct path when loading plugins.
[reactos.git] / irc / TechBot / TechBot.Library / Factory / CommandFactory.cs
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Reflection;
7
8 namespace TechBot.Library
9 {
10 public class CommandFactory
11 {
12 private static CommandBuilderCollection m_Commands = new CommandBuilderCollection();
13
14 private CommandFactory()
15 {
16 }
17
18 public static void LoadPlugins()
19 {
20 //get the file names of the dll files in the current directory.
21 foreach (string fileName in Directory.GetFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "*.dll"))
22 {
23 LoadPluginsFromDLLFile(fileName);
24 }
25 }
26
27 private static void LoadPluginsFromDLLFile(string sFile)
28 {
29 Assembly assPlugin = Assembly.LoadFile(sFile);
30
31 if (assPlugin != null)
32 {
33 foreach (Type pluginType in assPlugin.GetTypes())
34 {
35 if (pluginType.IsSubclassOf(typeof(Command)))
36 {
37 if (pluginType.IsAbstract == false)
38 {
39 //Add it to the list.
40 Commands.Add(new CommandBuilder(pluginType));
41 }
42 }
43 }
44 }
45 }
46
47 public static CommandBuilderCollection Commands
48 {
49 get { return m_Commands; }
50 }
51 }
52 }