public static SimpleConfig LoadConfigRegistry(string appKeyIn, SimpleConfigRegistryNode regNodeIn, SimpleConfigRegistryHive hiveIn)
        {
            SimpleConfig optionsOut = new SimpleConfig();

            RegistryView regView = RegistryView.Default;

            switch (regNodeIn)
            {
            case SimpleConfigRegistryNode.NODE_32:
                regView = RegistryView.Registry32;
                break;

            case SimpleConfigRegistryNode.NODE_64:
                regView = RegistryView.Registry64;
                break;
            }

            RegistryHive regHive = RegistryHive.LocalMachine;

            if (SimpleConfigRegistryHive.HIVE_LOCAL_USER == hiveIn)
            {
                regHive = RegistryHive.CurrentUser;
            }

            try {
                using (RegistryKey baseKey = RegistryKey.OpenBaseKey(regHive, regView)) {
                    using (RegistryKey loadKey = baseKey.OpenSubKey("Software\\" + appKeyIn)) {
                        if (null == loadKey)
                        {
                            // The key doesn't exist, so we can't do anything, anyway.
                            return(new SimpleConfig());
                        }

                        foreach (string valueName in loadKey.GetValueNames())
                        {
                            optionsOut.Set(
                                valueName,
                                (string)loadKey.GetValue(
                                    valueName,
                                    ""
                                    )
                                );
                            if (null == optionsOut.Get(valueName, null))
                            {
                                optionsOut.Set(valueName, "");
                            }
                        }
                    }
                }
            } catch (UnauthorizedAccessException ex) {
                // Wrap and throw upwards to isolate usings.
                throw new SimpleConfigException(ex.Message);
            }

            return(optionsOut);
        }
        public void SaveConfigRegistry(string appKeyIn, SimpleConfigRegistryNode regNodeIn, SimpleConfigRegistryHive hiveIn)
        {
            RegistryView regView = RegistryView.Default;

            switch (regNodeIn)
            {
            case SimpleConfigRegistryNode.NODE_32:
                regView = RegistryView.Registry32;
                break;

            case SimpleConfigRegistryNode.NODE_64:
                regView = RegistryView.Registry64;
                break;
            }

            RegistryHive regHive = RegistryHive.LocalMachine;

            if (SimpleConfigRegistryHive.HIVE_LOCAL_USER == hiveIn)
            {
                regHive = RegistryHive.CurrentUser;
            }

            try {
                using (RegistryKey baseKey = RegistryKey.OpenBaseKey(regHive, regView)) {
                    // Make sure the key exists before writing to it.
                    using (RegistryKey loadKey = baseKey.OpenSubKey("Software\\" + appKeyIn)) {
                        if (null == loadKey)
                        {
                            baseKey.CreateSubKey("Software\\" + appKeyIn);
                        }
                    }

                    // Write out the config as subkeys.
                    using (RegistryKey loadKey = baseKey.OpenSubKey("Software\\" + appKeyIn, true)) {
                        foreach (string keyIter in this.internalConfig.Keys)
                        {
                            loadKey.SetValue(
                                keyIter,
                                this.internalConfig[keyIter],
                                RegistryValueKind.String
                                );
                        }
                    }
                }
            } catch (UnauthorizedAccessException ex) {
                // Wrap and throw upwards to isolate usings.
                throw new SimpleConfigException(ex.Message);
            }
        }
 public static SimpleConfig LoadConfigRegistry(string appKeyIn, SimpleConfigRegistryNode regNodeIn)
 {
     return(SimpleConfig.LoadConfigRegistry(appKeyIn, regNodeIn, SimpleConfigRegistryHive.HIVE_LOCAL_MACHINE));
 }
 public void SaveConfigRegistry(string appKeyIn, SimpleConfigRegistryNode regNodeIn)
 {
     this.SaveConfigRegistry(appKeyIn, regNodeIn, SimpleConfigRegistryHive.HIVE_LOCAL_MACHINE);
 }