Skip to content

Commit

Permalink
2.36 keepass support
Browse files Browse the repository at this point in the history
Use dynamics and reflection to support both old and new keepass versions:)
  • Loading branch information
mitchcapper committed Jun 13, 2017
1 parent 1b65bc4 commit d59ef97
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
4 changes: 2 additions & 2 deletions EntryTemplateManager.TemplateEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
Expand Down Expand Up @@ -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;
Expand Down
41 changes: 33 additions & 8 deletions EntryTemplateManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
Expand All @@ -8,6 +8,8 @@
using KeePassLib.Collections;
using KeePassLib.Security;
using KeePassLib.Utility;
using KeePass.UI;
using KeePass.Resources;

namespace KPEntryTemplates {
partial class EntryTemplateManager {
Expand Down Expand Up @@ -154,14 +156,37 @@ public static PwObjectList<PwEntry> GetPossibleTemplates(IPluginHost m_host) {
return entries;
}
public static PwEntry show_parent_template_chooser(IPluginHost m_host) {
EntryListForm elf = new EntryListForm();
PwObjectList<PwEntry> 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<object>();
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<ListView>)((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");
Expand Down
1 change: 1 addition & 0 deletions KPEntryTemplates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<HintPath>..\..\save\keepass_bin\KeePass.exe</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")]

Expand All @@ -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")]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d59ef97

Please sign in to comment.