public static IEnumerable <JunkNode> FindJunk(IEnumerable <ApplicationUninstallerEntry> uninstallers, IEnumerable <ApplicationUninstallerEntry> allUninstallers, ListGenerationProgress.ListGenerationCallback progressCallback) { var targetEntries = uninstallers as IList <ApplicationUninstallerEntry> ?? uninstallers.ToList(); var otherUninstallers = allUninstallers.Except(targetEntries).ToList(); var result = new List <JunkNode>(targetEntries.Count); var progress = 0; foreach (var uninstaller in targetEntries) { var progressInfo = new ListGenerationProgress(progress++, targetEntries.Count, uninstaller.DisplayName); progressInfo.Inner = new ListGenerationProgress(0, 3, "Scanning start-ups..."); progressCallback(progressInfo); var sj = new StartupJunk(uninstaller); result.AddRange(sj.FindJunk()); progressInfo.Inner = new ListGenerationProgress(1, 3, "Scanning drives..."); progressCallback(progressInfo); var dj = new DriveJunk(uninstaller, otherUninstallers); result.AddRange(dj.FindJunk()); progressInfo.Inner = new ListGenerationProgress(2, 3, "Scanning registry..."); progressCallback(progressInfo); var rj = new RegistryJunk(uninstaller, otherUninstallers); result.AddRange(rj.FindJunk()); } result.AddRange(ShortcutJunk.FindAllJunk(targetEntries, otherUninstallers)); return(result); }
public static IEnumerable <IJunkResult> FindJunk(IEnumerable <ApplicationUninstallerEntry> targets, ICollection <ApplicationUninstallerEntry> allUninstallers, ListGenerationProgress.ListGenerationCallback progressCallback) { progressCallback(new ListGenerationProgress(-1, 0, Localisation.Junk_Progress_Startup)); var scanners = ReflectionTools.GetTypesImplementingBase <IJunkCreator>() .Attempt(Activator.CreateInstance) .Cast <IJunkCreator>() .ToList(); foreach (var junkCreator in scanners) { junkCreator.Setup(allUninstallers); } var results = new List <IJunkResult>(); var targetEntries = targets as IList <ApplicationUninstallerEntry> ?? targets.ToList(); var progress = 0; foreach (var junkCreator in scanners) { var scannerProgress = new ListGenerationProgress(progress++, scanners.Count, junkCreator.CategoryName); var entryProgress = 0; foreach (var target in targetEntries) { scannerProgress.Inner = new ListGenerationProgress(entryProgress++, targetEntries.Count, target.DisplayName); progressCallback(scannerProgress); try { results.AddRange(junkCreator.FindJunk(target)); } catch (SystemException ex) { PremadeDialogs.GenericError(ex); } } } progressCallback(new ListGenerationProgress(-1, 0, Localisation.Junk_Progress_Finishing)); foreach (var target in targetEntries) { results.AddRange(target.AdditionalJunk); } return(CleanUpResults(results)); }
private void ProgressCallback(ListGenerationProgress report) { if (_cancelled) { throw new OperationCanceledException(); } lock (_thread) { if (_parentProgress == null) { _threadLastReport = report; } else { _parentProgress.Inner = report; _callback.Invoke(_parentProgress); } } }
public List <ApplicationUninstallerEntry> GetResults(ListGenerationProgress.ListGenerationCallback callback, ListGenerationProgress parentProgress) { if (parentProgress == null) { throw new ArgumentNullException(nameof(parentProgress)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } Debug.Assert(_thread != null); if (_thread.IsAlive) { lock (_thread) { _parentProgress = parentProgress; if (_threadLastReport != null) { _parentProgress.Inner = _threadLastReport; callback.Invoke(_parentProgress); } _callback = callback; } _thread.Join(); } if (_cancelled) { throw new OperationCanceledException(); } return(_threadResults ?? new List <ApplicationUninstallerEntry>()); }
public static IList <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback callback) { const int totalStepCount = 8; var currentStep = 1; // Find msi products --------------------------------------------------------------------------------------- var msiProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_MSI); callback(msiProgress); var msiGuidCount = 0; var msiProducts = MsiTools.MsiEnumProducts().DoForEach(x => { msiProgress.Inner = new ListGenerationProgress(0, -1, String.Format(Localisation.Progress_MSI_sub, ++msiGuidCount)); callback(msiProgress); }).ToList(); // Find stuff mentioned in registry ------------------------------------------------------------------------ List <ApplicationUninstallerEntry> registryResults; if (UninstallToolsGlobalConfig.ScanRegistry) { var regProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Registry); callback(regProgress); var registryFactory = new RegistryFactory(msiProducts); registryResults = registryFactory.GetUninstallerEntries(report => { regProgress.Inner = report; callback(regProgress); }).ToList(); // Fill in instal llocations for the drive search if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(registryResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, InfoAdder); } var installLocAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GatherUninstallerInfo); callback(installLocAddProgress); var installLocAddCount = 0; foreach (var result in registryResults) { installLocAddProgress.Inner = new ListGenerationProgress(installLocAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(installLocAddProgress); InfoAdder.AddMissingInformation(result, true); } } else { registryResults = new List <ApplicationUninstallerEntry>(); } // Look for entries on drives, based on info in registry. ---------------------------------------------------- // Will introduce duplicates to already detected stuff. Need to check for duplicates with other entries later. List <ApplicationUninstallerEntry> driveResults; if (UninstallToolsGlobalConfig.ScanDrives) { var driveProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_DriveScan); callback(driveProgress); var driveFactory = new DirectoryFactory(registryResults); driveResults = driveFactory.GetUninstallerEntries(report => { driveProgress.Inner = report; callback(driveProgress); }).ToList(); } else { driveResults = new List <ApplicationUninstallerEntry>(); } // Get misc entries that use fancy logic -------------------------------------------------------------------- var miscProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_AppStores); callback(miscProgress); var otherResults = GetMiscUninstallerEntries(report => { miscProgress.Inner = report; callback(miscProgress); }); // Handle duplicate entries ---------------------------------------------------------------------------------- var mergeProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Merging); callback(mergeProgress); var mergedResults = registryResults.ToList(); mergedResults = MergeResults(mergedResults, otherResults, report => { mergeProgress.Inner = report; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Stores; callback(mergeProgress); }); // Make sure to merge driveResults last mergedResults = MergeResults(mergedResults, driveResults, report => { mergeProgress.Inner = report; report.CurrentCount += report.TotalCount; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Drives; callback(mergeProgress); }); // Fill in any missing information ------------------------------------------------------------------------- if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(mergedResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, InfoAdder); } var infoAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GeneratingInfo); callback(infoAddProgress); var infoAddCount = 0; foreach (var result in mergedResults) { infoAddProgress.Inner = new ListGenerationProgress(infoAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(infoAddProgress); InfoAdder.AddMissingInformation(result); result.IsValid = CheckIsValid(result, msiProducts); } // Cache missing information to speed up future scans if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { foreach (var entry in mergedResults) { UninstallToolsGlobalConfig.UninstallerFactoryCache.TryCacheItem(entry); } try { UninstallToolsGlobalConfig.UninstallerFactoryCache.Save(); } catch (SystemException e) { Console.WriteLine(@"Failed to save cache: " + e); } } // Detect startups and attach them to uninstaller entries ---------------------------------------------------- var startupsProgress = new ListGenerationProgress(currentStep, totalStepCount, Localisation.Progress_Startup); callback(startupsProgress); var i = 0; var startupEntries = new List <StartupEntryBase>(); foreach (var factory in StartupManager.Factories) { startupsProgress.Inner = new ListGenerationProgress(i++, StartupManager.Factories.Count, factory.Key); callback(startupsProgress); try { startupEntries.AddRange(factory.Value()); } catch (Exception ex) { PremadeDialogs.GenericError(ex); } } startupsProgress.Inner = new ListGenerationProgress(1, 1, Localisation.Progress_Merging); callback(startupsProgress); try { AttachStartupEntries(mergedResults, startupEntries); } catch (Exception ex) { PremadeDialogs.GenericError(ex); } return(mergedResults); }
public static IEnumerable <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback callback) { const int totalStepCount = 8; var currentStep = 1; // Find msi products var msiProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_MSI); callback(msiProgress); var msiGuidCount = 0; var msiProducts = MsiTools.MsiEnumProducts().DoForEach(x => { msiProgress.Inner = new ListGenerationProgress(0, -1, string.Format(Localisation.Progress_MSI_sub, ++msiGuidCount)); callback(msiProgress); }).ToList(); // Find stuff mentioned in registry var regProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Registry); callback(regProgress); var registryFactory = new RegistryFactory(msiProducts); var registryResults = registryFactory.GetUninstallerEntries(report => { regProgress.Inner = report; callback(regProgress); }).ToList(); // Fill in instal llocations for the drive search var installLocAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GatherUninstallerInfo); callback(installLocAddProgress); var infoAdder = new InfoAdderManager(); var installLocAddCount = 0; foreach (var result in registryResults) { installLocAddProgress.Inner = new ListGenerationProgress(installLocAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(installLocAddProgress); infoAdder.AddMissingInformation(result, true); } // Look for entries on drives, based on info in registry. Need to check for duplicates with other entries later var driveProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_DriveScan); callback(driveProgress); var driveFactory = new DirectoryFactory(registryResults); var driveResults = driveFactory.GetUninstallerEntries(report => { driveProgress.Inner = report; callback(driveProgress); }).ToList(); // Get misc entries that use fancy logic var miscProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_AppStores); callback(miscProgress); var otherResults = GetMiscUninstallerEntries(report => { miscProgress.Inner = report; callback(miscProgress); }); // Handle duplicate entries var mergeProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Merging); callback(mergeProgress); var mergedResults = registryResults.ToList(); mergedResults = MergeResults(mergedResults, otherResults, infoAdder, report => { mergeProgress.Inner = report; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Stores; callback(mergeProgress); }); // Make sure to merge driveResults last mergedResults = MergeResults(mergedResults, driveResults, infoAdder, report => { mergeProgress.Inner = report; report.CurrentCount += report.TotalCount; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Drives; callback(mergeProgress); }); // Fill in any missing information var infoAddProgress = new ListGenerationProgress(currentStep, totalStepCount, Localisation.Progress_GeneratingInfo); callback(infoAddProgress); var infoAddCount = 0; foreach (var result in mergedResults) { infoAddProgress.Inner = new ListGenerationProgress(infoAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(infoAddProgress); infoAdder.AddMissingInformation(result); result.IsValid = CheckIsValid(result, msiProducts); } //callback(new GetUninstallerListProgress(currentStep, totalStepCount, "Finished")); return(mergedResults); }
public static IList <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback callback) { const int totalStepCount = 7; var currentStep = 1; var infoAdder = new InfoAdderManager(); // Find msi products var msiProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_MSI); callback(msiProgress); var msiGuidCount = 0; var msiProducts = MsiTools.MsiEnumProducts().DoForEach(x => { msiProgress.Inner = new ListGenerationProgress(0, -1, string.Format(Localisation.Progress_MSI_sub, ++msiGuidCount)); callback(msiProgress); }).ToList(); // Find stuff mentioned in registry List <ApplicationUninstallerEntry> registryResults; if (UninstallToolsGlobalConfig.ScanRegistry) { var regProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Registry); callback(regProgress); var registryFactory = new RegistryFactory(msiProducts); registryResults = registryFactory.GetUninstallerEntries(report => { regProgress.Inner = report; callback(regProgress); }).ToList(); // Fill in instal llocations for the drive search if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(registryResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, infoAdder); } var installLocAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GatherUninstallerInfo); callback(installLocAddProgress); var installLocAddCount = 0; foreach (var result in registryResults) { installLocAddProgress.Inner = new ListGenerationProgress(installLocAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(installLocAddProgress); infoAdder.AddMissingInformation(result, true); } } else { registryResults = new List <ApplicationUninstallerEntry>(); } // Look for entries on drives, based on info in registry. Need to check for duplicates with other entries later List <ApplicationUninstallerEntry> driveResults; if (UninstallToolsGlobalConfig.ScanDrives) { var driveProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_DriveScan); callback(driveProgress); var driveFactory = new DirectoryFactory(registryResults); driveResults = driveFactory.GetUninstallerEntries(report => { driveProgress.Inner = report; callback(driveProgress); }).ToList(); } else { driveResults = new List <ApplicationUninstallerEntry>(); } // Get misc entries that use fancy logic var miscProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_AppStores); callback(miscProgress); var otherResults = GetMiscUninstallerEntries(report => { miscProgress.Inner = report; callback(miscProgress); }); // Handle duplicate entries var mergeProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Merging); callback(mergeProgress); var mergedResults = registryResults.ToList(); mergedResults = MergeResults(mergedResults, otherResults, infoAdder, report => { mergeProgress.Inner = report; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Stores; callback(mergeProgress); }); // Make sure to merge driveResults last mergedResults = MergeResults(mergedResults, driveResults, infoAdder, report => { mergeProgress.Inner = report; report.CurrentCount += report.TotalCount; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Drives; callback(mergeProgress); }); // Fill in any missing information if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(mergedResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, infoAdder); } var infoAddProgress = new ListGenerationProgress(currentStep, totalStepCount, Localisation.Progress_GeneratingInfo); callback(infoAddProgress); var infoAddCount = 0; foreach (var result in mergedResults) { infoAddProgress.Inner = new ListGenerationProgress(infoAddCount++, registryResults.Count, result.DisplayName ?? string.Empty); callback(infoAddProgress); infoAdder.AddMissingInformation(result); result.IsValid = CheckIsValid(result, msiProducts); } //callback(new GetUninstallerListProgress(currentStep, totalStepCount, "Finished")); if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { foreach (var entry in mergedResults) { UninstallToolsGlobalConfig.UninstallerFactoryCache.TryCacheItem(entry); } try { UninstallToolsGlobalConfig.UninstallerFactoryCache.Save(); } catch (SystemException e) { Console.WriteLine(@"Failed to save cache: " + e); } } return(mergedResults); }
public static IList <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback callback) { const int totalStepCount = 8; var currentStep = 1; var concurrentFactory = new ConcurrentApplicationFactory(GetMiscUninstallerEntries); try { // Find msi products --------------------------------------------------------------------------------------- var msiProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_MSI); callback(msiProgress); var msiGuidCount = 0; var msiProducts = MsiTools.MsiEnumProducts().DoForEach(x => { msiProgress.Inner = new ListGenerationProgress(0, -1, string.Format(Localisation.Progress_MSI_sub, ++msiGuidCount)); callback(msiProgress); }).ToList(); // Run some factories in a separate thread ----------------------------------------------------------------- concurrentFactory.Start(); // Find stuff mentioned in registry ------------------------------------------------------------------------ IList <ApplicationUninstallerEntry> registryResults; if (UninstallToolsGlobalConfig.ScanRegistry) { var regProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Registry); callback(regProgress); var sw = Stopwatch.StartNew(); var registryFactory = new RegistryFactory(msiProducts); registryResults = registryFactory.GetUninstallerEntries(report => { regProgress.Inner = report; callback(regProgress); }); Console.WriteLine($"[Performance] Factory {typeof(RegistryFactory).Name} took {sw.ElapsedMilliseconds}ms to finish"); // Fill in install llocations for DirectoryFactory to improve speed and quality of results if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(registryResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, InfoAdder); } var installLocAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GatherUninstallerInfo); callback(installLocAddProgress); FactoryThreadedHelpers.GenerateMisingInformation(registryResults, InfoAdder, null, true, report => { installLocAddProgress.Inner = report; callback(installLocAddProgress); }); } else { registryResults = new List <ApplicationUninstallerEntry>(); } // Look for entries on drives, based on info in registry. ---------------------------------------------------- // Will introduce duplicates to already detected stuff. Need to check for duplicates with other entries later. IList <ApplicationUninstallerEntry> driveResults; if (UninstallToolsGlobalConfig.ScanDrives) { var driveProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_DriveScan); callback(driveProgress); var sw = Stopwatch.StartNew(); var driveFactory = new DirectoryFactory(registryResults); driveResults = driveFactory.GetUninstallerEntries(report => { driveProgress.Inner = report; callback(driveProgress); }); Console.WriteLine($"[Performance] Factory {typeof(DirectoryFactory).Name} took {sw.ElapsedMilliseconds}ms to finish"); } else { driveResults = new List <ApplicationUninstallerEntry>(); } // Join up with the thread ---------------------------------------------------------------------------------- var miscProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_AppStores); callback(miscProgress); var otherResults = concurrentFactory.GetResults(callback, miscProgress); // Handle duplicate entries ---------------------------------------------------------------------------------- var mergeProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_Merging); callback(mergeProgress); var mergedResults = registryResults.ToList(); MergeResults(mergedResults, otherResults, report => { mergeProgress.Inner = report; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Stores; callback(mergeProgress); }); // Make sure to merge driveResults last MergeResults(mergedResults, driveResults, report => { mergeProgress.Inner = report; report.CurrentCount += report.TotalCount; report.TotalCount *= 2; report.Message = Localisation.Progress_Merging_Drives; callback(mergeProgress); }); // Fill in any missing information ------------------------------------------------------------------------- if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { ApplyCache(mergedResults, UninstallToolsGlobalConfig.UninstallerFactoryCache, InfoAdder); } var infoAddProgress = new ListGenerationProgress(currentStep++, totalStepCount, Localisation.Progress_GeneratingInfo); callback(infoAddProgress); FactoryThreadedHelpers.GenerateMisingInformation(mergedResults, InfoAdder, msiProducts, false, report => { infoAddProgress.Inner = report; callback(infoAddProgress); }); // Cache missing information to speed up future scans if (UninstallToolsGlobalConfig.UninstallerFactoryCache != null) { foreach (var entry in mergedResults) { UninstallToolsGlobalConfig.UninstallerFactoryCache.TryCacheItem(entry); } try { UninstallToolsGlobalConfig.UninstallerFactoryCache.Save(); } catch (SystemException e) { Console.WriteLine(@"Failed to save cache: " + e); } } // Detect startups and attach them to uninstaller entries ---------------------------------------------------- var startupsProgress = new ListGenerationProgress(currentStep, totalStepCount, Localisation.Progress_Startup); callback(startupsProgress); var i = 0; var startupEntries = new List <StartupEntryBase>(); foreach (var factory in StartupManager.Factories) { startupsProgress.Inner = new ListGenerationProgress(i++, StartupManager.Factories.Count, factory.Key); callback(startupsProgress); try { startupEntries.AddRange(factory.Value()); } catch (Exception ex) { PremadeDialogs.GenericError(ex); } } startupsProgress.Inner = new ListGenerationProgress(1, 1, Localisation.Progress_Merging); callback(startupsProgress); try { AttachStartupEntries(mergedResults, startupEntries); } catch (Exception ex) { PremadeDialogs.GenericError(ex); } return(mergedResults); } finally { concurrentFactory.Dispose(); } }