- note about fixing multithreaded fftw crashes
[FaRetSys.git] / PluginDB.cs
blobdcb2878534a6fb2ff0b33c75e6ec4f2f25190687
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);
89 f.Initialize();
91 switch(f.Type)
93 case IType.In:
94 In.Add(f);
95 break;
96 case IType.Out:
97 Out.Add(f);
98 break;
99 case IType.ImgProc:
100 ImgProc.Add(f);
101 break;
102 case IType.ResProc:
103 ResProc.Add(f);
104 break;
105 case IType.Comparator:
106 Comparator.Add(f);
107 break;
108 case IType.Other:
109 Other.Add(f);
110 break;
113 Origin.Add(f, new Source(Path.GetFileName(fn), t.FullName));
114 RevOrigin.Add(new Source(Path.GetFileName(fn), t.FullName), f);
118 catch(Exception e)
120 Console.WriteLine(Catalog.GetString("Error while processing {0}: {1}"), fn, e.Message);