From d59ef973344a1b223ae68b6900cf03fa96307f76 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Tue, 13 Jun 2017 11:14:06 -0700 Subject: [PATCH] 2.36 keepass support Use dynamics and reflection to support both old and new keepass versions:) --- EntryTemplateManager.TemplateEditor.cs | 4 +-- EntryTemplateManager.cs | 41 +++++++++++++++++++++----- KPEntryTemplates.csproj | 1 + Properties/AssemblyInfo.cs | 6 ++-- README.md | 1 + 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/EntryTemplateManager.TemplateEditor.cs b/EntryTemplateManager.TemplateEditor.cs index 253d035..bdb602c 100644 --- a/EntryTemplateManager.TemplateEditor.cs +++ b/EntryTemplateManager.TemplateEditor.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; @@ -365,7 +365,7 @@ void dataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e String old_row_err = validate_row(row, false, null); if (String.IsNullOrEmpty(old_row_err)) return; - DialogResult res = MessageBox.Show("The old row values are not valid, if you continue to cancel we will delete the row", "Error Editing Row", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); + DialogResult res = MessageBox.Show("The old row values are not valid, if you continue to cancel we will delete the row (make sure all fields are filled out and not named after another)", "Error Editing Row", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (res != DialogResult.Retry) { dataGridView.CancelEdit(); to_del = row; diff --git a/EntryTemplateManager.cs b/EntryTemplateManager.cs index b730e42..bfb9511 100644 --- a/EntryTemplateManager.cs +++ b/EntryTemplateManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; @@ -8,6 +8,8 @@ using KeePassLib.Collections; using KeePassLib.Security; using KeePassLib.Utility; +using KeePass.UI; +using KeePass.Resources; namespace KPEntryTemplates { partial class EntryTemplateManager { @@ -154,14 +156,37 @@ public static PwObjectList GetPossibleTemplates(IPluginHost m_host) { return entries; } public static PwEntry show_parent_template_chooser(IPluginHost m_host) { - EntryListForm elf = new EntryListForm(); - PwObjectList entries = GetPossibleTemplates(m_host); - elf.InitEx("Select Parent Template Entry", "Selecting Parent Template Entry", "Select the parent entry to use as a template", Resources.Resources.B48x48_Folder_Txt, m_host.MainWindow.ClientIcons, entries); - elf.EnsureForeground = true; + var list_type = Type.GetType("KeePass.Forms.ListViewForm,KeePass"); + var elf_type = Type.GetType("KeePass.Forms.EntryListForm,KeePass"); + var entries = GetPossibleTemplates(m_host); + if (list_type != null) { + dynamic elf = Activator.CreateInstance(list_type); + var entry_list = new List(); + foreach (var entry in entries) { + var lvi = new ListViewItem(entry.Strings.ReadSafe(PwDefs.TitleField), + entry.CustomIconUuid == PwUuid.Zero ? (int)entry.IconId : m_host.Database.GetCustomIconIndex(entry.CustomIconUuid)); + lvi.Tag = entry; + entry_list.Add(lvi); + } - if (elf.ShowDialog() != DialogResult.OK || elf.SelectedEntry == null) - return null; - return elf.SelectedEntry; + + elf.InitEx("Select Parent Template Entry", "Selecting Parent Template Entry", "Select the parent entry to use as a template", + Resources.Resources.B48x48_Folder_Txt, entry_list, m_host.MainWindow.ClientIcons, (Action)((lv) => { lv.Columns.Add(KPRes.Title, lv.ClientSize.Width - UIUtil.GetVScrollBarWidth()); })); + elf.EnsureForeground = true; + + if (elf.ShowDialog() != DialogResult.OK) + return null; + return elf.ResultItem as PwEntry; + } else if (elf_type != null) { + dynamic elf = Activator.CreateInstance(elf_type); + elf.InitEx("Select Parent Template Entry", "Selecting Parent Template Entry", "Select the parent entry to use as a template", Resources.Resources.B48x48_Folder_Txt, m_host.MainWindow.ClientIcons, entries); + elf.EnsureForeground = true; + if (elf.ShowDialog() != DialogResult.OK) + return null; + return elf.SelectedEntry; + + } else + throw new Exception("No EntryLListForm or ListViewForm? I am not sure how to work with this version of keepass"); } public static string get_entry_template_parent_uuid(PwEntry entry) { ProtectedString str = entry.Strings.Get("_etm_template_uuid"); diff --git a/KPEntryTemplates.csproj b/KPEntryTemplates.csproj index 9fcaea7..bbcccb8 100644 --- a/KPEntryTemplates.csproj +++ b/KPEntryTemplates.csproj @@ -52,6 +52,7 @@ ..\..\save\keepass_bin\KeePass.exe False + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b7507ad..79424fe 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Mitch Capper")] [assembly: AssemblyProduct("KeePass Plugin")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("7.3.0.0")] -[assembly: AssemblyFileVersion("7.3.0.0")] +[assembly: AssemblyVersion("7.5.0.0")] +[assembly: AssemblyFileVersion("7.5.0.0")] diff --git a/README.md b/README.md index d98515d..b84d1b2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ KP Entry Templates for KeePass 2.x CHANGES ----- +- 7.5 Compatibility with KeePass 2.36 and better - 7.3 Added inline url option that has a clickable link to open the url - 7.2 Fixed bug that prevented working on *nix platforms, thanks to @x09 - 7.01 Fixed bug causing crash if first field was not a textbox on a template