/// <summary> /// Gets an enumerable of the available sub keys full paths /// </summary> /// <param name="registryKey">The registry key</param> /// <returns>The enumerable of the available sub keys full paths</returns> public static IEnumerable <string> GetSubKeyFullPaths(this RegistryKey registryKey) { // Get the sub key names var names = registryKey.GetSubKeyNames(); // Combines their names with the current key path return(names.Select(x => RegistryHelpers.CombinePaths(registryKey.Name, x))); }
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); }
/// <summary> /// Renames the specified sub key /// </summary> /// <param name="registryKey">The parent registry key</param> /// <param name="subKeyName">The name of the sub key to rename</param> /// <param name="newSubKeyName">The new name of the key</param> public static void MoveSubKey(this RegistryKey registryKey, string subKeyName, string newSubKeyName) { // Make sure the new name doesn't exist if (RegistryHelpers.KeyExists(RegistryHelpers.CombinePaths(registryKey.Name, newSubKeyName), registryKey.View)) { throw new Exception($"The key {newSubKeyName} already exists"); } // Make sure the original key exists if (!RegistryHelpers.KeyExists(RegistryHelpers.CombinePaths(registryKey.Name, subKeyName), registryKey.View)) { throw new Exception($"The key {subKeyName} does not exist"); } try { // Copy the key registryKey.CopySubKey(subKeyName, newSubKeyName); } catch (Exception ex) { // Delete copied key registryKey.DeleteSubKeyTree(newSubKeyName, false); throw new Exception("Failed to copy sub key tree. Operation failed.", ex); } try { // Delete the old key registryKey.DeleteSubKeyTree(subKeyName); } catch (Exception ex) { throw new Exception("Failed to fully delete old key", ex); } }