private void buttonScan_Click(object sender, RoutedEventArgs e) { _scanBase.Model = Tree.Model as SectionModel; if (Scan.EnabledScanners.Count == 0) { MessageBox.Show(Application.Current.MainWindow, "At least one section must be selected in order for the Windows Registry to be scanned.", Utils.ProductName, MessageBoxButton.OK, MessageBoxImage.Error); return; } _scanBase.MoveNext(); }
/// <summary> /// Begins scanning for errors in the registry /// </summary> private void StartScanning() { // Set scan start time _dateTimeStart = DateTime.Now; // Create log file + Write Header Wizard.CreateNewLogFile(); // Begin Critical Region Thread.BeginCriticalRegion(); try { Wizard.Report.WriteLine("Started scan at " + DateTime.Now); Wizard.Report.WriteLine(); // Begin Scanning foreach (var scanner in EnabledScanners) { InvokeCurrentSection(scanner.ScannerName); Wizard.Report.WriteLine("Starting scanning: " + scanner.ScannerName); StartScanner(scanner); if (_cancellationTokenSource.IsCancellationRequested) { _cancellationTokenSource.Token.ThrowIfCancellationRequested(); } Wizard.Report.WriteLine("Finished scanning: " + scanner.ScannerName); Wizard.Report.WriteLine(); } } catch (OperationCanceledException) { // Scanning was aborted Wizard.Report.Write("User aborted scan... "); Wizard.Report.WriteLine("Exiting.\r\n"); } finally { // Compute time between start and end of scan var ts = DateTime.Now.Subtract(_dateTimeStart); // Report to Little Software Stats Main.Watcher.EventPeriod("Registry Cleaner", "Scan", (int)ts.TotalSeconds, true); // Stop timer _timerUpdate.Stop(); // Write scan stats to log file Wizard.Report.WriteLine("Total time elapsed: {0} minutes {1} seconds", ts.Minutes, ts.Seconds); Wizard.Report.WriteLine("Total problems found: {0}", TotalProblems); Wizard.Report.WriteLine("Total objects scanned: {0}", _totalItemsScanned); Wizard.Report.WriteLine(); Wizard.Report.WriteLine("Finished scan at " + DateTime.Now); // End Critical Region Thread.EndCriticalRegion(); // Reset taskbar progress bar Dispatcher.BeginInvoke(new Action(() => Main.TaskbarProgressState = TaskbarItemProgressState.None)); if (!_cancellationTokenSource.IsCancellationRequested) { _scanBase.MoveNext(); } _cancellationTokenSource.Dispose(); _cancellationTokenSource = null; } }