public static string GetCurrentRoot(RegistryKeyStruct registryKey) { var userRoot = new StringBuilder(); if (registryKey.Root.SelectedIndex != -1) userRoot.Append(registryKey.Root.SelectedItem); if (registryKey.Root2.SelectedIndex != -1) userRoot.Append("\\" + registryKey.Root2.SelectedItem); if (registryKey.Root3.SelectedIndex != -1) userRoot.Append("\\" + registryKey.Root3.SelectedItem); return userRoot.ToString(); }
public static void CheckCurrentKeyValue(RegistryKeyStruct registryKey) { var rootValue = GetCurrentRoot(registryKey); var keyValue = GetCurrentKeyValue(registryKey); MessageBox.Show($"{Constants.RegistryKeyMessages.CurrentSelectedKey}" + $"{rootValue}\\{registryKey.Subkey}" + $"{Constants.RegistryKeyMessages.CurrentValueOfKey}" + $"{keyValue}", Constants.RegistryKeyMessages.CurrentValueOfKeyCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private static bool CurrentKeyEqualsSavedKey(MonitoredRegistryKey monitoredKey, RegistryKeyStruct registryKey) { var currentRoot = GetCurrentRoot(registryKey); return currentRoot == monitoredKey.Root && registryKey.Subkey == monitoredKey.Subkey; }
private static string GetCurrentKeyValue(RegistryKeyStruct registryKey) { return (string) Registry.GetValue(GetCurrentRoot(registryKey), registryKey.Subkey, ""); }
public static void SaveNewRegistryKey(LoadedSettings loadedSettings, RegistryKeyStruct registryKey) { if (GetCurrentKeyValue(registryKey) == string.Empty) // New Key is invalid. { MessageBox.Show(Constants.RegistryKeyMessages.SelectRegistryKey, Constants.RegistryKeyMessages.SelectRegistryKeyCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (CurrentKeyEqualsSavedKey(loadedSettings.MonitoredRegistryKey, registryKey)) // New Key is Old Key. { return; } else // Save New Key. { var confirmMessage = MessageBox.Show(Constants.RegistryKeyMessages.OverrideRegistryKey, Constants.RegistryKeyMessages.OverrideRegistryKeyCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Hand); if (confirmMessage != DialogResult.Yes) return; var newRegistryKey = new MonitoredRegistryKey { Root = GetCurrentRoot(registryKey), Subkey = registryKey.Subkey }; loadedSettings.MonitoredRegistryKey = newRegistryKey; } }