/// <summary>
        ///     Run the uninstaller on a new thread.
        /// </summary>
        internal void RunUninstaller(RunUninstallerOptions options)
        {
            lock (_operationLock)
            {
                if (Finished || IsRunning || CurrentStatus != UninstallStatus.Waiting)
                {
                    return;
                }

                if ((UninstallerEntry.IsRegistered && !UninstallerEntry.RegKeyStillExists()) ||
                    (UninstallerEntry.UninstallerKind == UninstallerType.Msiexec &&
                     MsiTools.MsiEnumProducts().All(g => !g.Equals(UninstallerEntry.BundleProviderKey))))
                {
                    CurrentStatus = UninstallStatus.Completed;
                    Finished      = true;
                    return;
                }

                CurrentStatus = UninstallStatus.Uninstalling;
                IsRunning     = true;
            }

            var worker = new Thread(UninstallThread)
            {
                Name = "RunBulkUninstall_Worker"
            };

            worker.Start(options);
        }
        internal static X509Certificate2 TryGetCertificate(ApplicationUninstallerEntry entry)
        {
            // Don't even try if the entry is invalid, it will be marked as bad anyways
            if (!entry.IsValid)
            {
                return(null);
            }

            try
            {
                X509Certificate2 result = null;
                if (entry.SortedExecutables != null)
                {
                    result = TryExtractCertificateHelper(entry.SortedExecutables);
                }

                // Check executables before this because signatures in MSI store are modified and won't verify
                if (result == null && entry.UninstallerKind == UninstallerType.Msiexec)
                {
                    result = MsiTools.GetCertificate(entry.BundleProviderKey);
                }

                // If no certs were found finally check the uninstaller
                if (result == null && !string.IsNullOrEmpty(entry.UninstallerFullFilename))
                {
                    result = TryExtractCertificateHelper(entry.UninstallerFullFilename);
                }
                return(result);
            }
            catch
            {
                // Default to no certificate
                return(null);
            }
        }
        public IEnumerable <IJunkResult> FindJunk(ApplicationUninstallerEntry target)
        {
            if (target.RegKeyStillExists())
            {
                var regKeyNode = new RegistryKeyJunk(target.RegistryPath, target, this);
                regKeyNode.Confidence.Add(ConfidenceRecords.IsUninstallerRegistryKey);
                yield return(regKeyNode);
            }

            if (target.UninstallerKind == UninstallerType.Msiexec && !target.BundleProviderKey.IsEmpty())
            {
                var upgradeKey = MsiTools.ConvertBetweenUpgradeAndProductCode(target.BundleProviderKey).ToString("N");

                var matchedKeyPaths = _targetKeys
                                      .Where(x => x.Value.Equals(upgradeKey, StringComparison.OrdinalIgnoreCase));

                foreach (var keyPath in matchedKeyPaths)
                {
                    var fullKeyPath = Path.Combine(keyPath.Key, keyPath.Value);
                    var result      = new RegistryKeyJunk(fullKeyPath, target, this);
                    result.Confidence.Add(ConfidenceRecords.ExplicitConnection);
                    yield return(result);
                }
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var returnCode = MsiTools.VerifyMsiSignature(args[0], args[1]);

            if (returnCode != CertificateCheckReturnCodes.Success)
            {
                throw new DataException(returnCode.ToString());
            }
        }
Exemple #5
0
        /// <summary>
        ///     A valid guid is REQUIRED. It doesn't have to be set on the entry, but should be.
        /// </summary>
        private static void ApplyMsiInfo(ApplicationUninstallerEntry entry, Guid guid)
        {
            //IMPORTANT: If MsiGetProductInfo returns null it means that the guid is invalid or app is not installed
            if (MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME) == null)
            {
                return;
            }

            FillInMissingInfoMsiHelper(() => entry.RawDisplayName, x => entry.RawDisplayName = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLEDPRODUCTNAME, MsiWrapper.INSTALLPROPERTY.PRODUCTNAME);

            FillInMissingInfoMsiHelper(() => entry.DisplayVersion, x => entry.DisplayVersion = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.VERSIONSTRING, MsiWrapper.INSTALLPROPERTY.VERSION);

            FillInMissingInfoMsiHelper(() => entry.Publisher, x => entry.Publisher = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.PUBLISHER);

            FillInMissingInfoMsiHelper(() => entry.InstallLocation, x => entry.InstallLocation = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLLOCATION);

            FillInMissingInfoMsiHelper(() => entry.InstallSource, x => entry.InstallSource = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.INSTALLSOURCE);

            FillInMissingInfoMsiHelper(() => entry.UninstallerFullFilename, x => entry.UninstallerFullFilename = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.LOCALPACKAGE);

            FillInMissingInfoMsiHelper(() => entry.DisplayIcon, x => entry.DisplayIcon = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.PRODUCTICON);

            FillInMissingInfoMsiHelper(() => entry.AboutUrl, x => entry.AboutUrl = x, guid,
                                       MsiWrapper.INSTALLPROPERTY.HELPLINK, MsiWrapper.INSTALLPROPERTY.URLUPDATEINFO,
                                       MsiWrapper.INSTALLPROPERTY.URLINFOABOUT);

            if (!entry.InstallDate.IsDefault())
            {
                return;
            }
            var temp = MsiTools.MsiGetProductInfo(guid, MsiWrapper.INSTALLPROPERTY.INSTALLDATE);

            if (!temp.IsNotEmpty())
            {
                return;
            }
            try
            {
                entry.InstallDate = new DateTime(int.Parse(temp.Substring(0, 4)),
                                                 int.Parse(temp.Substring(4, 2)),
                                                 int.Parse(temp.Substring(6, 2)));
            }
            catch
            {
                // Date had invalid format, default to nothing
            }
        }
