Beispiel #1
0
        public static ICollection <ApplicationUninstallerEntry> GetApplicationsFromDirectories(
            IEnumerable <ApplicationUninstallerEntry> allUninstallers, ICollection <DirectoryInfo> results)
        {
            var output    = new List <ApplicationUninstallerEntry>();
            var processed = new List <DirectoryInfo>();

            foreach (var dir in results.Distinct(PathTools.PathsEqual).OrderBy(x => x.FullName))
            {
                if (processed.Any(x => x.FullName.Contains(dir.FullName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    continue;
                }

                processed.Add(dir);
            }

            var exceptions = allUninstallers.Where(x => x.InstallLocation != null).ToList();

            var infoAdder = new InfoAdderManager();

            foreach (var dir in processed)
            {
                var items = exceptions.Where(
                    x => x.InstallLocation.Contains(dir.FullName, StringComparison.InvariantCultureIgnoreCase))
                            .ToList();

                if (items.Count > 0)
                {
                    output.AddRange(items);
                    continue;
                }

                var res = DirectoryFactory.TryCreateFromDirectory(dir, exceptions).ToList();
                if (res.Count == 0)
                {
                    MessageBox.Show(
                        string.Format(Localisable.Uninstaller_GetApplicationsFromDirectories_NothingFound_Message,
                                      dir.FullName), Localisable.Uninstaller_GetApplicationsFromDirectories_NothingFound_Title,
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    continue;
                }

                foreach (var result in res)
                {
                    infoAdder.AddMissingInformation(result);
                    output.Add(result);
                }
            }

            return(output);
        }
Beispiel #2
0
        public static void GenerateMisingInformation(List <ApplicationUninstallerEntry> entries,
                                                     InfoAdderManager infoAdder, List <Guid> msiProducts, bool skipRunLast,
                                                     ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            void WorkLogic(ApplicationUninstallerEntry entry, object state)
            {
                infoAdder.AddMissingInformation(entry, skipRunLast);
                if (msiProducts != null)
                {
                    entry.IsValid = FactoryTools.CheckIsValid(entry, msiProducts);
                }
            }

            var workSpreader = new ThreadedWorkSpreader <ApplicationUninstallerEntry, object>(MaxThreadsPerDrive,
                                                                                              WorkLogic, list => null, entry => entry.DisplayName ?? entry.RatingId ?? string.Empty);

            var cDrive       = new DirectoryInfo(Environment.SystemDirectory).Root;
            var dividedItems = SplitByPhysicalDrives(entries, entry =>
            {
                var loc = entry.InstallLocation ?? entry.UninstallerLocation;
                if (!string.IsNullOrEmpty(loc))
                {
                    try
                    {
                        return(new DirectoryInfo(loc));
                    }
                    catch (SystemException ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
                return(cDrive);
            });

            workSpreader.Start(dividedItems, progressCallback);
            workSpreader.Join();
        }
 private static void ApplyCache(List <ApplicationUninstallerEntry> baseEntries, ApplicationUninstallerFactoryCache cache, InfoAdderManager infoAdder)
 {
     foreach (var entry in baseEntries)
     {
         var matchedEntry = cache.TryGetCachedItem(entry);
         if (matchedEntry != null)
         {
             infoAdder.CopyMissingInformation(entry, matchedEntry);
         }
     }
 }
        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);
        }
        private static List <ApplicationUninstallerEntry> MergeResults(ICollection <ApplicationUninstallerEntry> baseEntries,
                                                                       ICollection <ApplicationUninstallerEntry> newResults, InfoAdderManager infoAdder, ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            // Create local copy
            //var baseEntries = baseResults.ToList();
            // Add all of the base results straight away
            var results  = new List <ApplicationUninstallerEntry>(baseEntries);
            var progress = 0;

            foreach (var entry in newResults)
            {
                progressCallback(new ListGenerationProgress(progress++, newResults.Count, null));

                var matchedEntries = baseEntries.Where(x => CheckAreEntriesRelated(x, entry)).Take(2).ToList();
                if (matchedEntries.Count == 1)
                {
                    // Prevent setting incorrect UninstallerType
                    if (matchedEntries[0].UninstallPossible)
                    {
                        entry.UninstallerKind = UninstallerType.Unknown;
                    }

                    infoAdder.CopyMissingInformation(matchedEntries[0], entry);
                    continue;
                }

                // If the entry failed to match to anything, add it to the results
                results.Add(entry);
            }

            return(results);
        }
        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);
        }
Beispiel #7
0
        private static void ApplyCache(ICollection <ApplicationUninstallerEntry> baseEntries, ApplicationUninstallerFactoryCache cache, InfoAdderManager infoAdder)
        {
            var hits = 0;

            foreach (var entry in baseEntries)
            {
                var matchedEntry = cache.TryGetCachedItem(entry);
                if (matchedEntry != null)
                {
                    infoAdder.CopyMissingInformation(entry, matchedEntry);
                    hits++;
                }
                else
                {
                    Debug.WriteLine("Cache miss: " + entry.DisplayName);
                }
            }
            Console.WriteLine($@"Cache hits: {hits}/{baseEntries.Count}");
        }