Ejemplo n.º 1
0
        public void RunUninstall(IEnumerable <ApplicationUninstallerEntry> selectedUninstallers,
                                 IEnumerable <ApplicationUninstallerEntry> allUninstallers, bool quiet)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }
            var listRefreshNeeded = false;

            try
            {
                var targetList         = new List <ApplicationUninstallerEntry>(selectedUninstallers);
                var allUninstallerList = allUninstallers as IList <ApplicationUninstallerEntry> ?? allUninstallers.ToList();

                if (!_settings.AdvancedDisableProtection)
                {
                    var protectedTargets = targetList.Where(x => x.IsProtected).ToList();
                    if (
                        MessageBoxes.ProtectedItemsWarningQuestion(protectedTargets.Select(x => x.DisplayName).ToArray()) ==
                        MessageBoxes.PressedButton.Cancel)
                    {
                        return;
                    }

                    targetList.RemoveAll(protectedTargets);
                }

                if (targetList.Any())
                {
                    _lockApplication(true);

                    BulkUninstallEntry[] taskEntries;

                    using (var wizard = new BeginUninstallTaskWizard())
                    {
                        wizard.Initialize(targetList, allUninstallerList.ToList(), quiet);

                        wizard.StartPosition = FormStartPosition.CenterParent;
                        if (wizard.ShowDialog(MessageBoxes.DefaultOwner) != DialogResult.OK)
                        {
                            return;
                        }

                        taskEntries = wizard.Results;
                    }

                    _visibleCallback(false);

                    // No turning back at this point (kind of)
                    listRefreshNeeded = true;

                    if (_settings.ExternalEnable && _settings.ExternalPreCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePreUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPreCommands, controller); });
                    }

                    var status = UninstallManager.CreateBulkUninstallTask(taskEntries, GetConfiguration(quiet));
                    status.OneLoudLimit = _settings.UninstallConcurrentOneLoud;
                    status.ConcurrentUninstallerCount = _settings.UninstallConcurrency
                        ? _settings.UninstallConcurrentMaxCount
                        : 1;
                    status.Start();

                    UninstallProgressWindow.ShowUninstallDialog(status, entries => SearchForAndRemoveJunk(entries, allUninstallerList));

                    var junkRemoveTargetsQuery = from bulkUninstallEntry in status.AllUninstallersList
                                                 where bulkUninstallEntry.CurrentStatus == UninstallStatus.Completed ||
                                                 bulkUninstallEntry.CurrentStatus == UninstallStatus.Invalid ||
                                                 (bulkUninstallEntry.CurrentStatus == UninstallStatus.Skipped &&
                                                  !bulkUninstallEntry.UninstallerEntry.RegKeyStillExists())
                                                 select bulkUninstallEntry.UninstallerEntry;

                    if (MessageBoxes.LookForJunkQuestion())
                    {
                        SearchForAndRemoveJunk(junkRemoveTargetsQuery, allUninstallerList);
                    }

                    if (_settings.ExternalEnable && _settings.ExternalPostCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePostUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPostCommands, controller); });
                    }

                    SystemRestore.EndSysRestore();
                }
                else
                {
                    MessageBoxes.NoUninstallersSelectedInfo();
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
                _visibleCallback(true);
                if (listRefreshNeeded)
                {
                    _initiateListRefresh();
                }
            }
        }
