public IOption Add(string name, object def, OptionEventHandler action) { IOption opt = GetByName(name); if (opt == null) { try { RegistryKey folderKey = FolderKey(path); object regValue = folderKey.GetValue(name); if (regValue != null) { RegistryValueKind kind = folderKey.GetValueKind(name); switch (kind) { case RegistryValueKind.DWord: opt = new IntOption(path, name, (int)def); opt.ValueChanged += action; opt.Value = regValue; break; case RegistryValueKind.String: default: if (def is int) { opt = new IntOption(path, name, (int)def); } else { opt = new Option(path, name, (string)def); } opt.ValueChanged += action; opt.Value = regValue; break; } } else { if (def is int) { opt = new IntOption(path, name, (int)def); } else { opt = new Option(path, name, (string)def); } opt.ValueChanged += action; opt.Value = def; opt.Save(); } options.Add(opt); } catch { } } return(opt); }
public void LoadForced() { RegistryKey folderKey = OptionCollection.FolderKey(path); string[] regNames = folderKey.GetValueNames(); IOption option; foreach (string regName in regNames) { RegistryValueKind kind = folderKey.GetValueKind(regName); object regValue = folderKey.GetValue(regName); switch (kind) { case RegistryValueKind.DWord: option = new IntOption(path, regName, 0); break; case RegistryValueKind.String: default: option = new Option(path, regName, null); break; } option.Value = regValue; options.Add(option); } }