/// <summary> /// Removes all ressources such as menus, handles and forms from KeePass. /// </summary> public override void Terminate() { //Destroy Help Form. if (HelpForm.Visible) { HelpForm.Close(); } else { HelpForm.Dispose(); } //Unregister internal events. m_host.MainWindow.Shown -= MainWindow_Shown; //Remove Tools Menus. m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toMenuTrayTotp); toMenuTrayTotp.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuSettings); toSubMenuSettings.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuSeperator1); toSubMenuSeperator1.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuAbout); toSubMenuAbout.Dispose(); //Remove Notify Icon menus. m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Opening -= OnNotifyMenuOpening; m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(niMenuTitle); niMenuTitle.Dispose(); foreach (var Menu in niMenuList) { m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(Menu); Menu.Dispose(); } m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(niMenuSeperator); niMenuSeperator.Dispose(); //Remove Context menus. m_host.MainWindow.EntryContextMenu.Opening -= OnEntryMenuOpening; m_host.MainWindow.EntryContextMenu.Items.Remove(enMenuCopyTotp); enMenuCopyTotp.Dispose(); //Unregister auto-type function. if (SprEngine.FilterPlaceholderHints.Contains(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets())) { SprEngine.FilterCompile -= SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Remove(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets()); } //Remove Column provider. m_host.ColumnProviderPool.Remove(liColumnTotp); liColumnTotp = null; //Remove Timer. liRefreshTimer.Elapsed -= OnTimerTick; liRefreshTimer.Dispose(); }
/// <summary> /// Removes all ressources such as menus, handles and forms from KeePass. /// </summary> public override void Terminate() { //Destroy Help Form. if (HelpForm.Visible) { HelpForm.Close(); } else { HelpForm.Dispose(); } //Unregister internal events. m_host.MainWindow.Shown -= MainWindow_Shown; //Remove Tools Menus. m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toMenuTrayTotp); toMenuTrayTotp.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuSettings); toSubMenuSettings.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuSeperator1); toSubMenuSeperator1.Dispose(); m_host.MainWindow.ToolsMenu.DropDownItems.Remove(toSubMenuAbout); toSubMenuAbout.Dispose(); //Remove Notify Icon menus. m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Opening -= OnNotifyMenuOpening; m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(niMenuTitle); niMenuTitle.Dispose(); foreach (var Menu in niMenuList) { m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(Menu); Menu.Dispose(); } m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Remove(niMenuSeperator); niMenuSeperator.Dispose(); //Remove Context menus. m_host.MainWindow.EntryContextMenu.Opening -= OnEntryMenuOpening; m_host.MainWindow.EntryContextMenu.Items.Remove(enMenuCopyTotp); enMenuCopyTotp.Dispose(); //Unregister auto-type function. if (SprEngine.FilterPlaceholderHints.Contains(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets())) { SprEngine.FilterCompile -= SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Remove(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets()); } //Remove Column provider. m_host.ColumnProviderPool.Remove(liColumnTotp); liColumnTotp = null; //Remove Timer. liRefreshTimer.Tick -= OnTimerTick; liRefreshTimer.Dispose(); }
/// <summary> /// Initialization of the plugin, adding menus, handlers and forms. /// </summary> /// <param name="host">Plugin host for access to KeePass functions.</param> /// <returns>Successful loading of the plugin, if not the plugin is removed.</returns> public override bool Initialize(IPluginHost host) { //Internalise Host Handle. if (host == null) return false; m_host = host; //Instanciate Help Form. HelpForm = new FormHelp(this); //Register form events. m_host.MainWindow.Shown += MainWindow_Shown; //Tools Menus. toMenuTrayTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strTrayTotpPlugin); toMenuTrayTotp.Image = Properties.Resources.TOTP; m_host.MainWindow.ToolsMenu.DropDownItems.Add(toMenuTrayTotp); toSubMenuSettings = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strSettings); toSubMenuSettings.Image = Properties.Resources.TOTP_Settings; toSubMenuSettings.Click += OnMenuSettingsClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuSettings); toSubMenuSeperator1 = new ToolStripSeparator(); toMenuTrayTotp.DropDownItems.Add(toSubMenuSeperator1); toSubMenuHelp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strHelp); toSubMenuHelp.Image = Properties.Resources.TOTP_Help; toSubMenuHelp.Click += OnMenuHelpClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuHelp); toSubMenuAbout = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strAbout + "..."); toSubMenuAbout.Image = Properties.Resources.TOTP_Info; toSubMenuAbout.Click += OnMenuAboutClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuAbout); //Entry Context Menus. m_host.MainWindow.EntryContextMenu.Opening += OnEntryMenuOpening; enMenuCopyTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strCopyTotp); enMenuCopyTotp.Image = Properties.Resources.TOTP; enMenuCopyTotp.ShortcutKeys = (Keys)Shortcut.CtrlT; enMenuCopyTotp.Click += OnEntryMenuTotpClick; m_host.MainWindow.EntryContextMenu.Items.Insert(m_host.MainWindow.EntryContextMenu.Items.IndexOfKey(keeobj_string_EntryContextMenuCopyPassword_Name) + 1, enMenuCopyTotp); enMenuSetupTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strSetupTotp); enMenuSetupTotp.Image = Properties.Resources.TOTP_Setup; enMenuSetupTotp.ShortcutKeys = (Keys)Shortcut.CtrlShiftI; enMenuSetupTotp.Click += OnEntryMenuSetupClick; var ContextMenu = (ToolStripMenuItem)m_host.MainWindow.EntryContextMenu.Items.Find(keeobj_string_EntryContextMenuEntriesSubMenu_Name, true)[0]; ContextMenu.DropDownItems.Insert(ContextMenu.DropDownItems.IndexOfKey(keeobj_string_EntryContextMenuEntriesSubMenuSeperator1_Name) + 1, enMenuSetupTotp); enMenuSeperator = new ToolStripSeparator(); ContextMenu.DropDownItems.Insert(ContextMenu.DropDownItems.IndexOf(enMenuSetupTotp) + 1, enMenuSeperator); //Notify Icon Context Menus. m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Opening += OnNotifyMenuOpening; niMenuTitle = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strTrayTotpPlugin); niMenuTitle.Image = Properties.Resources.TOTP; m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Insert(0, niMenuTitle); niMenuSeperator = new ToolStripSeparator(); m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Insert(1, niMenuSeperator); //Register auto-type function. if (m_host.CustomConfig.GetBool(setname_bool_AutoType_Enable, true)) { SprEngine.FilterCompile += SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Add(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets()); } //List Column TOTP. liColumnTotp = new TrayTotp_CustomColumn(this); m_host.ColumnProviderPool.Add(liColumnTotp); //Refresh Timer. liRefreshTimer.Interval = setstat_int_EntryList_RefreshRate; liRefreshTimer.Enabled = true; liRefreshTimer.Tick += OnTimerTick; //Time Correction. TimeCorrections = new TimeCorrection_Collection(this, m_host.CustomConfig.GetBool(setname_bool_TimeCorrection_Enable, false)); TimeCorrection_Provider.Interval = Convert.ToInt16(m_host.CustomConfig.GetULong(TrayTotpGTExt.setname_ulong_TimeCorrection_RefreshTime, TrayTotpGTExt.setdef_ulong_TimeCorrection_RefreshTime)); TimeCorrections.AddRangeFromList(m_host.CustomConfig.GetString(setname_string_TimeCorrection_List, string.Empty).Split(';').ToList()); return true; }
/// <summary> /// Initialization of the plugin, adding menus, handlers and forms. /// </summary> /// <param name="host">Plugin host for access to KeePass functions.</param> /// <returns>Successful loading of the plugin, if not the plugin is removed.</returns> public override bool Initialize(IPluginHost host) { //Internalise Host Handle. if (host == null) { return(false); } m_host = host; // Capture the current synchronisation context to allow us to // post a message back to the context's thread in order to update // the user interface (TOTP column) when the timer event fires. _syncContext = SynchronizationContext.Current; //Instanciate Help Form. HelpForm = new FormHelp(this); //Register form events. m_host.MainWindow.Shown += MainWindow_Shown; //Tools Menus. toMenuTrayTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strTrayTotpPlugin); toMenuTrayTotp.Image = Properties.Resources.TOTP; m_host.MainWindow.ToolsMenu.DropDownItems.Add(toMenuTrayTotp); toSubMenuSettings = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strSettings); toSubMenuSettings.Image = Properties.Resources.TOTP_Settings; toSubMenuSettings.Click += OnMenuSettingsClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuSettings); toSubMenuSeperator1 = new ToolStripSeparator(); toMenuTrayTotp.DropDownItems.Add(toSubMenuSeperator1); toSubMenuHelp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strHelp); toSubMenuHelp.Image = Properties.Resources.TOTP_Help; toSubMenuHelp.Click += OnMenuHelpClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuHelp); toSubMenuAbout = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strAbout + "..."); toSubMenuAbout.Image = Properties.Resources.TOTP_Info; toSubMenuAbout.Click += OnMenuAboutClick; toMenuTrayTotp.DropDownItems.Add(toSubMenuAbout); //Entry Context Menus. m_host.MainWindow.EntryContextMenu.Opening += OnEntryMenuOpening; enMenuCopyTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strCopyTotp); enMenuCopyTotp.Image = Properties.Resources.TOTP; enMenuCopyTotp.ShortcutKeys = (Keys)Shortcut.CtrlT; enMenuCopyTotp.Click += OnEntryMenuTotpClick; m_host.MainWindow.EntryContextMenu.Items.Insert(m_host.MainWindow.EntryContextMenu.Items.IndexOfKey(keeobj_string_EntryContextMenuCopyPassword_Name) + 1, enMenuCopyTotp); enMenuSetupTotp = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strSetupTotp); enMenuSetupTotp.Image = Properties.Resources.TOTP_Setup; enMenuSetupTotp.ShortcutKeys = (Keys)Shortcut.CtrlShiftI; enMenuSetupTotp.Click += OnEntryMenuSetupClick; var ContextMenu = new ToolStripMenuItem(); if (m_host.MainWindow.EntryContextMenu.Items.Find(keeobj_string_EntryContextMenuEntriesSubMenu_Name, true).Length > 0) { ContextMenu = (ToolStripMenuItem)m_host.MainWindow.EntryContextMenu.Items.Find(keeobj_string_EntryContextMenuEntriesSubMenu_Name, true)[0]; } ContextMenu.DropDownItems.Insert(ContextMenu.DropDownItems.IndexOfKey(keeobj_string_EntryContextMenuEntriesSubMenuSeperator1_Name) + 1, enMenuSetupTotp); enMenuSeperator = new ToolStripSeparator(); ContextMenu.DropDownItems.Insert(ContextMenu.DropDownItems.IndexOf(enMenuSetupTotp) + 1, enMenuSeperator); //Notify Icon Context Menus. m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Opening += OnNotifyMenuOpening; niMenuTitle = new ToolStripMenuItem(TrayTotp_Plugin_Localization.strTrayTotpPlugin); niMenuTitle.Image = Properties.Resources.TOTP; m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Insert(0, niMenuTitle); niMenuSeperator = new ToolStripSeparator(); m_host.MainWindow.MainNotifyIcon.ContextMenuStrip.Items.Insert(1, niMenuSeperator); //Register auto-type function. if (m_host.CustomConfig.GetBool(setname_bool_AutoType_Enable, true)) { SprEngine.FilterCompile += SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Add(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets()); } //List Column TOTP. liColumnTotp = new TrayTotp_CustomColumn(this); m_host.ColumnProviderPool.Add(liColumnTotp); //Refresh Timer. liRefreshTimer.Interval = setstat_int_EntryList_RefreshRate; liRefreshTimer.Enabled = true; liRefreshTimer.Elapsed += OnTimerTick; //Time Correction. TimeCorrections = new TimeCorrection_Collection(this, m_host.CustomConfig.GetBool(setname_bool_TimeCorrection_Enable, false)); TimeCorrection_Provider.Interval = Convert.ToInt16(m_host.CustomConfig.GetULong(TrayTotpGTExt.setname_ulong_TimeCorrection_RefreshTime, TrayTotpGTExt.setdef_ulong_TimeCorrection_RefreshTime)); TimeCorrections.AddRangeFromList(m_host.CustomConfig.GetString(setname_string_TimeCorrection_List, string.Empty).Split(';').ToList()); return(true); }