2021-04-25 22:59:36 -05:00
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
2021-05-26 11:26:08 -05:00
|
|
|
namespace ZuneModCore.Win32
|
2021-04-25 22:59:36 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CA1416 // Validate platform compatibility
|
|
|
|
|
|
|
|
|
|
public class RegEdit
|
|
|
|
|
{
|
|
|
|
|
public const string ZUNE_REG_PATH = @"SOFTWARE\Microsoft\Zune\";
|
|
|
|
|
|
2021-05-06 02:36:14 -05:00
|
|
|
public static bool CurrentUserSetBoolValue(string key, string name, bool value)
|
2021-04-25 22:59:36 -05:00
|
|
|
{
|
|
|
|
|
RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
|
|
|
|
|
if (regKey == null)
|
|
|
|
|
regKey = Registry.CurrentUser.CreateSubKey(key, true);
|
|
|
|
|
|
|
|
|
|
regKey.SetValue(name, value, RegistryValueKind.DWord);
|
|
|
|
|
regKey.Close();
|
|
|
|
|
regKey.Dispose();
|
2021-05-06 02:36:14 -05:00
|
|
|
|
|
|
|
|
// Read the key to make sure it was set properly
|
|
|
|
|
if (CurrentUserGetBoolValue(key, name) == null)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2021-04-25 22:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
2021-05-06 02:36:14 -05:00
|
|
|
public static bool? CurrentUserGetBoolValue(string key, string name)
|
2021-04-25 22:59:36 -05:00
|
|
|
{
|
|
|
|
|
using RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
|
|
|
|
|
if (regKey == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-05-06 02:36:14 -05:00
|
|
|
// Return null if a boolean value couldn't be read from the key
|
2021-04-25 22:59:36 -05:00
|
|
|
int? value = regKey.GetValue(name, false) as int?;
|
2021-05-06 02:36:14 -05:00
|
|
|
if (!value.HasValue)
|
|
|
|
|
return null;
|
|
|
|
|
return value != 0;
|
2021-04-25 22:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CurrentUserDeleteKey(string key)
|
|
|
|
|
{
|
|
|
|
|
using RegistryKey? targetKey = Registry.CurrentUser.OpenSubKey(key, true);
|
|
|
|
|
if (targetKey == null)
|
|
|
|
|
// Key is already deleted
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-29 16:15:18 -06:00
|
|
|
// Delete target subkeys
|
|
|
|
|
if (targetKey.SubKeyCount > 0)
|
|
|
|
|
targetKey.DeleteSubKeyTree(key, false);
|
|
|
|
|
|
|
|
|
|
// Delete target values
|
|
|
|
|
string[] values = targetKey.GetValueNames();
|
|
|
|
|
foreach (string value in values)
|
|
|
|
|
targetKey.DeleteValue(value, false);
|
2021-04-25 22:59:36 -05:00
|
|
|
|
|
|
|
|
// Delete target key
|
2021-12-29 16:15:18 -06:00
|
|
|
Registry.CurrentUser.DeleteSubKey(key);
|
2021-04-25 22:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CurrentUserDeleteValue(string key, string name)
|
|
|
|
|
{
|
|
|
|
|
using RegistryKey? regKey = Registry.CurrentUser.OpenSubKey(key, true);
|
|
|
|
|
if (regKey == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-04-26 17:02:21 -05:00
|
|
|
regKey.DeleteValue(name, false);
|
2021-04-25 22:59:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma warning restore CA1416 // Validate platform compatibility
|
|
|
|
|
|
|
|
|
|
}
|