Skip to content

Commit 4e5d2c2

Browse files
authored
Merge pull request #3 from blankburian/master
Search for key in multiple databases
2 parents 39532bd + 555e07a commit 4e5d2c2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

KeepassPinentry/EntryDB.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using KeePassLib;
33
using KeePassLib.Collections;
44
using System.Windows.Forms;
5+
using System;
56

67
namespace KeepassPinentry
78
{
@@ -20,13 +21,20 @@ public PwEntry Get(string text)
2021
SearchString = text
2122
};
2223

23-
var list = new PwObjectList<PwEntry>();
24-
Host.Database.RootGroup.SearchEntries(p, list);
25-
26-
var e = list.GetAt(0); // TODO(djherbis): might throw
27-
var title = e.Strings.ReadSafe(PwDefs.TitleField);
28-
ShowBalloonNotification($"Entry {title} was read.");
29-
return e;
24+
var databases = Host.MainWindow.DocumentManager.GetOpenDatabases();
25+
foreach (var database in databases)
26+
{
27+
var list = new PwObjectList<PwEntry>();
28+
database.RootGroup.SearchEntries(p, list);
29+
if (list.UCount > 0)
30+
{
31+
var e = list.GetAt(0);
32+
var title = e.Strings.ReadSafe(PwDefs.TitleField);
33+
ShowBalloonNotification($"Entry {title} was read.");
34+
return e;
35+
}
36+
}
37+
throw new Exception("No " + text + " entry found!");
3038
}
3139

3240
public void ShowBalloonNotification(string aMessage)

0 commit comments

Comments
 (0)