Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        private static bool CurrentKeyEqualsSavedKey(MonitoredRegistryKey monitoredKey, RegistryKeyStruct registryKey)
        {
            var currentRoot = GetCurrentRoot(registryKey);

            return(currentRoot == monitoredKey.Root &&
                   registryKey.Subkey == monitoredKey.Subkey);
        }
Exemplo n.º 3
0
        private static MonitoredRegistryKey AddPropertyToRegistryKey(MonitoredRegistryKey monitoredRegistryKey, string propertyName, string propertyValue)
        {
            switch (propertyName)
            {
            case FileConstants.RegistryKey.ROOT:
                monitoredRegistryKey.Root = propertyValue;
                break;

            case FileConstants.RegistryKey.SUBKEY:
                monitoredRegistryKey.Subkey = propertyValue;
                break;
            }
            return(monitoredRegistryKey);
        }
Exemplo n.º 4
0
        private void LoadRegistryMonitor()
        {
            _currentLoadedEnvironment = _loadedSettings.Environments.Find(env => env.SubkeyValue == (string)Registry.GetValue(_loadedSettings.MonitoredRegistryKey.Root, _loadedSettings.MonitoredRegistryKey.Subkey, ""));
            SetIcon();

            _registryMonitor = new RegistryUtils.RegistryMonitor(_loadedSettings.MonitoredRegistryKey.Root)
            {
                RegChangeNotifyFilter = RegChangeNotifyFilter.Value
            };
            _registryMonitor.RegChanged += OnRegChanged;
            _registryMonitor.Error      += OnError;
            _registryMonitor.Start();
            _currentMonitoredRegistryKey = _loadedSettings.MonitoredRegistryKey;
        }
Exemplo n.º 5
0
        public static void PopulateComboBoxesBasedOnCurrentRegistryKey(MonitoredRegistryKey registryKey, RegistryKeyObjectStruct registryKeyObjectStruct)
        {
            var splitRegistryKey = registryKey.Root.Split(char.Parse("\\"));

            PopulateRootCombo(registryKeyObjectStruct.Root);
            registryKeyObjectStruct.Root.SelectedIndex = registryKeyObjectStruct.Root.Items.GetIndex(splitRegistryKey[0]);
            PopulateRootCombo2(registryKeyObjectStruct.Root, registryKeyObjectStruct.Root2);
            registryKeyObjectStruct.Root2.SelectedIndex = registryKeyObjectStruct.Root2.Items.GetIndex(splitRegistryKey[1]);
            if (registryKeyObjectStruct.Root2.SelectedIndex != -1)
            {
                PopulateRootCombo3(registryKeyObjectStruct.Root, registryKeyObjectStruct.Root2, registryKeyObjectStruct.Root3);
                registryKeyObjectStruct.Root3.SelectedIndex = registryKeyObjectStruct.Root3.Items.GetIndex(splitRegistryKey[2]);
            }
            registryKeyObjectStruct.Subkey.Text = registryKey.Subkey;
        }
Exemplo n.º 6
0
        private void SetNewRegistrykeyIfChanged()
        {
            if (_currentMonitoredRegistryKey == _loadedSettings.MonitoredRegistryKey)
            {
                return;
            }

            _registryMonitor.Stop();
            _registryMonitor.Dispose();

            _registryMonitor = new RegistryUtils.RegistryMonitor(_loadedSettings.MonitoredRegistryKey.Root)
            {
                RegChangeNotifyFilter = RegChangeNotifyFilter.Value
            };
            _registryMonitor.RegChanged += OnRegChanged;
            _registryMonitor.Error      += OnError;
            _registryMonitor.Start();
            _currentMonitoredRegistryKey = _loadedSettings.MonitoredRegistryKey;
        }
Exemplo n.º 7
0
        public static void WriteRegistryKeySettings(MonitoredRegistryKey monitoredRegistryKey, bool firstLoad = false)
        {
            string environmnentJsonFile = Path.Combine(Directory.GetCurrentDirectory(), REGISTRYKEY_FILE_NAME);

            try
            {
                using (StreamWriter file = File.CreateText(environmnentJsonFile))
                    using (JsonTextWriter writer = new JsonTextWriter(file))
                    {
                        var jsonRegistryKey = JsonConvert.SerializeObject(firstLoad ? GetInitialRegistryKey() : monitoredRegistryKey);
                        writer.WriteRaw(jsonRegistryKey);
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{Constants.RegistryKeyMessages.ErrorWritingFile}{ex}",
                                Constants.RegistryKeyMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Exemplo n.º 8
0
        public static MonitoredRegistryKey ReadRegistryKeySettings()
        {
            string registryKeyJsonFile = Path.Combine(Directory.GetCurrentDirectory(), REGISTRYKEY_FILE_NAME);

            var registryKey = new MonitoredRegistryKey();

            if (!File.Exists(registryKeyJsonFile))
            {
                registryKey = GetInitialRegistryKey();
                WriteRegistryKeySettings(registryKey);
            }
            else
            {
                try
                {
                    using (StreamReader file = File.OpenText(registryKeyJsonFile))
                        using (JsonTextReader reader = new JsonTextReader(file))
                        {
                            while (reader.Read())
                            {
                                JObject o3 = (JObject)JToken.ReadFrom(reader);
                                foreach (var child in o3.Children())
                                {
                                    AddPropertyToRegistryKey(registryKey, child.Path, child.First.ToString());
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{Constants.RegistryKeyMessages.ErrorWritingFile}{ex}",
                                    Constants.RegistryKeyMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }
            return(registryKey);
        }