public static void CopyToClipboard(IEnumerable <string> inputLines)
        {
            var text = string.Join("\r\n", inputLines.OrderBy(t => t).ToArray());

            if (text.IsNotEmpty())
            {
                try
                {
                    Clipboard.SetText(text);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }
            else
            {
                MessageBoxes.NothingToCopy();
            }
        }
Esempio n. 2
0
        public static void AskAndBeginUpdate()
        {
            if (MessageBoxes.UpdateAskToDownload())
            {
                try
                {
                    // Prevent log cleaner from running in portable builds
                    EntryPoint.IsRestarting = true;

                    UpdateSystem.BeginUpdate();
                }
                catch (Exception ex)
                {
                    EntryPoint.IsRestarting = false;

                    Console.WriteLine(ex);
                    MessageBoxes.UpdateFailed(ex.Message);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Returns false if export failed, else true.
        /// </summary>
        /// <param name="itemsToExport">What to export</param>
        /// <param name="filename">Full path with filename and extension to write the export result to.</param>
        /// <returns></returns>
        public static bool ExportUninstallers(IEnumerable <ApplicationUninstallerEntry> itemsToExport, string filename)
        {
            var applicationUninstallerEntries = itemsToExport as List <ApplicationUninstallerEntry> ??
                                                itemsToExport.ToList();

            if (applicationUninstallerEntries.Count <= 0)
            {
                return(false);
            }

            try
            {
                ApplicationEntrySerializer.SerializeApplicationEntries(filename, applicationUninstallerEntries);
            }
            catch (Exception ex)
            {
                MessageBoxes.ExportFailed(ex.Message, null);
                return(false);
            }
            return(true);
        }
        public static void SearchOnline(IEnumerable <ApplicationUninstallerEntry> selectedUninstallers, string searchString, Func <ApplicationUninstallerEntry, string> searchStringGetter, SearchSeparatorType spaceReplacement)
        {
            if (WindowsTools.IsNetworkAvailable())
            {
                var items = selectedUninstallers
                            .Select(searchStringGetter)
                            .Where(x => !string.IsNullOrEmpty(x))
                            .Select(str =>
                {
                    switch (spaceReplacement)
                    {
                    case SearchSeparatorType.Plus:
                        return(HttpUtility.UrlEncodeUnicode(str));

                    //return str.Replace(' ', '+');
                    case SearchSeparatorType.Escaped:
                        return(HttpUtility.UrlEncodeUnicode(str).Replace("+", "%20"));

                    default:
                        throw new ArgumentOutOfRangeException(nameof(spaceReplacement), spaceReplacement, null);
                    }
                }).Select(y => string.Concat(searchString, y)).ToList();

                if (MessageBoxes.SearchOnlineMessageBox(items.Count) == MessageBoxes.PressedButton.Yes)
                {
                    try
                    {
                        items.ForEach(x => Process.Start(x));
                    }
                    catch (Exception ex)
                    {
                        MessageBoxes.SearchOnlineError(ex);
                    }
                }
            }
            else
            {
                MessageBoxes.NoNetworkConnected();
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Ask to self uninstall and do so if user agrees, else return and do nothing.
        /// </summary>
        internal void AskToSelfUninstall()
        {
            if (MessageBoxes.SelfUninstallQuestion())
            {
                if (!TryGetUninstallLock())
                {
                    return;
                }

                try
                {
                    Process.Start("unins000.exe");
                    Environment.Exit(0);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
                finally
                {
                    ReleaseUninstallLock();
                }
            }
        }
Esempio n. 6
0
        public void UninstallFromDirectory(IEnumerable <ApplicationUninstallerEntry> allUninstallers)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }
            var listRefreshNeeded = false;

            var applicationUninstallerEntries = allUninstallers as IList <ApplicationUninstallerEntry> ?? allUninstallers.ToList();

            try
            {
                var dialog = new FolderBrowserDialog
                {
                    RootFolder  = Environment.SpecialFolder.Desktop,
                    Description = Localisable.UninstallFromDirectory_FolderBrowse
                };

                if (dialog.ShowDialog(MessageBoxes.DefaultOwner) != DialogResult.OK)
                {
                    return;
                }

                var items = new List <ApplicationUninstallerEntry>();
                LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.UninstallFromDirectory_ScanningTitle,
                                         _ =>
                {
                    items.AddRange(DirectoryFactory.TryCreateFromDirectory(
                                       new DirectoryInfo(dialog.SelectedPath), null, new string[] { }));
                });

                if (items.Count == 0)
                {
                    items.AddRange(applicationUninstallerEntries
                                   .Where(x => PathTools.PathsEqual(dialog.SelectedPath, x.InstallLocation)));
                }

                if (items.Count == 0)
                {
                    MessageBoxes.UninstallFromDirectoryNothingFound();
                }
                else
                {
                    foreach (var item in items.ToList())
                    {
                        if (item.UninstallPossible && item.UninstallerKind != UninstallerType.SimpleDelete &&
                            MessageBoxes.UninstallFromDirectoryUninstallerFound(item.DisplayName, item.UninstallString))
                        {
                            item.RunUninstaller(false, Settings.Default.AdvancedSimulate).WaitForExit(60000);
                            items.Remove(item);
                            listRefreshNeeded = true;
                        }
                        else
                        {
                            var found = applicationUninstallerEntries.Where(
                                x => PathTools.PathsEqual(item.InstallLocation, x.InstallLocation)).ToList();

                            if (!found.Any())
                            {
                                continue;
                            }

                            items.Remove(item);

                            foreach (var entry in found)
                            {
                                if (entry.UninstallPossible && entry.UninstallerKind != UninstallerType.SimpleDelete &&
                                    MessageBoxes.UninstallFromDirectoryUninstallerFound(entry.DisplayName, entry.UninstallString))
                                {
                                    try { item.RunUninstaller(false, Settings.Default.AdvancedSimulate).WaitForExit(60000); }
                                    catch (Exception ex) { PremadeDialogs.GenericError(ex); }

                                    listRefreshNeeded = true;
                                }
                                else
                                {
                                    items.Add(entry);
                                }
                            }
                        }
                    }

                    AdvancedUninstall(items, applicationUninstallerEntries.Where(
                                          x => !items.Any(y => PathTools.PathsEqual(y.InstallLocation, x.InstallLocation))));
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
                if (listRefreshNeeded)
                {
                    _initiateListRefresh();
                }
            }
        }
Esempio n. 7
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();
                }
            }
        }
Esempio n. 8
0
        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
                                     // Run commands before deleting any files or reg keys to avoid missing files
                                     orderby item is RunProcessJunk descending,
                    // Need to stop and unregister service before deleting its exe
                    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);
            }
        }
Esempio n. 9
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();
                }
            }
        }
        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();
                }
            }
        }
        /// <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);
        }