public vActivationState Activate() { if (_assembly == null) { return(vActivationState.NoActivationRequired); } try { _plugin = Activator.CreateInstance(_PluginType) as IGCPlugin; foreach (Plugin p in Plugin.Plugins) { if (p.ShortName.Trim().ToLower() == _plugin.ShortName.Trim().ToLower()) { _plugin = null; // the assembly is loaded, but there isn't any way to unload it // without tearing down the appDomain, so we'll just have to leave // it until the user corrects it, if ever. return(vActivationState.NameConflict); } } string[] o = null; try { o = Serializer.Load <string[]>(Global.AppDataFolder + "\\PluginSettings." + _PluginType.Name + ".xml"); } catch (Exception ex) { Log.WriteLine("Couldn't load plugin settings (" + FriendlyName + ")"); Log.WriteLine(ex); } _plugin.LoadSettings(o); return(vActivationState.Activated); } catch (Exception e) { Log.WriteLine("[ER] Could not avticate plugin"); Log.WriteLine(e); return(vActivationState.Error); } }
public Plugin(IGCPlugin p) { _plugin = p; _SecurityKey = Security.SecurityKey; _assembly = Assembly.GetAssembly(typeof(Program)); }
public static IGCPlugin SetPlugin(string PluginFile) { if (!Security.matchKey(Security.getKey(asm))) { if (!PluginState.inst.alwaysAllow.Contains(asm.ToString())) { sec.setSigned((Security.getKey(asm) != "")); sec.setPlugin(asm.ManifestModule.Name); DialogResult d = DialogResult.None; try { Global.mainForm.Show(); d = sec.ShowDialog(Global.mainForm); } catch (Exception) { // exception here if the program is closed from the // tray while waiting for a dialog. } switch (d) { case DialogResult.Abort: // do not load asm return(null); case DialogResult.OK: // temp allow // break; case DialogResult.Yes: // always allow PluginState.inst.alwaysAllow.Add(asm.ToString()); break; default: return(null); } } else { // already in list. } } IGCPlugin plug = null; try { plug = Activator.CreateInstance(PluginClass) as IGCPlugin; } catch (Exception e) { MessageBox.Show("Plugin Error: " + e.InnerException.Message, "Plugin Error"); return(null); } if (plug == null) { return(null); } foreach (IGCPlugin p in Plugins) { if (p.getInfo().NameSpace.Trim().ToLower() == plug.getInfo().NameSpace.Trim().ToLower()) { MessageBox.Show("Plugin '" + p.getInfo().Name + "' is already loaded with namespace '" + p.getInfo().NameSpace + "'\n\n" + "Plugin '" + plug.getInfo().Name + "' with namespace '" + plug.getInfo().NameSpace + "' cannot be loaded because they are equal", "Plugin Load Error"); return(null); } } //MessageBox.Show( asm.FullName + " " + Security.getKey(asm)); AsmList.Add(plug, asm); return(plug); }