- renamed aa to offset
[FaRetSys.git] / PluginDB.cs
bloba47a62ce54d6f87957650d61f53c5c196d89178c
1 using System;
2 using System.Collections;
3 using System.IO;
4 using System.Reflection;
5 using Mono.Unix;
7 namespace Eithne
9 class Source
11 private readonly string a, c;
13 public Source(string a, string c)
15 this.a = a;
16 this.c = c;
19 public string Assembly
21 get { return a; }
24 public string Class
26 get { return c; }
29 public static bool operator == (Source s1, Source s2)
31 return s1.Assembly == s2.Assembly && s1.Class == s2.Class;
34 public static bool operator != (Source s1, Source s2)
36 return !(s1 == s2);
39 public override bool Equals(object o)
41 if(!(o is Source))
42 return false;
43 return this == (Source)o;
46 public override int GetHashCode()
48 return a.GetHashCode() ^ c.GetHashCode();
52 class PluginDB
54 public static ArrayList In = new ArrayList();
55 public static ArrayList Out = new ArrayList();
56 public static ArrayList ImgProc = new ArrayList();
57 public static ArrayList ResProc = new ArrayList();
58 public static ArrayList Comparator = new ArrayList();
59 public static ArrayList Other = new ArrayList();
61 public static Hashtable Origin = new Hashtable();
62 public static Hashtable RevOrigin = new Hashtable();
64 public static void LoadPlugins(Splash s)
66 string basedir = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Plugins");
67 string[] tmp = Directory.GetFiles(basedir, "*.dll");
68 string[] p = new string[tmp.Length + 1];
70 p[0] = System.Reflection.Assembly.GetExecutingAssembly().Location;
71 for(int i=0; i<tmp.Length; i++)
72 p[i+1] = tmp[i];
74 int count = 0;
76 foreach(string fn in p)
78 try
80 s.Message = Catalog.GetString("Inspecting ") + fn;
81 s.Progress = ++count / (float)(tmp.Length + 1);
82 Assembly a = Assembly.LoadFrom(fn);
84 foreach(Type t in a.GetTypes())
86 if(t.GetInterface(typeof(IFactory).FullName) != null && !t.IsAbstract)
88 IFactory f = (IFactory)Activator.CreateInstance(t);
90 switch(f.Type)
92 case IType.In:
93 In.Add(f);
94 break;
95 case IType.Out:
96 Out.Add(f);
97 break;
98 case IType.ImgProc:
99 ImgProc.Add(f);
100 break;
101 case IType.ResProc:
102 ResProc.Add(f);
103 break;
104 case IType.Comparator:
105 Comparator.Add(f);
106 break;
107 case IType.Other:
108 Other.Add(f);
109 break;
112 Origin.Add(f, new Source(Path.GetFileName(fn), t.FullName));
113 RevOrigin.Add(new Source(Path.GetFileName(fn), t.FullName), f);
117 catch(Exception e)
119 Console.WriteLine(Catalog.GetString("Error while processing {0}: {1}"), fn, e.Message);