Ejemplo n.º 2
0
        public void RunUninstall(IEnumerable <ApplicationUninstallerEntry> selectedUninstallers,
                                 IEnumerable <ApplicationUninstallerEntry> allUninstallers, bool quiet)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }
            var listRefreshNeeded = false;

            try
            {
                var targets = new List <ApplicationUninstallerEntry>(selectedUninstallers);

                if (!_settings.AdvancedDisableProtection)
                {
                    var protectedTargets = targets.Where(x => x.IsProtected).ToList();
                    if (
                        MessageBoxes.ProtectedItemsWarningQuestion(protectedTargets.Select(x => x.DisplayName).ToArray()) ==
                        MessageBoxes.PressedButton.Cancel)
                    {
                        return;
                    }

                    targets.RemoveAll(protectedTargets);
                }

                if (targets.Any())
                {
                    _lockApplication(true);

                    var taskEntries = ConvertToTaskEntries(quiet, targets);

                    taskEntries = _settings.AdvancedIntelligentUninstallerSorting
                        ? SortIntelligently(taskEntries).ToList()
                        : taskEntries.OrderBy(x => x.UninstallerEntry.DisplayName).ToList();

                    taskEntries = UninstallConfirmationWindow.ShowConfirmationDialog(MessageBoxes.DefaultOwner, taskEntries);

                    if (taskEntries == null || taskEntries.Count == 0)
                    {
                        return;
                    }

                    if (!SystemRestore.BeginSysRestore(targets.Count))
                    {
                        return;
                    }

                    if (!CheckForRunningProcessesBeforeUninstall(taskEntries.Select(x => x.UninstallerEntry), !quiet))
                    {
                        return;
                    }

                    // No turning back at this point (kind of)
                    listRefreshNeeded = true;

                    _visibleCallback(false);

                    if (_settings.ExternalEnable && _settings.ExternalPreCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePreUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPreCommands, controller); });
                    }

                    var status = UninstallManager.CreateBulkUninstallTask(taskEntries, GetConfiguration(quiet));
                    status.OneLoudLimit = _settings.UninstallConcurrentOneLoud;
                    status.ConcurrentUninstallerCount = _settings.UninstallConcurrency
                        ? _settings.UninstallConcurrentMaxCount
                        : 1;
                    status.Start();

                    UninstallProgressWindow.ShowUninstallDialog(status, entries => SearchForAndRemoveJunk(entries, allUninstallers));

                    var junkRemoveTargetsQuery = from bulkUninstallEntry in status.AllUninstallersList
                                                 where bulkUninstallEntry.CurrentStatus == UninstallStatus.Completed ||
                                                 bulkUninstallEntry.CurrentStatus == UninstallStatus.Invalid ||
                                                 (bulkUninstallEntry.CurrentStatus == UninstallStatus.Skipped &&
                                                  !bulkUninstallEntry.UninstallerEntry.RegKeyStillExists())
                                                 select bulkUninstallEntry.UninstallerEntry;

                    if (MessageBoxes.LookForJunkQuestion())
                    {
                        SearchForAndRemoveJunk(junkRemoveTargetsQuery, allUninstallers);
                    }

                    if (_settings.ExternalEnable && _settings.ExternalPostCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePostUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPostCommands, controller); });
                    }

                    SystemRestore.EndSysRestore();
                }
                else
                {
                    MessageBoxes.NoUninstallersSelectedInfo();
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
                _visibleCallback(true);
                if (listRefreshNeeded)
                {
                    _initiateListRefresh();
                }
            }
        }
Ejemplo n.º 3
0
        public void RunUninstall(IEnumerable <ApplicationUninstallerEntry> selectedUninstallers,
                                 IEnumerable <ApplicationUninstallerEntry> allUninstallers, bool quiet)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }
            var listRefreshNeeded = false;

            try
            {
                var targets = new List <ApplicationUninstallerEntry>(selectedUninstallers);

                if (!_settings.AdvancedDisableProtection)
                {
                    var protectedTargets = targets.Where(x => x.IsProtected).ToList();
                    if (
                        MessageBoxes.ProtectedItemsWarningQuestion(protectedTargets.Select(x => x.DisplayName).ToArray()) ==
                        MessageBoxes.PressedButton.Cancel)
                    {
                        return;
                    }

                    targets.RemoveAll(protectedTargets);
                }

                if (targets.Any())
                {
                    _lockApplication(true);

                    // Steam will be required to run loud steam app uninstalls
                    if (!CheckForRunningProcessesBeforeUninstall(targets, !quiet))
                    {
                        return;
                    }

                    if (!SystemRestore.BeginSysRestore(targets.Count))
                    {
                        return;
                    }

                    // No turning back at this point (kind of)
                    listRefreshNeeded = true;

                    if (_settings.ExternalEnable && _settings.ExternalPreCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePreUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPreCommands, controller); });
                    }

                    var status = UninstallManager.RunBulkUninstall(targets, GetConfiguration(quiet));
                    status.OneLoudLimit = _settings.UninstallConcurrentOneLoud;
                    status.ConcurrentUninstallerCount = _settings.UninstallConcurrency
                        ? _settings.UninstallConcurrentMaxCount
                        : 1;
                    status.Start();

                    using (var uninstallWindow = new UninstallProgressWindow())
                    {
                        uninstallWindow.Shown += (sender, args) => ((UninstallProgressWindow)sender).SetTargetStatus(status);
                        uninstallWindow.ShowDialog(MessageBoxes.DefaultOwner);
                    }

                    var junkRemoveTargetsQuery = from bulkUninstallEntry in status.AllUninstallersList
                                                 where bulkUninstallEntry.CurrentStatus == UninstallStatus.Completed ||
                                                 bulkUninstallEntry.CurrentStatus == UninstallStatus.Invalid ||
                                                 (bulkUninstallEntry.CurrentStatus == UninstallStatus.Skipped &&
                                                  !bulkUninstallEntry.UninstallerEntry.RegKeyStillExists())
                                                 select bulkUninstallEntry.UninstallerEntry;

                    if (MessageBoxes.LookForJunkQuestion())
                    {
                        SearchForAndRemoveJunk(junkRemoveTargetsQuery, allUninstallers);
                    }

                    if (_settings.ExternalEnable && _settings.ExternalPostCommands.IsNotEmpty())
                    {
                        LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitlePostUninstallCommands,
                                                 controller => { RunExternalCommands(_settings.ExternalPostCommands, controller); });
                    }

                    SystemRestore.EndSysRestore();
                }
                else
                {
                    MessageBoxes.NoUninstallersSelectedInfo();
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
                if (listRefreshNeeded)
                {
                    _initiateListRefresh();
                }
            }
        }