diff --git a/mdfinder/MainWindow.xaml b/mdfinder/MainWindow.xaml
index a686699..2ab37cd 100644
--- a/mdfinder/MainWindow.xaml
+++ b/mdfinder/MainWindow.xaml
@@ -49,7 +49,7 @@
-
+
@@ -61,7 +61,7 @@
-
-
-
-
+
diff --git a/mdfinder/MainWindow.xaml.cs b/mdfinder/MainWindow.xaml.cs
index 8088ba4..cba95e0 100644
--- a/mdfinder/MainWindow.xaml.cs
+++ b/mdfinder/MainWindow.xaml.cs
@@ -12,6 +12,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using System.Windows.Forms;
+using System.Threading;
namespace mdfinder
{
@@ -24,6 +26,8 @@ namespace mdfinder
public DBHelper Database { get; set; }
+ public Scanner Scanner { get; set; }
+
#endregion
#region Constructors
@@ -32,8 +36,40 @@ namespace mdfinder
public MainWindow()
{
this.Database = new DBHelper();
+ this.Scanner = new Scanner();
+
+ this.Scanner.DirectoryFound += (sender, args) => Dispatcher.Invoke(() => txtScanLocation.Text = args.Directory.Name);
+ //this.Scanner.FilesFound += (sender, args) => args.Files;
+ this.Scanner.ReportProgress += (sender, args) => Dispatcher.Invoke(() => { if (args.Processed > 0) { this.progressBar.Value = args.Percentage * 100; } });
+
InitializeComponent();
- }
+ }
+
+ #endregion
+
+ #region Methods
+
+ private void btnFilePicker_Click(object sender, RoutedEventArgs e)
+ {
+ var fbd = new FolderBrowserDialog();
+
+ if(fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ txtScanLocation.Text = fbd.SelectedPath;
+ }
+ }
+
+ private void btnScan_Click(object sender, RoutedEventArgs e)
+ {
+ var location = txtScanLocation.Text;
+ if (!this.Scanner.IsScanning)
+ {
+ new Thread(() =>
+ {
+ this.Scanner.Scan(location);
+ }).Start();
+ }
+ }
#endregion
}
diff --git a/mdfinder/Scanner.cs b/mdfinder/Scanner.cs
index 0780d5d..ecf479a 100644
--- a/mdfinder/Scanner.cs
+++ b/mdfinder/Scanner.cs
@@ -8,37 +8,37 @@ using System.Threading.Tasks;
namespace mdfinder
{
/// Scans directories, logging files and their attributes.
- public static class Scanner
+ public class Scanner
{
#region Members
/// Event queue for all listeners interested in FilesFound events.
- public static event EventHandler FilesFound;
+ public event EventHandler FilesFound;
/// Event queue for all listeners interested in DirectoryFound events.
- public static event EventHandler DirectoryFound;
+ public event EventHandler DirectoryFound;
/// Event queue for all listeners interested in ReportProgress events.
- public static event EventHandler ReportProgress;
+ public event EventHandler ReportProgress;
#endregion
#region Properties
- public static uint Processed { get; private set; }
+ public uint Processed { get; private set; }
- public static uint Total { get; private set; }
+ public uint Total { get; private set; }
- public static bool IsScanning { get; private set; }
+ public bool IsScanning { get; private set; }
#endregion
#region Methods
- public static void Scan(string path)
+ public void Scan(string path)
{
- Processed = 0;
- Total = 0;
+ this.Processed = 0;
+ this.Total = 0;
var scanPath = new DirectoryInfo(path);
if (scanPath.Exists)
@@ -47,51 +47,58 @@ namespace mdfinder
}
}
- private static void Scan(DirectoryInfo directory)
+ private void Scan(DirectoryInfo directory)
{
- var files = directory.GetFiles();
- var fileBatches = files.Bin(Properties.Settings.Default.FilesFoundAlert);
- var subdirectories = directory.GetDirectories();
-
- Total += (uint)files.Count();
-
- foreach (var subdirectory in subdirectories)
+ try
{
- OnDirectoryFound(subdirectory);
+ var files = directory.GetFiles();
+ var fileBatches = files.Bin(Properties.Settings.Default.FilesFoundAlert);
+ var subdirectories = directory.GetDirectories();
- Scan(subdirectory);
+ this.Total += (uint)files.Count();
+
+ foreach (var subdirectory in subdirectories)
+ {
+ OnDirectoryFound(subdirectory);
+
+ Scan(subdirectory);
+ }
+
+ foreach (var batch in fileBatches)
+ {
+ OnFilesFound(batch);
+
+ this.Processed += (uint)batch.Count();
+
+ OnReportProgress(this.Processed, this.Total);
+ }
}
-
- foreach (var batch in fileBatches)
+ catch(UnauthorizedAccessException unauthorizedAccessException)
{
- OnFilesFound(batch);
-
- Processed += (uint)batch.Count();
-
- OnReportProgress(Processed, Total);
+ //Ignore and just continue.
}
}
/// Executes the files found action.
/// The files.
- private static void OnFilesFound(IEnumerable files)
+ private void OnFilesFound(IEnumerable files)
{
- FilesFound?.Invoke(null, new FilesFoundEventArgs(files));
+ this.FilesFound?.Invoke(this, new FilesFoundEventArgs(files));
}
/// Executes the directory found action.
/// Pathname of the directory.
- private static void OnDirectoryFound(DirectoryInfo directory)
+ private void OnDirectoryFound(DirectoryInfo directory)
{
- DirectoryFound?.Invoke(null, new DirectoryFoundEventArgs(directory));
+ this.DirectoryFound?.Invoke(this, new DirectoryFoundEventArgs(directory));
}
/// Executes the report progress action.
/// The processed.
/// Number of.
- private static void OnReportProgress(uint processed, uint total)
+ private void OnReportProgress(uint processed, uint total)
{
- ReportProgress?.Invoke(null, new ProgressReportEventArgs(processed, total));
+ this.ReportProgress?.Invoke(this, new ProgressReportEventArgs(processed, total));
}
#endregion
@@ -175,7 +182,8 @@ namespace mdfinder
/// The total discovereditem count.
public ProgressReportEventArgs(uint processed, uint total)
{
-
+ this.Processed = processed;
+ this.Total = total;
}
#endregion
diff --git a/mdfinder/mdfinder.csproj b/mdfinder/mdfinder.csproj
index 0e1d3f3..73f54f2 100644
--- a/mdfinder/mdfinder.csproj
+++ b/mdfinder/mdfinder.csproj
@@ -54,6 +54,7 @@
+