private bool ShowJunkWindow(List <IJunkResult> junk) { if (!junk.Any(x => _settings.MessagesShowAllBadJunk || x.Confidence.GetRawConfidence() >= 0)) { MessageBoxes.NoJunkFoundInfo(); return(false); } using (var junkWindow = new JunkRemoveWindow(junk)) { if (junkWindow.ShowDialog() != DialogResult.OK) { return(false); } var selectedJunk = junkWindow.SelectedJunk.ToList(); if (!CheckForRunningProcessesBeforeCleanup(selectedJunk)) { return(false); } //Removing the junk LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitleRemovingJunk, controller => { var top = selectedJunk.Count; controller.SetMaximum(top); var itemsRemoved = 0; // current value var sortedJunk = from item in selectedJunk // Need to stop and unregister service before deleting its exe orderby item is StartupJunkNode descending select item; foreach (var junkNode in sortedJunk) { controller.SetProgress(itemsRemoved++); if (_settings.AdvancedSimulate) { Thread.Sleep(100); } else { try { junkNode.Delete(); } catch (Exception ex) { Console.WriteLine("Exception while removing junk: " + ex.ToString()); } } } }); return(true); } }
/// <summary> /// Returns true if things were actually removed, false if user cancelled the operation. /// </summary> /// <param name="junkGetter"> /// Delegate that returns junk items to remove. /// It will be ran on a separate thread with a progress bar. /// </param> /// <returns></returns> private bool SearchForAndRemoveJunk(Func <IEnumerable <JunkNode> > junkGetter) { var junk = new List <JunkNode>(); var error = LoadingDialog.ShowDialog(Localisable.LoadingDialogTitleLookingForJunk, x => { junk.AddRange(junkGetter()); }); if (error != null) { PremadeDialogs.GenericError(error); } else if (junk.Any(x => x.Confidence.GetRawConfidence() >= 0)) { using (var junkWindow = new JunkRemoveWindow(junk)) { if (junkWindow.ShowDialog() != DialogResult.OK) { return(false); } var selectedJunk = junkWindow.SelectedJunk.ToList(); if (!CheckForRunningProcessesBeforeCleanup(selectedJunk)) { return(false); } //Removing the junk LoadingDialog.ShowDialog(Localisable.LoadingDialogTitleRemovingJunk, controller => { var top = selectedJunk.Count; controller.SetMaximum(top); var itemsRemoved = 0; // current value foreach (var junkNode in selectedJunk) { controller.SetProgress(itemsRemoved++); if (_settings.AdvancedSimulate) { Thread.Sleep(100); } else { try { junkNode.Delete(); } catch (Exception ex) { Debug.WriteLine("Exception while removing junk: " + ex.ToString()); } } } }); return(true); } } else { MessageBoxes.NoJunkFoundInfo(); } return(false); }