private void buttonCleaner_Click(object sender, EventArgs e) { panelActionButtons.Show(); this.panelProgress.Visible = true; buttonCleaner.BackColor = ApplicationSettings.SelectedButtonColor; buttonRegistry.BackColor = ApplicationSettings.NormalButtonColor; buttonTools.BackColor = ApplicationSettings.NormalButtonColor; buttonOptions.BackColor = ApplicationSettings.NormalButtonColor; this.ucCleaner1.Visible = true; this.ucResult.Visible = false; this.panelCleanerComponents.Visible = true; this.gboxResult.Visible = true; this.panelProgress.Visible = true; if (panelCleanerComponents.Controls.Find("Registry", false).Count() > 0) { UCRegistry registry = panelCleanerComponents.Controls.Find("Registry", false)[0] as UCRegistry; registry.Hide(); } if (panelCleanerComponents.Controls.Find("ucCleaner1", false).Count() > 0) { UCCleaner registry = panelCleanerComponents.Controls.Find("ucCleaner1", false)[0] as UCCleaner; registry.Show(); } if (gboxResult.Controls.Find("Tools", false).Count() > 0) { UCTools registry = gboxResult.Controls.Find("Tools", false)[0] as UCTools; registry.Hide(); } if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() > 0) { UCResultRegistry result = this.gboxResult.Controls.Find("UCResultRegistry", true)[0] as UCResultRegistry; result.Visible = false; } if (gboxResult.Controls.Find("Options", false).Count() > 0) { UCOptions result = this.gboxResult.Controls.Find("Options", true)[0] as UCOptions; result.Visible = false; } ShowHideControls(ApplicationItem.Cleaner); SelectedItem = ApplicationItem.Cleaner; //ucResult.ResetView(); }
private void CleanupSystem() { if (this.progressBar1.InvokeRequired) { this.progressBar1.Invoke(new MethodInvoker(delegate { this.progressBar1.Visible = true; })); } ; var searchCriteria = GetSearchCriteria(); var filesFound = Analyzer.GetSearchResults(searchCriteria, ref ProgressBarLabel, ref this.backgroundWorkerSearch, true); if (SelectedItem == ApplicationItem.Registry) { var registryItems = filesFound; var gridItems = new List <ResultDetail>(); UCResultRegistry result = this.gboxResult.Controls.Find("UCResultRegistry", true)[0] as UCResultRegistry; var items = result.SelectedRows; Cleaner.CleanUpSystem(searchCriteria, items, SelectedItem, ref this.backgroundWorkerSearch); MessageBox.Show($"{items.Count} registry items deleted successfully."); result.SelectedRows.Clear(); } else { long totalSpaceCleanedUp = filesFound.Sum(t => t.FileSize); Cleaner.CleanUpSystem(searchCriteria, filesFound, SelectedItem, ref this.backgroundWorkerSearch); Task.Factory.StartNew(() => ProcessSearch(true)); double mb = 0; if (totalSpaceCleanedUp > 0) { mb = (totalSpaceCleanedUp * 1.0 / 1000); } MessageBox.Show("Total space wiped is " + Math.Round(mb, 2) + " MB"); } this.backgroundWorkerSearch.DoWork -= backgroundWorkerSearch_DoWork; this.backgroundWorkerSearch.ProgressChanged -= backgroundWorkerSearch_ProgressChanged; }
public void ProcessSearch(bool afterSearch = false) { if (afterSearch) { this.backgroundWorkerSearch = new BackgroundWorker(); this.backgroundWorkerSearch.WorkerReportsProgress = true; this.backgroundWorkerSearch.WorkerSupportsCancellation = true; this.backgroundWorkerSearch.DoWork += backgroundWorkerSearch_DoWork; this.backgroundWorkerSearch.ProgressChanged += backgroundWorkerSearch_ProgressChanged; this.backgroundWorkerSearch.RunWorkerCompleted += backgroundWorkerSearch_RunWorkerCompleted; } if (this.progressBar1.InvokeRequired) { this.progressBar1.Invoke(new MethodInvoker(delegate { this.progressBar1.Visible = true; })); } ; if (SelectedItem == ApplicationItem.Cleaner) { if (this.gboxResult.InvokeRequired) { this.gboxResult.Invoke(new MethodInvoker(delegate { this.gboxResult.Visible = true; if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() > 0) { this.gboxResult.Controls.Find("UCResultRegistry", true)[0].Visible = false; } })); } else { this.gboxResult.Visible = true; if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() > 0) { this.gboxResult.Controls.Find("UCResultRegistry", true)[0].Visible = false; } } if (this.ucResult.InvokeRequired) { this.ucResult.Invoke(new MethodInvoker(delegate { this.ucResult.Visible = true; })); } else { this.ucResult.Visible = true; } if (this.ucResult.panelSearchComplete.InvokeRequired) { this.ucResult.panelSearchComplete.Invoke(new MethodInvoker(delegate { this.ucResult.panelSearchComplete.Hide(); })); } else { this.ucResult.panelSearchComplete.Hide(); } if (this.ucResult.panelStatus.InvokeRequired) { this.ucResult.panelStatus.Invoke(new MethodInvoker(delegate { this.ucResult.panelStatus.Show(); })); } else { this.ucResult.panelStatus.Show(); } if (this.ucResult.panelSearchProgress.InvokeRequired) { this.ucResult.panelSearchProgress.Invoke(new MethodInvoker(delegate { this.ucResult.panelSearchProgress.Dock = DockStyle.Fill; this.ucResult.panelSearchProgress.Show(); })); } else { this.ucResult.panelSearchProgress.Dock = DockStyle.Fill; this.ucResult.panelSearchProgress.Show(); } if (this.ucResult.labelProgressBar.InvokeRequired) { this.ucResult.labelProgressBar.Invoke(new MethodInvoker(delegate { this.ucResult.labelProgressBar.Visible = true; })); } else { this.ucResult.labelProgressBar.Visible = true; } try { List <SearchCriteria> searchCriteria = GetSearchCriteria(); SearchResult = Analyzer.GetSearchResults(searchCriteria, ref this.ProgressBarLabel, ref this.backgroundWorkerSearch); var overAllResult = Analyzer.GetOverallResult(SearchResult); CleanerApplicationContext.ResultSummary = overAllResult; this.ucResult.ShowResult(ResultView.Overall, overAllResult, afterSearch); this.FilesFound = SearchResult; } catch (Exception ex) { ; } } else if (SelectedItem == ApplicationItem.Registry) { if (this.ucResult.InvokeRequired) { this.ucResult.Invoke(new MethodInvoker(delegate { this.ucResult.Visible = false; })); } else { this.ucResult.Visible = false; } List <SearchCriteria> searchCriteria = GetSearchCriteria(); SearchResult = Analyzer.GetSearchResults(searchCriteria, ref this.ProgressBarLabel, ref this.backgroundWorkerSearch); var overAllResult = Analyzer.GetOverallResult(SearchResult); UCResultRegistry registryControl = null; if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() < 1) { registryControl = new UCResultRegistry(); registryControl.Name = "UCResultRegistry"; registryControl.Dock = DockStyle.Fill; //registryControl.ShowResult(ResultView.Detail, overAllResult); } else { registryControl = this.gboxResult.Controls.Find("UCResultRegistry", true)[0] as UCResultRegistry; if (registryControl.InvokeRequired) { registryControl.Invoke(new MethodInvoker(delegate { registryControl.Visible = true; })); } else { registryControl.Visible = true; } } if (this.gboxResult.InvokeRequired) { this.gboxResult.Invoke(new MethodInvoker(delegate { if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() < 1) { this.gboxResult.Controls.Add(registryControl); } registryControl.ShowResult(ResultView.Detail, overAllResult); })); } else { if (this.gboxResult.Controls.Find("UCResultRegistry", true).Count() < 1) { this.gboxResult.Controls.Add(registryControl); } registryControl.ShowResult(ResultView.Detail, overAllResult); } } this.backgroundWorkerSearch.DoWork -= backgroundWorkerSearch_DoWork; this.backgroundWorkerSearch.ProgressChanged -= backgroundWorkerSearch_ProgressChanged; }