Esempio n. 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
                {
                    otherResults = MergeResults(otherResults, kvp.GetUninstallerEntries(null).ToList(), null);
                }
                catch (Exception ex)
                {
                    PremadeDialogs.GenericError(ex);
                }
            }

            return(otherResults);
        }
Esempio n. 2
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();
                }
            }
        }
        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);
        }
        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));
            }
        }
        /// <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());
            }
        }
Esempio n. 6
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();
        }
        /// <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);
                }
            }
        }
        /// <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);
                }
            }
        }
Esempio n. 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
                {
                    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);
        }
Esempio n. 11
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);
            }
        }
Esempio n. 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();
        }
 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); }
 }
 private static void OpenJunkNodePreview(IJunkResult item)
 {
     try
     {
         item.Open();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
Esempio n. 15
0
 public override void Open()
 {
     try
     {
         StartupManager.OpenStartupEntryLocations(new[] { Entry });
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
 public static void Restart()
 {
     try
     {
         UpdateSystem.RestartApplication();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
Esempio n. 17
0
 private void openLinkLocationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         StartupManager.OpenStartupEntryLocations(Selection);
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }
Esempio n. 18
0
 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);
     }
 }
Esempio n. 20
0
 private void ClearCaches(object sender, EventArgs e)
 {
     try
     {
         File.Delete(MainWindow.CertCacheFilename);
         File.Delete(UninstallToolsGlobalConfig.AppInfoCachePath);
     }
     catch (SystemException systemException)
     {
         PremadeDialogs.GenericError(systemException);
     }
 }
        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);
        }
Esempio n. 22
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 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);
     }
 }
Esempio n. 25
0
 private void WindowTargeterWindowSelected(object sender, Klocman.Subsystems.WindowHoverEventArgs e)
 {
     try
     {
         var parentDirectory = new FileInfo(e.TargetWindow.GetRunningProcess().MainModule.FileName).Directory;
         OnDirectoriesSelected(new DirectoriesSelectedEventArgs(parentDirectory.ToEnumerable().ToList()));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
         PremadeDialogs.GenericError(exception);
     }
 }
Esempio n. 26
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;
     }
 }
Esempio n. 27
0
 public static void Restart()
 {
     try
     {
         IsRestarting = true;
         UpdateSystem.RestartApplication();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
         IsRestarting = false;
     }
 }
Esempio n. 28
0
        private void CloseWizard(object sender, EventArgs e)
        {
            try
            {
                _settings.Settings.MiscFirstRun = false;
                _settings.Settings.Save();
            }
            catch (Exception ex)
            {
                PremadeDialogs.GenericError(ex);
            }

            Close();
        }
Esempio n. 29
0
 private void openFileLocationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (var item in Selection)
     {
         try
         {
             WindowsTools.OpenExplorerFocusedOnObject(item.CommandFilePath);
         }
         catch (Exception ex)
         {
             PremadeDialogs.GenericError(ex);
         }
     }
 }
Esempio n. 30
0
 private static void SetupDependancies()
 {
     // Order is semi-important, prepare settings should go first.
     Program.PrepareSettings();
     CultureConfigurator.SetupCulture();
     try
     {
         UpdateSystem.ProcessPendingUpdates();
     }
     catch (Exception ex)
     {
         PremadeDialogs.GenericError(ex);
     }
 }