/// <summary> /// Constructs the MainWindow object /// </summary> /// <param name="plugins"></param> public MainWindow(string[] plugins) { CheckForIllegalCrossThreadCalls = false; // No worries ;) Log("Loading CPAutomator..."); this.plug_struct = new cpPlugins(); plug_struct.plugins = new List<CPPluginInterface>(); plug_struct.rev_plugins = new List<CPRevertablePluginInterface>(); foreach (string plugin in plugins) { AssemblyName an = AssemblyName.GetAssemblyName(plugin); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } InitializeComponent(); enumeratePlugins(plug_struct); foreach (var item in plug_struct.plugins) { if (item.SupportedOS != this.getOperatingSystem() && item.SupportedOS != OS_TYPE.OS_GENERIC) continue; CPAPI.setAPI(CPAPI.createApiInstance( this.getOperatingSystem(), this, item.Name)); this.pluginGridView.Rows.Add(item.PrettyName, "Run", "Settings", "Unload", "0", item.Name); item.onPluginLoad(); } foreach (var item in plug_struct.rev_plugins) { if (item.SupportedOS != this.getOperatingSystem() && item.SupportedOS != OS_TYPE.OS_GENERIC) continue; CPAPI.setAPI(CPAPI.createApiInstance( this.getOperatingSystem(), this, item.Name)); this.pluginGridView.Rows.Add(item.PrettyName + " (Rev)"); item.onPluginLoad(); } }
/// <summary> /// Enumerates plugins from their Assembly /// </summary> /// <param name="plugins"></param> private void enumeratePlugins(cpPlugins plugins) { foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types; try { types = assembly.GetTypes(); } catch (Exception) { Log("Unable to load assembly -- Skipping..."); continue; } foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) continue; else { if (type.GetInterface(typeof(CPRevertablePluginInterface).FullName) != null) plugins.rev_plugins.Add( (CPRevertablePluginInterface)Activator.CreateInstance(type)); else if (type.GetInterface(typeof(CPPluginInterface).FullName) != null) plugins.plugins.Add( (CPPluginInterface)Activator.CreateInstance(type)); } } } } }