コード例 #1
0
        private static IEnumerable <ApplicationUninstallerEntry> GetUpdates()
        {
            if (!HelperIsAvailable)
            {
                yield break;
            }

            var output = SteamFactory.StartProcessAndReadOutput(HelperPath, "list");

            if (string.IsNullOrEmpty(output) || output.Contains("error", StringComparison.OrdinalIgnoreCase))
            {
                yield break;
            }

            foreach (var group in ProcessInput(output))
            {
                var entry = new ApplicationUninstallerEntry
                {
                    UninstallerKind = UninstallerType.WindowsUpdate,
                    IsUpdate        = true,
                    Publisher       = "Microsoft Corporation"
                };
                foreach (var valuePair in group)
                {
                    switch (valuePair.Key)
                    {
                    case "UpdateID":
                        entry.RatingId = valuePair.Value;
                        Guid result;
                        if (GuidTools.TryExtractGuid(valuePair.Value, out result))
                        {
                            entry.BundleProviderKey = result;
                        }
                        break;

                    case "RevisionNumber":
                        entry.DisplayVersion = valuePair.Value;
                        break;

                    case "Title":
                        entry.RawDisplayName = valuePair.Value;
                        break;

                    case "IsUninstallable":
                        bool isUnins;
                        if (bool.TryParse(valuePair.Value, out isUnins))
                        {
                            entry.IsValid = isUnins;
                        }
                        break;

                    case "SupportUrl":
                        entry.AboutUrl = valuePair.Value;
                        break;

                    case "MinDownloadSize":
                        long size;
                        if (long.TryParse(valuePair.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out size))
                        {
                            entry.EstimatedSize = FileSize.FromBytes(size);
                        }
                        break;

                    case "LastDeploymentChangeTime":
                        DateTime date;
                        if (DateTime.TryParse(valuePair.Value, CultureInfo.InvariantCulture, DateTimeStyles.None, out date) &&
                            !DateTime.MinValue.Equals(date))
                        {
                            entry.InstallDate = date;
                        }
                        break;
                    }
                }

                if (entry.IsValid)
                {
                    entry.UninstallString      = $"\"{HelperPath}\" uninstall {entry.RatingId}";
                    entry.QuietUninstallString = entry.UninstallString;
                }

                yield return(entry);
            }
        }
コード例 #2
0
        public IEnumerable <ApplicationUninstallerEntry> GetUninstallerEntries(
            ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            if (!WindowsTools.CheckNetFramework4Installed(true) || !File.Exists(StoreAppHelperPath))
            {
                yield break;
            }

            var output = SteamFactory.StartProcessAndReadOutput(StoreAppHelperPath, "/query");

            if (string.IsNullOrEmpty(output))
            {
                yield break;
            }

            var windowsPath = WindowsTools.GetEnvironmentPath(CSIDL.CSIDL_WINDOWS);

            var parts   = output.SplitNewlines(StringSplitOptions.None);
            var current = parts.Take(5).ToList();

            while (current.Count == 5)
            {
                /*
                 * @"FullName: "
                 * @"DisplayName: "
                 * @"PublisherDisplayName: "
                 * @"Logo: "
                 * @"InstalledLocation: "
                 */

                //Trim the labels
                for (var i = 0; i < current.Count; i++)
                {
                    current[i] = current[i].Substring(current[i].IndexOf(" ", StringComparison.Ordinal)).Trim();
                }

                if (Directory.Exists(current[4]))
                {
                    var uninstallStr = $"\"{StoreAppHelperPath}\" /uninstall \"{current[0]}\"";
                    var result       = new ApplicationUninstallerEntry
                    {
                        RatingId             = current[0],
                        UninstallString      = uninstallStr,
                        QuietUninstallString = uninstallStr,
                        RawDisplayName       = string.IsNullOrEmpty(current[1]) ? current[0] : current[1],
                        Publisher            = current[2],
                        IsValid         = true,
                        UninstallerKind = UninstallerType.StoreApp,
                        InstallLocation = current[4],
                        InstallDate     = Directory.GetCreationTime(current[4])
                    };

                    if (File.Exists(current[3]))
                    {
                        try
                        {
                            result.DisplayIcon = current[3];
                            result.IconBitmap  = DrawingTools.IconFromImage(new Bitmap(current[3]));
                        }
                        catch
                        {
                            result.DisplayIcon = null;
                            result.IconBitmap  = null;
                        }
                    }

                    if (result.InstallLocation.StartsWith(windowsPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        result.SystemComponent = true;
                        //result.IsProtected = true;
                    }

                    yield return(result);
                }

                parts   = parts.Skip(5).ToArray();
                current = parts.Take(5).ToList();
            }
        }