Exemple #1
0
        public IEnumerable <ApplicationUninstallerEntry> GetUninstallerEntries(ListGenerationProgress.ListGenerationCallback progressCallback)
        {
            if (!HelperAvailable)
            {
                yield break;
            }

            var output = FactoryTools.StartProcessAndReadOutput(HelperPath, "/query");

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

            foreach (var data in FactoryTools.ExtractAppDataSetsFromHelperOutput(output))
            {
                if (!data.ContainsKey("CanonicalName"))
                {
                    continue;
                }
                var name = data["CanonicalName"];
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                var uninstallStr = $"\"{HelperPath}\" /uninstall {name}";

                var entry = new ApplicationUninstallerEntry
                {
                    RatingId = name,
                    //RegistryKeyName = name,
                    UninstallString      = uninstallStr,
                    QuietUninstallString = uninstallStr,
                    IsValid         = true,
                    UninstallerKind = UninstallerType.Oculus,
                    InstallLocation = data["InstallLocation"],
                    InstallDate     = Directory.GetCreationTime(data["InstallLocation"]),
                    DisplayVersion  = data["Version"],
                    IsProtected     = "true".Equals(data["IsCore"], StringComparison.OrdinalIgnoreCase),
                };

                var executable = data["LaunchFile"];
                if (File.Exists(executable))
                {
                    ExecutableAttributeExtractor.FillInformationFromFileAttribs(entry, executable, true);
                }

                if (string.IsNullOrEmpty(entry.RawDisplayName))
                {
                    entry.RawDisplayName = name.Replace('-', ' ').ToTitleCase();
                }

                yield return(entry);
            }
        }
        private static void CreateFromDirectoryHelper(ICollection <ApplicationUninstallerEntry> results,
                                                      DirectoryInfo directory, int level, ICollection <string> dirsToSkip)
        {
            // Level 0 is for the pf folder itself. First subfolder is level 1.
            if (level > 2 || dirsToSkip.Any(x => directory.FullName.Contains(x, StringComparison.InvariantCultureIgnoreCase)))
            {
                return;
            }

            // Get contents of this installDir
            AppExecutablesSearcher.ScanDirectoryResult result;

            try
            {
                result = AppExecutablesSearcher.ScanDirectory(directory);
            }
            catch (IOException)
            {
                return;
            }
            catch (UnauthorizedAccessException)
            {
                return;
            }

            // Check if it is potentially dangerous to process this installDir.
            if (result.ExecutableFiles.Count > 40)
            {
                return;
            }

            var anyFiles = result.ExecutableFiles.Any();

            if (!anyFiles && !result.BinSubdirs.Any())
            {
                foreach (var dir in result.OtherSubdirs)
                {
                    CreateFromDirectoryHelper(results, dir, level + 1, dirsToSkip);
                }
            }
            else if (anyFiles)
            {
                var entry = new ApplicationUninstallerEntry();

                // Parse directories into useful information
                if (level > 0 && directory.Name.StartsWithAny(AppExecutablesSearcher.BinaryDirectoryNames, StringComparison.OrdinalIgnoreCase))
                {
                    entry.InstallLocation = directory.Parent?.FullName;
                    entry.RawDisplayName  = directory.Parent?.Name;
                }
                else
                {
                    entry.InstallLocation = directory.FullName;
                    entry.RawDisplayName  = directory.Name;

                    if (level > 0)
                    {
                        entry.Publisher = directory.Parent?.Name;
                    }
                }

                var sorted = AppExecutablesSearcher.SortListExecutables(result.ExecutableFiles, entry.DisplayNameTrimmed).ToArray();
                entry.SortedExecutables = sorted.Select(x => x.FullName).ToArray();

                entry.InstallDate = directory.CreationTime;
                //entry.IconBitmap = TryExtractAssociatedIcon(compareBestMatchFile.FullName);

                // Extract info from file metadata and overwrite old values
                var compareBestMatchFile = sorted.First();
                ExecutableAttributeExtractor.FillInformationFromFileAttribs(entry, compareBestMatchFile.FullName, false);

                results.Add(entry);
            }
        }