Skip to content

Commit

Permalink
Allow closing and deleting OTP databases (#9)
Browse files Browse the repository at this point in the history
Allow closure and deletion of OTP database
Prompt for deletion of OTP database when switching to entry-specific storage
  • Loading branch information
Rookiestyle authored Jul 19, 2020
1 parent ebaf199 commit c389182
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 52 deletions.
10 changes: 9 additions & 1 deletion Translations/KeePassOTP.de.language.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Translation>
<TranslationVersion>6</TranslationVersion>
<TranslationVersion>7</TranslationVersion>
<item>
<key>OTPCopyTrayNoEntries</key>
<value>KPOTP - Keine Einträge vorhanden</value>
Expand Down Expand Up @@ -225,5 +225,13 @@ Neuer Platzhalter: {1}

Damit Auto-Type weiterhin vollumfänglich genutzt werden kann, muss {0} überall durch {1} ersetzt werden..
Soll diese Ersetzung jetzt in allen geladenen Datenbanken durchgeführt werden?</value>
</item>
<item>
<kye>ConfirmOTPDBDelete</key>
<value>Diese Aktion deaktiviert die OTP-Datenbank.
Die OTP-Datenbank wird dadurch NICHT gelöscht.

Klicke '{0}' um die OTP-Datenbank zu deaktivieren und zu löschen.
Klicke '{1}' um die OTP-Datenbank zu deaktivieren und nicht zu löschen.</value>
</item>
</Translation>
8 changes: 8 additions & 0 deletions Translations/KeePassOTP.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,12 @@ New value: {1}
All occurrences of {0} need to be replaced by {1} for Auto-Type to work.
Replace now in currently loaded databases?</value>
</item>
<item>
<kye>ConfirmOTPDBDelete</key>
<value>This will deactivate the OTP database.
It will NOT delete the OTP database.

Click '{0}' to deactivate AND delete OTP database.
Click '{1}' to deactivate but not delete OTP database.</value>
</item>
</Translation>
18 changes: 18 additions & 0 deletions src/DAO/OTPDAO_DB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,20 @@ public void OTPDB_Open()
}

OTPDB_Load();
if (OTPDB_Opened) OTPDB.Modified = false;
m_bOpening = false;
}

public void OTPDB_Close()
{
if (!Valid) return;
if (!OTPDB_Opened) return;

OTPDB_Save();
OTPDB.Close();
OTPDB_Opened = false;
}

public void OTPDB_Remove()
{
if (!Valid) return;
Expand Down Expand Up @@ -342,6 +353,13 @@ private void UpdateDBHeader()
#endregion

#region Handle PwEntry
public bool HasEntries()
{
if (!Valid) return false;
if (!OTPDB_Exists) return false;
if (!OTPDB_Opened) return false;
return (OTPDB.RootGroup != null) && (OTPDB.RootGroup.GetEntriesCount(true) > 0);
}
public override bool EnsureOTPSetupPossible(PwEntry pe)
{
if (!Valid) return false;
Expand Down
9 changes: 5 additions & 4 deletions src/KeePassOTPColumnProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void StopTimer()
}

private bool m_bUpdateInProgress = false;
public static bool ForceUpdate = false;
private void OnTimerTick(object sender, EventArgs e)
{
if (m_bUpdateInProgress)
Expand All @@ -101,14 +102,14 @@ private void OnTimerTick(object sender, EventArgs e)
if (KeePass.Program.MainForm.UIIsInteractionBlocked()) return;
if (!KeePass.Program.MainForm.Visible) return;
if (!KeePass.Program.MainForm.ActiveDatabase.IsOpen) return;
if (KeePass.Program.Config.MainWindow.EntryListColumns.Find(x => x.CustomName == KeePassOTPColumnProvider.KPOTPColumnName) == null) return;
if (KeePass.Program.Config.MainWindow.EntryListColumns.Find(x => x.CustomName == KPOTPColumnName) == null) return;
PwGroup pg = KeePass.Program.MainForm.GetSelectedGroup();
if (pg == null) return;
bool bRefresh = pg.GetEntries(KeePass.Program.Config.MainWindow.ShowEntriesOfSubGroups).FirstOrDefault(x => OTPDAO.OTPDefined(x) == OTPDAO.OTPDefinition.Complete) != null;
if (!bRefresh) return;
if (!bRefresh && !ForceUpdate) return; //Update entry list if OTP DB was closed / deleted
if (ForceUpdate) ForceUpdate = false;
bool LVPossible = LV_DirectUpdate();
if (!LVPossible)
KeePass.Program.MainForm.RefreshEntriesList();
if (!LVPossible) KeePass.Program.MainForm.RefreshEntriesList();
}
finally { m_bUpdateInProgress = false; }
}
Expand Down
62 changes: 36 additions & 26 deletions src/Options.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c389182

Please sign in to comment.