示例#1
0
        private static List <ApplicationUninstallerEntry> GetMiscUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            var otherResults = new List <ApplicationUninstallerEntry>();

            var miscFactories = ReflectionTools.GetTypesImplementingBase <IIndependantUninstallerFactory>()
                                .Attempt(Activator.CreateInstance)
                                .Cast <IIndependantUninstallerFactory>()
                                .Where(x => x.IsEnabled())
                                .ToList();

            var progress = 0;

            foreach (var kvp in miscFactories)
            {
                progressCallback(new ListGenerationProgress(progress++, miscFactories.Count, kvp.DisplayName));
                try
                {
                    var sw = Stopwatch.StartNew();
                    MergeResults(otherResults, kvp.GetUninstallerEntries(null), null);
                    Console.WriteLine($"[Performance] Factory {kvp.DisplayName} took {sw.ElapsedMilliseconds}ms to finish");
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }

            return(otherResults);
        }
        public void SaveSettings()
        {
            if (_resetSettings)
            {
                Selected.Settings.MiscVersion = "Reset";
            }
            else
            {
                Selected.Settings.WindowState = _mainWindow.WindowState;
                if (_mainWindow.WindowState == FormWindowState.Normal)
                {
                    Selected.Settings.WindowSize     = _mainWindow.Size;
                    Selected.Settings.WindowPosition = _mainWindow.Location;
                }

                Selected.Settings.UninstallerListViewState =
                    Convert.ToBase64String(_mainWindow.uninstallerObjectListView.SaveState());

                Selected.Settings.UninstallerListSortOrder  = _mainWindow.uninstallerObjectListView.PrimarySortOrder;
                Selected.Settings.UninstallerListSortColumn = _mainWindow.uninstallerObjectListView.Columns.IndexOf(
                    _mainWindow.uninstallerObjectListView.PrimarySortColumn);
                Selected.Settings.MiscVersion = Program.AssemblyVersion.ToString();
            }

            try
            {
                Selected.Settings.Save();
            }
            catch (Exception ex)
            {
                /*Failed to save settings, probably read only drive*/
                PremadeDialogs.GenericError(new IOException(Localisable.Error_SaveSettingsFailed, ex));
            }
        }
        private void CreateBackup(string backupPath)
        {
            var dir = Path.Combine(backupPath, GetUniqueBackupName());

            try
            {
                Directory.CreateDirectory(dir);
            }
            catch (Exception ex)
            {
                PremadeDialogs.GenericError(ex);
                throw new OperationCanceledException();
            }

            try
            {
                FilesystemTools.CompressDirectory(dir);
            }
            catch
            {
                // Ignore, not important
            }

            RunBackup(dir);
        }
        /// <summary>
        /// Warning: only use with helpers that output unicode and use 0 as success return code.
        /// </summary>
        internal static string StartHelperAndReadOutput(string filename, string args)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            using (var process = Process.Start(new ProcessStartInfo(filename, args)
            {
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = false,
                CreateNoWindow = true,
                StandardOutputEncoding = Encoding.Unicode
            }))
            {
                try
                {
                    var sw     = Stopwatch.StartNew();
                    var output = process?.StandardOutput.ReadToEnd();
                    Console.WriteLine($"[Performance] Running command {filename} {args} took {sw.ElapsedMilliseconds}ms");
                    return(process?.ExitCode == 0 ? output : null);
                }
                catch (Win32Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                    return(null);
                }
            }
        }
