public RegistryEntry(string fullPath, string keyName, RegDataType dataType, object defaultValue = null, string comparer = "", Int64 min = Int64.MinValue, Int64 max = Int64.MaxValue) { if (fullPath.StartsWith("HKEY_CLASSES_ROOT") || fullPath.StartsWith("HKCR")) { Hive = RegistryHive.HKEY_CLASSES_ROOT; } else if (fullPath.StartsWith("HKEY_LOCAL_MACHINE") || fullPath.StartsWith("HKLM")) { Hive = RegistryHive.HKEY_LOCAL_MACHINE; } else if (fullPath.StartsWith("HKEY_CURRENT_USER") || fullPath.StartsWith("HKCU")) { Hive = RegistryHive.HKEY_CURRENT_USER; } else if (fullPath.Contains("HKEY_CURRENT_CONFIG") || fullPath.Contains("HKCC")) { Hive = RegistryHive.HKEY_CURRENT_CONFIG; } KeyPath = fullPath.Substring(fullPath.IndexOf('\\') + 1); KeyName = keyName; DataType = dataType; DefaultValue = defaultValue; Comparer = comparer; Min = min; Max = max; IsInteropUnlocked(); }
public RegistryEntry(string fullPath, string keyName, RegDataType dataType, object defaultValue = null, string comparer = "", Int64 min = Int64.MinValue, Int64 max = Int64.MaxValue) { if (fullPath.StartsWith("HKEY_CLASSES_ROOT") || fullPath.StartsWith("HKCR")) Hive = RegistryHive.HKEY_CLASSES_ROOT; else if (fullPath.StartsWith("HKEY_LOCAL_MACHINE") || fullPath.StartsWith("HKLM")) Hive = RegistryHive.HKEY_LOCAL_MACHINE; else if (fullPath.StartsWith("HKEY_CURRENT_USER") || fullPath.StartsWith("HKCU")) Hive = RegistryHive.HKEY_CURRENT_USER; else if (fullPath.Contains("HKEY_CURRENT_CONFIG") || fullPath.Contains("HKCC")) Hive = RegistryHive.HKEY_CURRENT_CONFIG; KeyPath = fullPath.Substring(fullPath.IndexOf('\\') + 1); KeyName = keyName; DataType = dataType; DefaultValue = defaultValue; Comparer = comparer; Min = min; Max = max; IsInteropUnlocked(); }
public static dynamic FromString(string data, RegDataType dataType) { switch (dataType) { case RegDataType.REG_SZ: case RegDataType.REG_MULTI_SZ: return data; case RegDataType.REG_DWORD: return Convert.ToUInt32(string.IsNullOrEmpty(data) ? "0" : data, 16); case RegDataType.REG_QWORD: return Convert.ToUInt64(string.IsNullOrEmpty(data) ? "0" : data, 16); case RegDataType.REG_BINARY: data = data.Replace("-", ""); return Enumerable.Range(0, data.Length).Where(x => x % 2 == 0).Select(x => Convert.ToByte(data.Substring(x, 2), 16)).ToArray(); default: return 0; } }
public static dynamic FromString(string data, RegDataType dataType) { switch (dataType) { case RegDataType.REG_SZ: case RegDataType.REG_MULTI_SZ: return(data); case RegDataType.REG_DWORD: return(Convert.ToUInt32(string.IsNullOrEmpty(data) ? "0" : data, 16)); case RegDataType.REG_QWORD: return(Convert.ToUInt64(string.IsNullOrEmpty(data) ? "0" : data, 16)); case RegDataType.REG_BINARY: data = data.Replace("-", ""); return(Enumerable.Range(0, data.Length).Where(x => x % 2 == 0).Select(x => Convert.ToByte(data.Substring(x, 2), 16)).ToArray()); default: return(0); } }
public static string ToString(object data, RegDataType dataType) { switch (dataType) { case RegDataType.REG_SZ: return data as string; case RegDataType.REG_MULTI_SZ: return data as string; case RegDataType.REG_DWORD: return String.Format("{0:X}", data); case RegDataType.REG_QWORD: return String.Format("{0:X}", data); case RegDataType.REG_BINARY: return BitConverter.ToString(data as byte[], 0); default: return string.Empty; } }
public static string ToString(object data, RegDataType dataType) { switch (dataType) { case RegDataType.REG_SZ: return(data as string); case RegDataType.REG_MULTI_SZ: return(data as string); case RegDataType.REG_DWORD: return(String.Format("{0:X}", data)); case RegDataType.REG_QWORD: return(String.Format("{0:X}", data)); case RegDataType.REG_BINARY: return(BitConverter.ToString(data as byte[], 0)); default: return(string.Empty); } }
public Tweak(XElement xml) { if (xml.Attribute("category") == null) { throw new AttributeMissingException("category", "tweak"); } if (xml.Attribute("name") == null) { throw new AttributeMissingException("name", "tweak"); } if (xml.Attribute("type") == null) { throw new AttributeMissingException("type", "tweak"); } Category = xml.Attribute("category").Value; Name = xml.Attribute("name").Value; try { Type = (TweakType)Array.IndexOf(TweakNames.TweakTypeNames, xml.Attribute("type").Value); } catch { throw new Exception(string.Format("Error: unknown \"type\" value for the tweak \"{0}\"", Name)); } Description = xml.Attribute("description") != null?xml.Attribute("description").Value : string.Empty; RequireReboot = (xml.Attribute("reboot") != null && xml.Attribute("reboot").Value.Equals("true")) ? 1 : 0; InputHelper = xml.Attribute("helper") != null?xml.Attribute("helper").Value : string.Empty; var xmlEntries = xml.Descendants("entry"); if (xmlEntries == null || xmlEntries.Count() == 0) { throw new Exception(string.Format("Error: no registry entries found for the tweak \"{0}\"", Name)); } foreach (var xmlEntry in xmlEntries) { if (xmlEntry.Attribute("path") == null) { throw new AttributeMissingException("path", "entry"); } if (xmlEntry.Attribute("name") == null) { throw new AttributeMissingException("name", "entry"); } if (xmlEntry.Attribute("type") == null) { throw new AttributeMissingException("type", "entry"); } string entryPath = xmlEntry.Attribute("path").Value; string entryName = xmlEntry.Attribute("name").Value; string entryType = xmlEntry.Attribute("type").Value; string entryComparer = xmlEntry.Attribute("comparer") != null?xmlEntry.Attribute("comparer").Value : string.Empty; Int64 min = Int64.MinValue; Int64 max = Int64.MaxValue; if (Type == TweakType.Input) { if (xmlEntry.Attribute("min") != null) { Int64.TryParse(xmlEntry.Attribute("min").Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out min); } if (xmlEntry.Attribute("max") != null) { Int64.TryParse(xmlEntry.Attribute("max").Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out max); } } RegDataType dataType = RegistryEntry.DataTypeFromString(entryType); if (dataType == RegDataType.REG_UNKNOWN) { throw new Exception(string.Format("Error, invalid data type \"{0}\" for the entry value", entryType)); } var defValue = xmlEntry.Attribute("default") != null?DataConverter.FromString(xmlEntry.Attribute("default").Value, dataType) : null; var regEntry = new RegistryEntry(entryPath, entryName, dataType, defValue, entryComparer, min, max); var values = new List <RegValue>(); var xmlValues = xmlEntry.Descendants("value"); if (xmlValues == null) { throw new Exception("Error: no values found for the registry entry"); } else if (xmlValues.Count() > 1 && Type == TweakType.Input) { throw new Exception(string.Format("Error: too many values for the tweak type {0}", Type)); } else { foreach (var xmlValue in xmlValues) { string valueDisplayName = (xmlValue.Attribute("name") != null) ? xmlValue.Attribute("name").Value : string.Empty; values.Add(new RegValue(DataConverter.FromString(xmlValue.Value, dataType), valueDisplayName)); } } Entries.Add(new TweakEntry(regEntry, values)); } }