Skip to content

Commit

Permalink
delegates and new registry key
Browse files Browse the repository at this point in the history
added delegates to the entry work, added a new registry key that contains executed files and cleaned the code a lil bit
  • Loading branch information
ponei committed Sep 10, 2020
1 parent f461c82 commit 5d4ca19
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 57 deletions.
32 changes: 29 additions & 3 deletions Data/Entries.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
using CachedProgramsList.Register;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CachedProgramsList.Data
{
class Entries
{

private DataGridViewRow baseRow;
private List<DataGridViewRow> entriesList = new List<DataGridViewRow>();

public event EventHandler<int> EntryAmountUpdate;
public event EventHandler<int> WorkEnded;
public Entries(DataGridViewRow baseRow)
{
this.baseRow = baseRow;
}

protected virtual void OnEntryAmountUpdate()
{
EntryAmountUpdate?.Invoke(this, entryAmount);
}

protected virtual void OnWorkEnded()
{
WorkEnded?.Invoke(this, entryAmount);
}

private int entryAmount = 0;
public List<DataGridViewRow> getEntries(bool search = true)
{
if (search)
{
entriesList.Clear();
entryAmount = 0;
getEntriesForKey(@"SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache");
getEntriesForKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store");
getEntriesForKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");
getEntriesForKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted");
getEntriesForKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FeatureUsage\AppSwitched");
}

OnWorkEnded();
return entriesList;
}

Expand Down Expand Up @@ -91,11 +106,21 @@ public List<DataGridViewRow> filterEntries(string filter, string field)
return filteredEntriesList;
}

private void updateEntryAmountIfNecessary()
{
if (entryAmount % 100 == 0)
{
OnEntryAmountUpdate();
}
}

private void getEntriesForKey(string keyToSearch)
{

Key key = new Key(keyToSearch);
foreach (Entry value in key.getEntries())
{
updateEntryAmountIfNecessary();
if (value.Valid)
{
bool alreadyExists = false;
Expand All @@ -120,6 +145,7 @@ private void getEntriesForKey(string keyToSearch)
newEntry.Cells[2].Value = value.Exists == true ? value.Creation : (DateTime?)null;
newEntry.Cells[3].Value = value.Exists == true ? value.Modification : (DateTime?)null;
newEntry.Cells[4].Value = value.Path;
entryAmount++;
entriesList.Add(newEntry);
}
}
Expand Down
79 changes: 47 additions & 32 deletions FormMain.Designer.cs

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

25 changes: 20 additions & 5 deletions FormMain.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using CachedProgramsList.Data;
using CachedProgramsList.Properties;
using CachedProgramsList.Register;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand All @@ -24,10 +19,26 @@ public FormMain()
{
InitializeComponent();
DoubleBufferedControl(datagEntries, true);

dataEntries = new Entries((DataGridViewRow)datagEntries.Rows[0].Clone());
dataEntries.EntryAmountUpdate += dataEntries_EntryAmountUpdate;
dataEntries.WorkEnded += DataEntries_WorkEnded;

comboFilterOptions.SelectedIndex = 0;
}

private void DataEntries_WorkEnded(object sender, int e)
{
lbEntryAmount.Text = $"Found {e} entries.";
}

private void dataEntries_EntryAmountUpdate(object sender, int e)
{
lbEntryAmount.Text = $"{e} entries...";
}



private void DoubleBufferedControl(DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
Expand Down Expand Up @@ -220,6 +231,8 @@ private void lightTheme()
{
BackColor = Color.FromArgb(235, 235, 235);

lbEntryAmount.ForeColor = Color.FromArgb(15, 15, 15);

datagEntries.BackgroundColor = Color.FromArgb(230, 230, 230);
datagEntries.GridColor = Color.FromArgb(150, 150, 150);

Expand All @@ -239,6 +252,8 @@ private void darkTheme()
{
BackColor = Color.FromArgb(20, 20, 20);

lbEntryAmount.ForeColor = Color.FromArgb(240, 240, 240);

datagEntries.BackgroundColor = Color.FromArgb(25, 25, 25);
datagEntries.GridColor = Color.FromArgb(105, 105, 105);

Expand Down
3 changes: 0 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CachedProgramsList
Expand Down
1 change: 0 additions & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// As informações gerais sobre um assembly são controladas por
Expand Down
8 changes: 1 addition & 7 deletions Register/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;

namespace CachedProgramsList.Register
{
Expand All @@ -16,7 +10,7 @@ class Entry
private bool valid = false, exists = false;
private DateTime creation, modification;
public string Path { get => path; }
public bool Valid { get => valid; }
public bool Valid { get => valid; }
public bool Exists { get => exists; }
public DateTime Creation { get => creation; }
public DateTime Modification { get => modification; }
Expand Down
9 changes: 3 additions & 6 deletions Register/Key.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CachedProgramsList.Register
Expand All @@ -22,10 +19,10 @@ public List<Entry> getEntries()
try
{
string[] keyValues = Registry.CurrentUser.OpenSubKey(key).GetValueNames();
foreach(string keyValue in keyValues)
foreach (string keyValue in keyValues)
{
Entry valueEntry = new Entry(keyValue);
entries.Add(valueEntry);
Entry valueEntry = new Entry(keyValue);
entries.Add(valueEntry);
}
}
catch (Exception e)
Expand Down

0 comments on commit 5d4ca19

Please sign in to comment.