コード例 #1
0
        public IList <ApplicationUninstallerEntry> GetUninstallerEntries(
            ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            var results = new List <ApplicationUninstallerEntry>();

            if (StoreAppHelperPath == null)
            {
                return(results);
            }

            var output = FactoryTools.StartHelperAndReadOutput(StoreAppHelperPath, "/query");

            if (string.IsNullOrEmpty(output))
            {
                return(results);
            }

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

            foreach (var data in FactoryTools.ExtractAppDataSetsFromHelperOutput(output))
            {
                if (!data.ContainsKey("InstalledLocation") || !Directory.Exists(data["InstalledLocation"]))
                {
                    continue;
                }

                var fullName     = data["FullName"];
                var uninstallStr = $"\"{StoreAppHelperPath}\" /uninstall \"{fullName}\"";
                var isProtected  = data.ContainsKey("IsProtected") && Convert.ToBoolean(data["IsProtected"], CultureInfo.InvariantCulture);
                var result       = new ApplicationUninstallerEntry
                {
                    Comment              = fullName,
                    CacheIdOverride      = fullName,
                    RatingId             = fullName.Substring(0, fullName.IndexOf("_", StringComparison.Ordinal)),
                    UninstallString      = uninstallStr,
                    QuietUninstallString = uninstallStr,
                    RawDisplayName       = string.IsNullOrEmpty(data["DisplayName"]) ? fullName : data["DisplayName"],
                    Publisher            = data["PublisherDisplayName"],
                    IsValid              = true,
                    UninstallerKind      = UninstallerType.StoreApp,
                    InstallLocation      = data["InstalledLocation"],
                    InstallDate          = Directory.GetCreationTime(data["InstalledLocation"]),
                    IsProtected          = isProtected,
                    SystemComponent      = isProtected
                };

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

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

                results.Add(result);
            }

            return(results);
        }
コード例 #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();
            }
        }