コード例 #1
0
 /// <summary>
 /// Creates a new <see cref="RegistryValue"/> from a key path, the value name and view used to get the key
 /// </summary>
 /// <param name="keyPath">The full path of the key</param>
 /// <param name="valueName">The name of the value</param>
 /// <param name="view">The view used to get the key</param>
 public RegistryValue(string keyPath, string valueName, RegistryView view)
 {
     using (var key = RegistryHelpers.GetKeyFromFullPath(keyPath, view))
     {
         Value     = key.GetValue(valueName);
         ValueKind = key.GetValueKind(valueName);
         Name      = valueName;
         KeyPath   = key.Name;
         KeyView   = key.View;
     }
 }
コード例 #2
0
    public override async Task <FileSystemPath?> LocateAsync()
    {
        FileSystemPath installDir;

        try
        {
            // Get the key path
            var keyPath = RegistryHelpers.CombinePaths(AppFilePaths.UninstallRegistryKey, $"Steam App {SteamID}");

            using var key = RegistryHelpers.GetKeyFromFullPath(keyPath, RegistryView.Registry64);

            // Get the install directory
            if (!(key?.GetValue("InstallLocation") is string dir))
            {
                Logger.Info("The {0} was not found under Steam Apps", Game);

                await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error);

                return(null);
            }

            installDir = dir;
        }
        catch (Exception ex)
        {
            Logger.Error(ex, "Getting Steam game install directory");

            await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error);

            return(null);
        }

        // Make sure the game is valid
        if (!await IsValidAsync(installDir))
        {
            Logger.Info("The {0} install directory was not valid", Game);

            await Services.MessageUI.DisplayMessageAsync(Resources.LocateGame_InvalidSteamGame, Resources.LocateGame_InvalidSteamGameHeader, MessageType.Error);

            return(null);
        }

        return(installDir);
    }
コード例 #3
0
    protected virtual IEnumerable <InstalledProgram> EnumerateRegistryUninstallPrograms()
    {
        Logger.Info("Getting installed programs from the Registry");

        // Get 64-bit location if on 64-bit system
        var keys = Environment.Is64BitOperatingSystem
            ? new RegistryKey[]
        {
            RegistryHelpers.GetKeyFromFullPath(AppFilePaths.UninstallRegistryKey,
                                               RegistryView.Registry32),
            RegistryHelpers.GetKeyFromFullPath(AppFilePaths.UninstallRegistryKey,
                                               RegistryView.Registry64)
        }
            : new RegistryKey[]
        {
            RegistryHelpers.GetKeyFromFullPath(AppFilePaths.UninstallRegistryKey,
                                               RegistryView.Registry32),
        };

        // Enumerate the uninstall keys
        foreach (var key in keys)
        {
            // Dispose key when done
            using RegistryKey registryKey = key;

            // Enumerate the sub keys
            foreach (string subKeyName in registryKey.GetSubKeyNames())
            {
                // Make sure it's not a Windows update
                if (subKeyName.StartsWith("KB") && subKeyName.Length == 8)
                {
                    continue;
                }

                // Open the sub key
                using RegistryKey subKey = registryKey.OpenSubKey(subKeyName);

                // Make sure the key is not null
                if (subKey == null)
                {
                    continue;
                }

                // Make sure it is not a system component
                if (subKey.GetValue("SystemComponent") as int? == 1)
                {
                    continue;
                }

                if (subKey.GetValue("WindowsInstaller") as int? == 1)
                {
                    continue;
                }

                // Make sure it has an uninstall string
                if (subKey.GetValue("UninstallString") == null)
                {
                    continue;
                }

                if (subKey.GetValue("ParentKeyName") != null)
                {
                    continue;
                }

                // Make sure it has a display name
                if (subKey.GetValue("DisplayName") is not string dn)
                {
                    continue;
                }

                // Make sure it has an install location
                if (subKey.GetValue("InstallLocation") is not string dir)
                {
                    continue;
                }

                yield return(new InstalledProgram(dn, subKey.Name, dir));
            }
        }
    }
コード例 #4
0
 /// <summary>
 /// Gets the key containing the value
 /// </summary>
 /// <param name="writable">True if the key should be writable</param>
 /// <returns>The key containing the value</returns>
 public RegistryKey GetKey(bool writable = false) =>
 RegistryHelpers.GetKeyFromFullPath(KeyPath, KeyView, writable);
コード例 #5
0
 /// <summary>
 /// Gets the parent key
 /// </summary>
 /// <param name="registryKey">The registry key</param>
 /// <param name="writable">True if the key should be writable</param>
 /// <returns>The parent key</returns>
 public static RegistryKey GetParentKey(this RegistryKey registryKey, bool writable = false)
 {
     return(RegistryHelpers.GetKeyFromFullPath(RegistryHelpers.GetParentKeyPath(registryKey.Name), registryKey.View, writable));
 }