public static void registryFix(string registryHiveName, string value) //Пишет в реестр путь, исправдяя ошибки { RegistryKey key = null; try { if (Environment.Is64BitOperatingSystem) { RegistryKey reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Wow6432Node\\Bethesda Softworks\"); key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Wow6432Node\" + registryHiveName); key.SetValue("Installed Path", value); key.Close(); } else { RegistryKey reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\\Bethesda Softworks\"); key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\" + registryHiveName); key.SetValue("Installed Path", value); key.Close(); } } catch (Exception) { RegistryException ex = new RegistryException(key.ToString()); throw ex; } }
/// <summary> /// Set a string value to be written to the <see cref="IRegistry" /> after <see cref="Apply" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="value"> The value to store in the <see cref="IRegistry" />. </param> /// <returns> A reference to this <see cref="IRegistryEditor" /> instance that can be used to chain calls together. </returns> public IRegistryEditor SetString(string key, string value) { if (string.IsNullOrWhiteSpace(key)) { throw RegistryException.InvalidKeyException(key); } this.newValues[key] = value; return(this); }
/// <summary> /// Set a double value to be written to the <see cref="IRegistry" /> after <see cref="Apply" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="value"> The value to store in the <see cref="IRegistry" />. </param> /// <returns> A reference to this <see cref="IRegistryEditor" /> instance that can be used to chain calls together. </returns> public IRegistryEditor SetDouble(string key, double value) { if (string.IsNullOrWhiteSpace(key)) { throw RegistryException.InvalidKeyException(key); } this.newValues[key] = value.ToString(CultureInfo.InvariantCulture); return(this); }
/// <summary> /// Marks a value for deletion from the <see cref="IRegistry" /> after <see cref="Apply" />. Will be applied before any /// sets /// in the same batch from this editor. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <returns> A reference to this <see cref="IRegistryEditor" /> instance that can be used to chain calls together. </returns> public IRegistryEditor Remove(string key) { if (string.IsNullOrWhiteSpace(key)) { throw RegistryException.InvalidKeyException(key); } this.valuesToRemove.Add(key); return(this); }
private bool TryGetValue(string key, out string value) { if (string.IsNullOrWhiteSpace(key)) { throw RegistryException.InvalidKeyException(key); } value = this.GetValue(key); return(value != null); }
/// <summary> /// Gets a bool value from the <see cref="IRegistry" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="defaultValue"> The default value to return if the specified key is not found. </param> /// <exception cref="ArgumentException"> /// Thrown when the value stored with the specified key is not compatible with the /// requested type. /// </exception> /// <returns> The value stored in the registry with the specified key, or the given default value if not found. </returns> public bool GetBool(string key, bool defaultValue) { string valStr; if (!this.TryGetValue(key, out valStr)) { return(defaultValue); } bool ret; if (bool.TryParse(valStr, out ret)) { return(ret); } throw RegistryException.RegistryValueNotFoundException(key, typeof(bool)); }
/// <summary> /// Gets a double value from the <see cref="IRegistry" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="defaultValue"> The default value to return if the specified key is not found. </param> /// <exception cref="ArgumentException"> /// Thrown when the value stored with the specified key is not compatible with the /// requested type. /// </exception> /// <returns> The value stored in the registry with the specified key, or the given default value if not found. </returns> public double GetDouble(string key, double defaultValue) { string valStr; if (!this.TryGetValue(key, out valStr)) { return(defaultValue); } double ret; if (double.TryParse(valStr, out ret)) { return(ret); } throw RegistryException.RegistryValueNotFoundException(key, typeof(double)); }
/// <summary> /// Gets a float value from the <see cref="IRegistry" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="defaultValue"> The default value to return if the specified key is not found. </param> /// <exception cref="ArgumentException"> /// Thrown when the value stored with the specified key is not compatible with the /// requested type. /// </exception> /// <returns> The value stored in the registry with the specified key, or the given default value if not found. </returns> public float GetFloat(string key, float defaultValue) { string valStr; if (!this.TryGetValue(key, out valStr)) { return(defaultValue); } float ret; if (float.TryParse(valStr, out ret)) { return(ret); } throw RegistryException.RegistryValueNotFoundException(key, typeof(float)); }
/// <summary> /// Gets an long value from the <see cref="IRegistry" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="defaultValue"> The default value to return if the specified key is not found. </param> /// <exception cref="ArgumentException"> /// Thrown when the value stored with the specified key is not compatible with the /// requested type. /// </exception> /// <returns> The value stored in the registry with the specified key, or the given default value if not found. </returns> public long GetLong(string key, long defaultValue) { string valStr; if (!this.TryGetValue(key, out valStr)) { return(defaultValue); } long ret; if (long.TryParse(valStr, out ret)) { return(ret); } throw RegistryException.RegistryValueNotFoundException(key, typeof(long)); }
/// <summary> /// Gets an int value from the <see cref="IRegistry" />. /// </summary> /// <param name="key"> The key used to store the value in the <see cref="IRegistry" />. </param> /// <param name="defaultValue"> The default value to return if the specified key is not found. </param> /// <exception cref="ArgumentException"> /// Thrown when the value stored with the specified key is not compatible with the /// requested type. /// </exception> /// <returns> The value stored in the registry with the specified key, or the given default value if not found. </returns> public int GetInt(string key, int defaultValue) { string valStr; if (!this.TryGetValue(key, out valStr)) { return(defaultValue); } int ret; if (int.TryParse(valStr, out ret)) { return(ret); } throw RegistryException.RegistryValueNotFoundException(key, typeof(int)); }