示例#5
0
        public void SearchForAndRemoveProgramFilesJunk(IEnumerable <ApplicationUninstallerEntry> allUninstallers)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }

            try
            {
                _lockApplication(true);

                var junk  = new List <IJunkResult>();
                var error = LoadingDialog.ShowDialog(null, Localisable.LoadingDialogTitleLookingForJunk,
                                                     x => junk.AddRange(JunkManager.FindProgramFilesJunk(allUninstallers.Where(y => y.RegKeyStillExists()).ToList())));

                if (error != null)
                {
                    PremadeDialogs.GenericError(error);
                }
                else
                {
                    ShowJunkWindow(junk);
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
            }
        }
        /// <summary>
        /// Alternative startup routine in case WindowsFormsApplicationBase fails.
        /// Uses Process.GetProcesses to check for other instances.
        /// </summary>
        private static void SafeRun()
        {
            var location = Assembly.GetAssembly(typeof(EntryPoint)).Location;
            var otherBcu = Process.GetProcesses().FirstOrDefault(x =>
            {
                try
                {
                    return(string.Equals(x.MainModule.FileName, location, StringComparison.OrdinalIgnoreCase));
                }
                catch
                {
                    return(false);
                }
            });

            if (otherBcu != null)
            {
                try
                {
                    SetForegroundWindow(otherBcu.MainWindowHandle.ToInt32());
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }
            else
            {
                SetupDependancies();
                Application.ApplicationExit += (sender, eventArgs) => ProcessShutdown();
                Application.EnableVisualStyles();
                Application.Run(new MainWindow());
            }
        }
示例#7
0
        public void UninstallUsingMsi(MsiUninstallModes mode,
                                      IEnumerable <ApplicationUninstallerEntry> selectedUninstallers)
        {
            if (!TryGetUninstallLock())
            {
                return;
            }
            var listRefreshNeeded = false;

            try
            {
                _lockApplication(true);

                var results = selectedUninstallers.Take(2).ToList();

                if (results.Count != 1)
                {
                    MessageBoxes.CanSelectOnlyOneItemInfo();
                    return;
                }

                var selected = results.First();

                if (!_settings.AdvancedDisableProtection && selected.IsProtected)
                {
                    MessageBoxes.ProtectedItemError(selected.DisplayName);
                    return;
                }

                if (selected.BundleProviderKey.IsEmpty())
                {
                    MessageBoxes.UninstallMsiGuidMissing();
                    return;
                }

                if (!CheckForRunningProcessesBeforeUninstall(new[] { selected }, true))
                {
                    return;
                }

                try
                {
                    selected.UninstallUsingMsi(mode, _settings.AdvancedSimulate);
                    listRefreshNeeded = true;
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }
            finally
            {
                ReleaseUninstallLock();
                _lockApplication(false);
                if (listRefreshNeeded)
                {
                    _initiateListRefresh();
                }
            }
        }
示例#8
0
        private void ListRefreshThread(LoadingDialogInterface dialogInterface)
        {
            dialogInterface.SetSubProgressVisible(true);
            var uninstallerEntries = ApplicationUninstallerFactory.GetUninstallerEntries(x =>
            {
                dialogInterface.SetMaximum(x.TotalCount);
                dialogInterface.SetProgress(x.CurrentCount, x.Message);

                var inner = x.Inner;
                if (inner != null)
                {
                    dialogInterface.SetSubMaximum(inner.TotalCount);
                    dialogInterface.SetSubProgress(inner.CurrentCount, inner.Message);
                }
                else
                {
                    dialogInterface.SetSubMaximum(-1);
                    dialogInterface.SetSubProgress(0, string.Empty);
                }

                if (dialogInterface.Abort)
                {
                    throw new OperationCanceledException();
                }
            });

            if (!string.IsNullOrEmpty(Program.InstalledRegistryKeyName))
            {
                uninstallerEntries = uninstallerEntries
                                     .Where(x => x.RegistryKeyName != Program.InstalledRegistryKeyName);
            }

            AllUninstallers = uninstallerEntries.ToList();

            dialogInterface.SetMaximum(9);
            dialogInterface.SetProgress(9, Localisable.Progress_Finishing);
            dialogInterface.SetSubMaximum(5);

            dialogInterface.SetSubProgress(2, Localisable.Progress_Finishing_Icons);
            try
            {
                _iconGetter.UpdateIconList(AllUninstallers);
            }
            catch (Exception ex)
            {
                PremadeDialogs.GenericError(ex);
            }

            dialogInterface.SetSubProgress(4, Localisable.Progress_Finishing_Startup);
            try
            {
                ReassignStartupEntries(false);
            }
            catch (Exception ex)
            {
                PremadeDialogs.GenericError(ex);
            }

            //dialogInterface.SetSubProgress(3, string.Empty);
        }
        private void createBackupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            folderBrowserDialog.ShowDialog(this);
            if (!Directory.Exists(folderBrowserDialog.SelectedPath))
            {
                return;
            }

            foreach (var item in Selection)
            {
                try
                {
                    item.CreateBackup(folderBrowserDialog.SelectedPath);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }

            Process.Start(new ProcessStartInfo(folderBrowserDialog.SelectedPath)
            {
                UseShellExecute = true
            });

            UpdateList();
        }
示例#10
0
        private static List <ApplicationUninstallerEntry> GetMiscUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            var otherResults = new List <ApplicationUninstallerEntry>();

            var miscFactories = ReflectionTools.GetTypesImplementingBase <IIndependantUninstallerFactory>()
                                .Attempt(Activator.CreateInstance)
                                .Cast <IIndependantUninstallerFactory>()
                                .Where(x => x.IsEnabled())
                                .ToList();

            var progress = 0;

            foreach (var kvp in miscFactories)
            {
                progressCallback(new ListGenerationProgress(progress++, miscFactories.Count, kvp.DisplayName));
                try
                {
                    otherResults = MergeResults(otherResults, kvp.GetUninstallerEntries(null).ToList(), null);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }

            return(otherResults);
        }
        /// <summary>
        /// Warning: only use with helpers that output unicode and use 0 as success return code.
        /// </summary>
        internal static string StartHelperAndReadOutput(string filename, string args)
        {
            if (!File.Exists(filename))
            {
                return(null);
            }

            using (var process = Process.Start(new ProcessStartInfo(filename, args)
            {
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = false,
                CreateNoWindow = true,
                StandardOutputEncoding = Encoding.Unicode
            }))
            {
                try
                {
                    var output = process?.StandardOutput.ReadToEnd();
                    return(process?.ExitCode == 0 ? output : null);
                }
                catch (Win32Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                    return(null);
                }
            }
        }
示例#12
0
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            var filters = SelectedJunk.OfType <DriveJunkNode>().Select(x => x.FullName).ToArray();

            if (!Uninstaller.CheckForRunningProcesses(filters, false, this))
            {
                return;
            }

            if (SelectedJunk.Any(x => !(x is DriveJunkNode)))
            {
                switch (MessageBoxes.BackupRegistryQuestion(this))
                {
                case MessageBoxes.PressedButton.Yes:
                    if (backupDirDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    var dir = Path.Combine(backupDirDialog.SelectedPath, GetUniqueBackupName());
                    try
                    {
                        Directory.CreateDirectory(dir);
                    }
                    catch (Exception ex)
                    {
                        PremadeDialogs.GenericError(ex);
                        goto case MessageBoxes.PressedButton.Yes;
                    }

                    try
                    {
                        FilesystemTools.CompressDirectory(dir);
                    }
                    catch
                    {
                        // Ignore, not important
                    }

                    if (!RunBackup(dir))
                    {
                        return;
                    }

                    break;

                case MessageBoxes.PressedButton.No:
                    break;

                default:
                    return;
                }
            }

            DialogResult = DialogResult.OK;
            Close();
        }
示例#13
0
        public static void DisplayPrivacyPolicy()
        {
            var path = GetBundledFilePath(Resources.PrivacyPolicyFilename);

            if (path != null)
            {
                PremadeDialogs.StartProcessSafely(path);
            }
        }
示例#14
0
        public static void DisplayLicense()
        {
            var path = GetBundledFilePath(Resources.LicenceFilename);

            if (path != null)
            {
                PremadeDialogs.StartProcessSafely(path);
            }
        }
 private void SoftCrash(object sender, EventArgs e)
 {
     try
     {
         throw new ArithmeticException("Soft crash test", new IndexOutOfRangeException("Yer a bit bored, eh?"));
     }
     catch (Exception ex)
     { PremadeDialogs.GenericError(ex); }
 }
示例#16
0
 private void runCommandToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (var command in Selection)
     {
         if (!PremadeDialogs.StartProcessSafely(command.Command))
         {
             break;
         }
     }
 }
示例#17
0
 private void openLinkLocationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         StartupManager.OpenStartupEntryLocations(Selection);
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
 protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
 {
     try
     {
         MainForm?.Activate();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
 public override void Open()
 {
     try
     {
         WindowsTools.OpenExplorerFocusedOnObject(ProcessToStart.FileName);
     }
     catch (SystemException ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
 private static void OpenJunkNodePreview(IJunkResult item)
 {
     try
     {
         item.Open();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
示例#21
0
 public override void Open()
 {
     try
     {
         StartupManager.OpenStartupEntryLocations(new[] { Entry });
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
 private void FacebookStatusButton_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(TargetSite))
     {
         PremadeDialogs.StartProcessSafely(@"https://www.facebook.com/sharer/sharer.php?u=" + TargetSite);
     }
     else
     {
         throw new InvalidOperationException("TargetSite is null or empty");
     }
 }
 public static void Restart()
 {
     try
     {
         UpdateSystem.RestartApplication();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
示例#24
0
 private void ClearCaches(object sender, EventArgs e)
 {
     try
     {
         File.Delete(MainWindow.CertCacheFilename);
         File.Delete(UninstallToolsGlobalConfig.AppInfoCachePath);
     }
     catch (SystemException systemException)
     {
         PremadeDialogs.GenericError(systemException);
     }
 }
示例#25
0
        /// <summary>
        ///     Returns true if things were actually removed, false if user cancelled the operation.
        /// </summary>
        private bool SearchForAndRemoveJunk(IEnumerable <ApplicationUninstallerEntry> selectedUninstallers,
                                            IEnumerable <ApplicationUninstallerEntry> allUninstallers)
        {
            var junk  = new List <IJunkResult>();
            var error = LoadingDialog.ShowDialog(MessageBoxes.DefaultOwner, Localisable.LoadingDialogTitleLookingForJunk,
                                                 dialogInterface =>
            {
                var allValidUninstallers = allUninstallers.Where(y => y.RegKeyStillExists());

                dialogInterface.SetSubProgressVisible(true);
                junk.AddRange(JunkManager.FindJunk(selectedUninstallers, allValidUninstallers.ToList(), x =>
                {
                    if (x.TotalCount <= 1)
                    {
                        // Don't update the title label to uninstaller name when there's only one uninstaller
                        dialogInterface.SetMaximum(-1);
                    }
                    else
                    {
                        dialogInterface.SetMaximum(x.TotalCount);
                        dialogInterface.SetProgress(x.CurrentCount, x.Message);
                    }

                    var inner = x.Inner;
                    if (inner != null)
                    {
                        dialogInterface.SetSubMaximum(inner.TotalCount);
                        dialogInterface.SetSubProgress(inner.CurrentCount, inner.Message);
                    }
                    else
                    {
                        dialogInterface.SetSubMaximum(-1);
                        dialogInterface.SetSubProgress(0, string.Empty);
                    }

                    if (dialogInterface.Abort)
                    {
                        throw new OperationCanceledException();
                    }
                }));
            });

            if (error != null)
            {
                PremadeDialogs.GenericError(error);
            }
            else
            {
                return(ShowJunkWindow(junk));
            }
            return(false);
        }
        private static List <ApplicationUninstallerEntry> GetMiscUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            var otherResults = new List <ApplicationUninstallerEntry>();

            var miscFactories = new Dictionary <IUninstallerFactory, string>();

            if (UninstallToolsGlobalConfig.ScanPreDefined)
            {
                miscFactories.Add(new PredefinedFactory(), Localisation.Progress_AppStores_Templates);
            }
            if (UninstallToolsGlobalConfig.ScanSteam)
            {
                miscFactories.Add(new SteamFactory(), Localisation.Progress_AppStores_Steam);
            }
            if (UninstallToolsGlobalConfig.ScanStoreApps)
            {
                miscFactories.Add(new StoreAppFactory(), Localisation.Progress_AppStores_WinStore);
            }
            if (UninstallToolsGlobalConfig.ScanWinFeatures)
            {
                miscFactories.Add(new WindowsFeatureFactory(), Localisation.Progress_AppStores_WinFeatures);
            }
            if (UninstallToolsGlobalConfig.ScanWinUpdates)
            {
                miscFactories.Add(new WindowsUpdateFactory(), Localisation.Progress_AppStores_WinUpdates);
            }
            if (UninstallToolsGlobalConfig.ScanChocolatey)
            {
                miscFactories.Add(new ChocolateyFactory(), Localisation.Progress_AppStores_Chocolatey);
            }
            if (UninstallToolsGlobalConfig.ScanOculus)
            {
                miscFactories.Add(new OculusFactory(), Localisation.Progress_AppStores_Oculus);
            }

            var progress = 0;

            foreach (var kvp in miscFactories)
            {
                progressCallback(new ListGenerationProgress(progress++, miscFactories.Count, kvp.Value));
                try
                {
                    otherResults = MergeResults(otherResults, kvp.Key.GetUninstallerEntries(null).ToList(), null);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }

            return(otherResults);
        }
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            try
            {
                File.Delete(DefaultUninstallListPath);

                toolStripButtonDelete.Enabled = false;
            }
            catch (SystemException ex)
            {
                PremadeDialogs.GenericError(ex);
            }
        }
 private void saveUlDialog_FileOk(object sender, CancelEventArgs e)
 {
     try
     {
         CurrentList.SaveToFile(saveUlDialog.FileName);
         CurrentListFileName = saveUlDialog.FileName;
         UnsavedChanges      = false;
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
示例#29
0
 private void openFileDialog_FileOk(object sender, CancelEventArgs e)
 {
     try
     {
         CurrentList.AddItems(UninstallList.ReadFromFile(openFileDialog.FileName).Filters);
         PopulateList();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
         e.Cancel = true;
     }
 }
 public static void Restart()
 {
     try
     {
         IsRestarting = true;
         UpdateSystem.RestartApplication();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
         IsRestarting = false;
     }
 }