public static bool VolatileKeyExists(string dir) { lock (typeof(KeyHandler)) { KeyHandler kh = (KeyHandler)dir_to_handler [dir]; if (kh != null) { return(kh.IsVolatile); } } if (Directory.Exists(dir)) // Non-volatile key exists. { return(false); } return(Directory.Exists(GetVolatileDir(dir))); }
public void DeleteValue(RegistryKey rkey, string name, bool throw_if_missing) { KeyHandler self = KeyHandler.Lookup(rkey, true); if (self == null) { // if key is marked for deletion, report success regardless of // throw_if_missing return; } if (throw_if_missing && !self.ValueExists(name)) { throw new ArgumentException("the given value does not exist"); } self.RemoveValue(name); }
public static KeyHandler Lookup(RegistryKey rkey, bool createNonExisting) { lock (typeof(KeyHandler)) { KeyHandler k = (KeyHandler)key_to_handler [rkey]; if (k != null) { return(k); } // when a non-root key is requested for no keyhandler exist // then that key must have been marked for deletion if (!rkey.IsRoot || !createNonExisting) { return(null); } RegistryHive x = (RegistryHive)rkey.Hive; switch (x) { case RegistryHive.CurrentUser: string userDir = Path.Combine(UserStore, x.ToString()); k = new KeyHandler(rkey, userDir); dir_to_handler [userDir] = k; break; case RegistryHive.CurrentConfig: case RegistryHive.ClassesRoot: case RegistryHive.DynData: case RegistryHive.LocalMachine: case RegistryHive.PerformanceData: case RegistryHive.Users: string machine_dir = Path.Combine(MachineStore, x.ToString()); k = new KeyHandler(rkey, machine_dir); dir_to_handler [machine_dir] = k; break; default: throw new Exception("Unknown RegistryHive"); } key_to_handler [rkey] = k; return(k); } }
public RegistryKey OpenSubKey(RegistryKey rkey, string keyname, bool writable) { KeyHandler self = KeyHandler.Lookup(rkey, true); if (self == null) { // return null if parent is marked for deletion return(null); } RegistryKey result = self.Probe(rkey, ToUnix(keyname), writable); if (result == null && IsWellKnownKey(rkey.Name, keyname)) { // create the subkey even if its parent was opened read-only result = CreateSubKey(rkey, keyname, writable); } return(result); }
public RegistryKey Ensure(RegistryKey rkey, string extra, bool writable) { Type typeFromHandle = typeof(KeyHandler); RegistryKey result; lock (typeFromHandle) { string text = Path.Combine(this.Dir, extra); KeyHandler keyHandler = (KeyHandler)KeyHandler.dir_to_handler[text]; if (keyHandler == null) { keyHandler = new KeyHandler(rkey, text); } RegistryKey registryKey = new RegistryKey(keyHandler, KeyHandler.CombineName(rkey, extra), writable); KeyHandler.key_to_handler[registryKey] = keyHandler; KeyHandler.dir_to_handler[text] = keyHandler; result = registryKey; } return(result); }
public void DeleteKey(RegistryKey rkey, string keyname, bool throw_if_missing) { KeyHandler self = KeyHandler.Lookup(rkey, true); if (self == null) { // key is marked for deletion if (!throw_if_missing) { return; } throw new ArgumentException("the given value does not exist"); } string dir = Path.Combine(self.Dir, ToUnix(keyname)); if (!KeyHandler.Delete(dir) && throw_if_missing) { throw new ArgumentException("the given value does not exist"); } }
public void DeleteKey(RegistryKey rkey, string keyname, bool throw_if_missing) { KeyHandler keyHandler = KeyHandler.Lookup(rkey, true); if (keyHandler != null) { string text = Path.Combine(keyHandler.Dir, UnixRegistryApi.ToUnix(keyname)); if (Directory.Exists(text)) { Directory.Delete(text, true); KeyHandler.Drop(text); } else if (throw_if_missing) { throw new ArgumentException("the given value does not exist"); } return; } if (!throw_if_missing) { return; } throw new ArgumentException("the given value does not exist"); }
public RegistryKey Probe(RegistryKey rkey, string extra, bool writable) { RegistryKey rk = null; lock (typeof(KeyHandler)){ string f = Path.Combine(Dir, extra); KeyHandler kh = (KeyHandler)dir_to_handler [f]; if (kh != null) { rk = new RegistryKey(kh, CombineName(rkey, extra), writable); key_to_handler [rk] = kh; } else if (Directory.Exists(f) || VolatileKeyExists(f)) { kh = new KeyHandler(rkey, f); rk = new RegistryKey(kh, CombineName(rkey, extra), writable); dir_to_handler [f] = kh; key_to_handler [rk] = kh; } return(rk); } }
public void Close(RegistryKey rkey) { KeyHandler.Drop(rkey); }
public static KeyHandler Lookup (RegistryKey rkey, bool createNonExisting) { lock (typeof (KeyHandler)){ KeyHandler k = (KeyHandler) key_to_handler [rkey]; if (k != null) return k; // when a non-root key is requested for no keyhandler exist // then that key must have been marked for deletion if (!rkey.IsRoot || !createNonExisting) return null; RegistryHive x = (RegistryHive) rkey.Hive; switch (x){ case RegistryHive.CurrentUser: string userDir = Path.Combine (UserStore, x.ToString ()); k = new KeyHandler (rkey, userDir); dir_to_handler [userDir] = k; break; case RegistryHive.CurrentConfig: case RegistryHive.ClassesRoot: case RegistryHive.DynData: case RegistryHive.LocalMachine: case RegistryHive.PerformanceData: case RegistryHive.Users: string machine_dir = Path.Combine (MachineStore, x.ToString ()); k = new KeyHandler (rkey, machine_dir); dir_to_handler [machine_dir] = k; break; default: throw new Exception ("Unknown RegistryHive"); } key_to_handler [rkey] = k; return k; } }
public RegistryKey Probe (RegistryKey rkey, string extra, bool writable) { RegistryKey rk = null; lock (typeof (KeyHandler)){ string f = Path.Combine (Dir, extra); KeyHandler kh = (KeyHandler) dir_to_handler [f]; if (kh != null) { rk = new RegistryKey (kh, CombineName (rkey, extra), writable); key_to_handler [rk] = kh; } else if (Directory.Exists (f) || VolatileKeyExists (f)) { kh = new KeyHandler (rkey, f); rk = new RegistryKey (kh, CombineName (rkey, extra), writable); dir_to_handler [f] = kh; key_to_handler [rk] = kh; } return rk; } }
// 'is_volatile' is used only if the key hasn't been created already. public RegistryKey Ensure (RegistryKey rkey, string extra, bool writable, bool is_volatile) { lock (typeof (KeyHandler)){ string f = Path.Combine (Dir, extra); KeyHandler kh = (KeyHandler) dir_to_handler [f]; if (kh == null) kh = new KeyHandler (rkey, f, is_volatile); RegistryKey rk = new RegistryKey (kh, CombineName (rkey, extra), writable); key_to_handler [rk] = kh; dir_to_handler [f] = kh; return rk; } }
public string [] GetSubKeyNames(RegistryKey rkey) { KeyHandler self = KeyHandler.Lookup(rkey, true); return(self.GetSubKeyNames()); }