Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaifm committed Sep 21, 2019
1 parent c901be8 commit 7d9d194
Showing 1 changed file with 53 additions and 16 deletions.
69 changes: 53 additions & 16 deletions HIBPOfflineCheck/HIBPOfflineColumnProv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public sealed class HIBPOfflineColumnProv : ColumnProvider
public IPluginHost Host { private get; set; }
public Options PluginOptions { get; set; }

private bool insecureWarning;
private bool receivedStatus;
private string currentStatus;
private bool insecureWarning = false;
private bool receivedStatus = false;
private string currentStatus = null;
private bool bulkCheck = false;

public BloomFilter BloomFilter { get; set; }

Expand Down Expand Up @@ -253,6 +254,7 @@ public override void PerformCellAction(string strColumnName, PwEntry pe)
if (strColumnName != PluginOptions.ColumnName) { return; }

PasswordEntry = pe;
bulkCheck = false;

GetPasswordStatus();

Expand Down Expand Up @@ -333,19 +335,26 @@ public override string GetCellData(string strColumnName, PwEntry pe)
private void UpdateStatus()
{
MainForm mainForm = HIBPOfflineCheckExt.Host.MainWindow;
ListView lv = (mainForm.Controls.Find("m_lvEntries", true)[0] as ListView);

UIScrollInfo scroll = UIUtil.GetScrollInfo(lv, true);

PasswordEntry.Strings.Set(PluginOptions.ColumnName, new ProtectedString(false, Status));

mainForm.UpdateUI(false, null, false, null, true, null, true);

UIUtil.Scroll(lv, scroll, true);
if (bulkCheck == false)
{
UpdateUI();
}

ResetState();
}

private void UpdateUI()
{
MainForm mainForm = HIBPOfflineCheckExt.Host.MainWindow;
ListView lv = (mainForm.Controls.Find("m_lvEntries", true)[0] as ListView);
UIScrollInfo scroll = UIUtil.GetScrollInfo(lv, true);
mainForm.UpdateUI(false, null, false, null, true, null, true);
UIUtil.Scroll(lv, scroll, true);
}

public void PasswordCheckWorker()
{
GetPasswordStatus();
Expand All @@ -358,6 +367,8 @@ public void PasswordCheckWorker()

public async void CheckAll()
{
bulkCheck = true;

var progressDisplay = new ProgressDisplay();
progressDisplay.Show();

Expand All @@ -379,6 +390,8 @@ public async void CheckAll()
}
}

UpdateUI();

progressDisplay.Close();
}

Expand All @@ -390,22 +403,30 @@ public void ClearAll()
if (dialog == DialogResult.Cancel)
return;

bulkCheck = true;

MainForm mainForm = Host.MainWindow;

PwObjectList<PwEntry> allEntries = new PwObjectList<PwEntry>();
Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries);

for (uint i = 0; i < allEntries.UCount; i++)
{
var pwEntry = allEntries.GetAt(i);
pwEntry.Strings.Remove(PluginOptions.ColumnName);
PasswordEntry = allEntries.GetAt(i);

PasswordEntry.Strings.Remove(PluginOptions.ColumnName);
Status = null;
receivedStatus = true;
TouchEntry(PasswordEntry);
}

mainForm.UpdateUI(false, null, false, null, true, null, true);
UpdateUI();
}

public async void OnMenuHIBP(object sender, EventArgs e)
{
bulkCheck = true;

var progressDisplay = new ProgressDisplay();
progressDisplay.Show();

Expand All @@ -427,6 +448,8 @@ public async void OnMenuHIBP(object sender, EventArgs e)
}
}

UpdateUI();

progressDisplay.Close();
}

Expand All @@ -435,26 +458,38 @@ public void OnMenuHIBPClear(object sender, EventArgs e)
MainForm mainForm = HIBPOfflineCheckExt.Host.MainWindow;
PwEntry[] selectedEntries = mainForm.GetSelectedEntries();

bulkCheck = true;

foreach (PwEntry pwEntry in selectedEntries)
{
pwEntry.Strings.Remove(PluginOptions.ColumnName);
PasswordEntry = pwEntry;

PasswordEntry.Strings.Remove(PluginOptions.ColumnName);
Status = null;
receivedStatus = true;
TouchEntry(PasswordEntry);
}

mainForm.UpdateUI(false, null, false, null, true, null, true);
UpdateUI();
}

public void OnMenuHIBPExclude(object sender, EventArgs e)
{
MainForm mainForm = HIBPOfflineCheckExt.Host.MainWindow;
PwEntry[] selectedEntries = mainForm.GetSelectedEntries();

bulkCheck = true;

foreach (PwEntry pwEntry in selectedEntries)
{
PasswordEntry = pwEntry;

Status = PluginOptions.ExcludedText;
pwEntry.Strings.Set(PluginOptions.ColumnName, new ProtectedString(false, Status));
receivedStatus = true;
TouchEntry(PasswordEntry);
}

mainForm.UpdateUI(false, null, false, null, true, null, true);
UpdateUI();
}

public void EntrySaved(object sender, EventArgs e)
Expand All @@ -469,6 +504,8 @@ public void EntrySaved(object sender, EventArgs e)
form.EntryRef.Touched -= PwdTouchedHandler;
form.EntryRef.Touched += PwdTouchedHandler;

bulkCheck = false;

form.EntryRef.Touch(true);
}

Expand Down

0 comments on commit 7d9d194

Please sign in to comment.