Exemple #6
0
        /// <summary>
        ///     Run the uninstaller on a new thread.
        /// </summary>
        internal void RunUninstaller(RunUninstallerOptions options)
        {
            lock (_operationLock)
            {
                if (Finished || IsRunning || CurrentStatus != UninstallStatus.Waiting)
                {
                    return;
                }

                if (UninstallerEntry.IsRegistered && !UninstallerEntry.RegKeyStillExists())
                {
                    CurrentStatus = UninstallStatus.Completed;
                    Finished      = true;
                    return;
                }

                if (UninstallerEntry.UninstallerKind == UninstallerType.Msiexec)
                {
                    var uninstallString = IsSilentPossible && UninstallerEntry.QuietUninstallPossible
                        ? UninstallerEntry.QuietUninstallString
                        : UninstallerEntry.UninstallString;

                    // Always reenumerate products in case any were uninstalled
                    if (ApplicationEntryTools.PathPointsToMsiExec(uninstallString) &&
                        MsiTools.MsiEnumProducts().All(g => !g.Equals(UninstallerEntry.BundleProviderKey)))
                    {
                        CurrentStatus = UninstallStatus.Completed;
                        Finished      = true;
                        return;
                    }
                }

                CurrentStatus = UninstallStatus.Uninstalling;

                try
                {
                    _worker = new Thread(UninstallThread)
                    {
                        Name = "RunBulkUninstall_Worker", IsBackground = false
                    };
                    _worker.Start(options);
                }
                catch
                {
                    CurrentStatus = UninstallStatus.Failed;
                    Finished      = true;
                    throw;
                }
            }
        }
Exemple #7
0
        private static void FillInMissingInfoMsiHelper(Func <string> get, Action <string> set, Guid guid,
                                                       params MsiWrapper.INSTALLPROPERTY[] properties)
        {
            if (string.IsNullOrEmpty(get()))
            {
                foreach (var item in properties)
                {
                    var temp = MsiTools.MsiGetProductInfo(guid, item);

                    //IMPORTANT: Do not assign empty strings, they will mess up automatic property creation later on.
                    if (temp.IsNotEmpty())
                    {
                        set(temp);
                    }
                }
            }
        }
        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);
        }
Exemple #11
0
        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();
            }
        }
 internal static void PopulateWindowsInstallerValidGuids()
 {
     WindowsInstallerValidGuids = MsiTools.MsiEnumProducts();
 }
Exemple #13
0
        public void Signed3shapeButWrongDNSName()
        {
            var returnCode = MsiTools.VerifyMsiSignature($"{_testProjectFolder}/data/Signed3Shape.dll", "Wrong name");

            Assert.AreEqual(CertificateCheckReturnCodes.ValidMsiButSignatureDnsNameMismatch, returnCode);
        }
Exemple #14
0
        public void Signed3shape()
        {
            var returnCode = MsiTools.VerifyMsiSignature($"{_testProjectFolder}/data/Signed3Shape.dll", "3Shape A/S");

            Assert.AreEqual(CertificateCheckReturnCodes.Success, returnCode);
        }
Exemple #15
0
        public void NotSigned()
        {
            var returnCode = MsiTools.VerifyMsiSignature($"{_testProjectFolder}/data/NotSigned.dll", "3Shape A/S");

            Assert.AreEqual(CertificateCheckReturnCodes.DoesNotPassAuthenticodeVerification, returnCode);
        }