Skip to content

Commit

Permalink
Add support for KeePassCPEO
Browse files Browse the repository at this point in the history
If KeePassCPEO is installed, the password change form let's you now also choose the expiry options defined KeePassCPEO

closes #26
  • Loading branch information
Rookiestyle committed May 11, 2024
1 parent 12be4ee commit a5cce66
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
35 changes: 34 additions & 1 deletion src/PCADialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,43 @@ private void InitExpiryDate()
EntryExpiry.Value = DateTime.Now.AddMonths(6).ToLocalTime();
EntryExpiry.Checked = true;
}
else return;
// else return;

//Let's see whether PEDCalc is installed and active
CheckPEDCalc();

//Let's see whether KeePassCPOEc is installed and active
CheckKeePassCPOE();
}

private void CheckKeePassCPOE()
{
KeePassCPEOStub kpcpoe = new KeePassCPEOStub((KeePass.Plugins.Plugin)Tools.GetPluginInstance("KeePassCPEO"));
if (!kpcpoe.Loaded) return;
if (kpcpoe.CustomOptions.Count == 0) return;
m_ctxDefaultTimes.Items.Add(new ToolStripSeparator());
foreach (var co in kpcpoe.CustomOptions)
{
var tsmi = new ToolStripMenuItem() { Text = co.ToString(), Tag = co };
tsmi.Click += OnKPCPOEClick;
m_ctxDefaultTimes.Items.Add(tsmi);
}
}

private void OnKPCPOEClick(object sender, EventArgs e)
{
var tsmi = sender as ToolStripMenuItem;
var x = tsmi.Tag.GetType().GetProperties();
var y = tsmi.Tag.GetType().GetProperty("Years").GetValue(tsmi.Tag, null);
var m = tsmi.Tag.GetType().GetProperty("Months").GetValue(tsmi.Tag, null);
var d = tsmi.Tag.GetType().GetProperty("Days").GetValue(tsmi.Tag, null);

if (y == null || m == null || d == null) return;
var dt = Program.MainForm.GetSelectedEntry(true).ExpiryTime;
dt = dt.AddYears((int)y);
dt = dt.AddMonths((int)y);
dt = dt.AddDays((int)d);
EntryExpiry.Value = dt.ToLocalTime();
}

private void CheckPEDCalc()
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("2.16.2")]
[assembly: AssemblyFileVersion("2.16.2")]
[assembly: AssemblyVersion("2.17")]
[assembly: AssemblyFileVersion("2.17")]
[assembly: Guid("5d5cc62b-d6f6-4e0b-a7ff-3d5ef21dd656")]
24 changes: 24 additions & 0 deletions src/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,30 @@ internal static Image ScaleImage(Image img, int w, int h)
}
}

public class KeePassCPEOStub
{
private KeePass.Plugins.Plugin _p = null;
public bool Loaded { get { return _p != null; } }

public List<object> CustomOptions = new List<object>();
public KeePassCPEOStub(KeePass.Plugins.Plugin p)
{
_p = p;
Initialize();
}

private void Initialize()
{
if (!Loaded) return;
var mi = _p.GetType().GetMember("CustomDateOptions");
if (mi == null) return;
var pi = ((PropertyInfo)mi[0]).GetValue(_p, null) as IEnumerable<object>;
if (pi == null) return;
foreach (var co in pi)
CustomOptions.Add(co);
}
}

public class PEDCalcStub
{
private KeePass.Plugins.Plugin _pedcalc = null;
Expand Down
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
PasswordChangeAssistant:2.16.2
PasswordChangeAssistant:2.17
PasswordChangeAssistant!de:11
PasswordChangeAssistant!it:3
PasswordChangeAssistant!pt:9
Expand Down

0 comments on commit a5cce66

Please sign in to comment.