Esempio n. 1
0
        public override void Terminate()
        {
            if (this.pluginMenuItem != null)
            {
                this.pluginHost.MainWindow.ToolsMenu.DropDownItems.Remove(pluginMenuItem);
            }
            if (this.pluginMenuItemAbout != null)
            {
                this.pluginMenuItemAbout.Click -= this.pluginMenuItemAboutOnClickEventHandler;
            }
            if (this.pluginMenuItemOptions != null)
            {
                this.pluginMenuItemOptions.Click -= this.pluginMenuItemOptionsOnClickEventHandler;
            }
            if (this.pluginMenuItemBatchPasswordChanger != null)
            {
                this.pluginMenuItemBatchPasswordChanger.Click -= this.pluginMenuItemBatchPasswordChangerOnClickEventHandler;
            }
            if (this.resourcesEventHandler != null)
            {
                AppDomain.CurrentDomain.ResourceResolve -= this.resourcesEventHandler;
            }

            var control         = FormsUtils.FindControlRecursive(pluginHost.MainWindow, KeePassListViewControl);
            var listViewControl = control as CustomListViewEx;

            if (listViewControl != null)
            {
                listViewControl.KeyUp -= listViewControl_KeyUp;
            }
        }
Esempio n. 2
0
        public override bool Initialize(IPluginHost pluginHost)
        {
            Debug.Assert(pluginHost != null);

            if (pluginHost == null)
            {
                return(false);
            }

            this.pluginHost = pluginHost;

            this.Settings = QuickConnectPluginSettings.Load(pluginHost, new PluginCustomConfigPropertyNameFormatter(PluginName));

            this.fieldsMapper = new SettingsFieldMapper(this.Settings);

            pluginMenuItemOptions        = new ToolStripMenuItem("Options...");
            pluginMenuItemOptions.Click += new EventHandler(
                pluginMenuItemOptionsOnClickEventHandler = delegate(object obj, EventArgs ev) {
                List <String> fields = null;

                // Check if database is open.
                if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen)
                {
                    fields = this.pluginHost.Database.GetAllFields(true).ToList();
                    fields.Sort();
                }

                try
                {
                    KeysHelper.UnregisterKeePassHotKeys();
                    using (FormOptions form = new FormOptions(Title, this.Settings, fields))
                    {
                        form.ShowDialog(pluginHost.MainWindow);
                    }
                }
                finally
                {
                    KeysHelper.RegisterKeePassHotKeys();
                }
            }
                );
            pluginMenuItemBatchPasswordChanger        = new ToolStripMenuItem("Batch Password Changer...");
            pluginMenuItemBatchPasswordChanger.Click += new EventHandler(
                pluginMenuItemBatchPasswordChangerOnClickEventHandler = delegate(object obj, EventArgs ev) {
                IPasswordChangerTreeNode pwTreeNode = null;
                // Check if database is open.
                if (this.pluginHost.Database != null && this.pluginHost.Database.IsOpen)
                {
                    pwTreeNode = PasswordChangerTreeNode.Build(pluginHost.Database, fieldsMapper);
                }
                else
                {
                    pwTreeNode = new EmptyTreeNode("No database available.");
                }
                var pwChangerFactory = new DictionaryPasswordChangerExFactory();

                if (QuickConnectUtils.IsVSpherePowerCLIInstalled())
                {
                    pwChangerFactory.Factories.Add(HostType.ESXi, new PasswordChangerExFactory(new ESXiPasswordChangerFactory()));
                }
                if (!String.IsNullOrEmpty(this.Settings.PsPasswdPath) &&
                    File.Exists(this.Settings.PsPasswdPath) &&
                    PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) &&
                    PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath))
                {
                    pwChangerFactory.Factories.Add(HostType.Windows, new PasswordChangerExFactory(new WindowsPasswordChangerFactory(
                                                                                                      new PsPasswdWrapper(this.Settings.PsPasswdPath)))
                                                   );
                }
                pwChangerFactory.Factories.Add(HostType.Linux, new LinuxPasswordChangerExFactory(new LinuxPasswordChangerFactory()));

                var pwChangerServiceFactory = new PasswordChangerServiceFactory(
                    new PasswordDatabase(this.pluginHost.Database),
                    pwChangerFactory,
                    new SystemClock()
                    );
                using (var form = new FormBatchPasswordChanger(pwTreeNode, pwChangerServiceFactory)) {
                    form.ShowDialog(pluginHost.MainWindow);
                    if (form.Changed)
                    {
                        refreshUI();
                    }
                }
            }
                );
            pluginMenuItemAbout        = new ToolStripMenuItem("About");
            pluginMenuItemAbout.Click += new EventHandler(
                pluginMenuItemAboutOnClickEventHandler = delegate(object obj, EventArgs ev) {
                using (FormAbout form = new FormAbout()) {
                    form.Text = form.Text.Replace("{title}", Title);
                    form.ShowDialog(pluginHost.MainWindow);
                }
            }
                );
            pluginMenuItem = new ToolStripMenuItem(String.Format("{0}", Title));
            pluginMenuItem.DropDownItems.Add(pluginMenuItemBatchPasswordChanger);
            pluginMenuItem.DropDownItems.Add(pluginMenuItemOptions);
            pluginMenuItem.DropDownItems.Add(pluginMenuItemAbout);

            this.pluginHost.MainWindow.ToolsMenu.DropDownItems.Add(pluginMenuItem);

            // Add handlers.
            ContextMenuStrip entryContextMenu = pluginHost.MainWindow.EntryContextMenu;

            entryContextMenu.Opened += new EventHandler(entryContextMenu_Opened);
            entryContextMenu.Closed += new ToolStripDropDownClosedEventHandler(entryContextMenu_Closed);

            var control         = FormsUtils.FindControlRecursive(pluginHost.MainWindow, KeePassListViewControl);
            var listViewControl = control as CustomListViewEx;

            if (listViewControl != null)
            {
                listViewControl.KeyUp += new KeyEventHandler(listViewControl_KeyUp);
            }

            return(true);
        }