Skip to content

Commit

Permalink
Changes to allow the TayTOTP plugin to work with versions of KeePass …
Browse files Browse the repository at this point in the history
…above 2.42.

A breaking change was introduced in version 2.42 which caused the TrayTOTP plugin to be incompatible (See here:  https://sourceforge.net/p/keepass/discussion/329220/thread/5ef408ed35/).  This fix allows the TRayTOTP plugin to work with versions of KeePass above 2.42 and whilst also retaining backwards compatibility with versions below 2.42.
  • Loading branch information
craigtp committed May 7, 2019
1 parent 76f1cfd commit c61c35c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/TrayTotp_Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal sealed partial class TrayTotpGTExt : Plugin
/// </summary>
internal const string keeobj_string_EntryContextMenuCopyPassword_Name = "m_ctxEntryCopyPassword";
internal const string keeobj_string_EntryContextMenuEntriesSubMenu_Name = "m_ctxEntryMassModify";
internal const string keeobj_string_EntryContextMenuEntriesSubMenu_NameAlternative = "m_ctxEntryEditQuick";
internal const string keeobj_string_EntryContextMenuEntriesSubMenuSeperator1_Name = "m_ctxEntrySelectedSep1";
/// <summary>
/// Constants (custom string key).
Expand Down Expand Up @@ -235,7 +236,17 @@ public override bool Initialize(IPluginHost host)
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];
ToolStripMenuItem ContextMenu;
try
{
//For KeePass versions 2.41 or below.
ContextMenu = (ToolStripMenuItem) m_host.MainWindow.EntryContextMenu.Items.Find(keeobj_string_EntryContextMenuEntriesSubMenu_Name, true)[0];
}
catch
{
// For KeePass versions 2.42 and above.
ContextMenu = (ToolStripMenuItem)m_host.MainWindow.EntryContextMenu.Items.Find(keeobj_string_EntryContextMenuEntriesSubMenu_NameAlternative, 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);
Expand Down

0 comments on commit c61c35c

Please sign in to comment.