Author: miguel
Date: 2006-08-13 23:49:08 -0400 (Sun, 13 Aug 2006)
New Revision: 63698
Modified:
trunk/mcs/class/corlib/Microsoft.Win32/ChangeLog
trunk/mcs/class/corlib/Microsoft.Win32/Registry.cs
trunk/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs
Log:
2006-08-13 Miguel de Icaza <[EMAIL PROTECTED]>
* Registry.cs (SetValue, GetValue): implement.
* UnixRegistryApi.cs (KeyHandler.LoadKey, KeyHandler.Save): Add
support for qwords.
(KeyHandler.Save): Do not save the entries if they have been
deleted/dropped. Fixes a crash.
(UnixRegistryApi.DeleteKey): bug fix, call ToUnix on the keyname.
Modified: trunk/mcs/class/corlib/Microsoft.Win32/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Microsoft.Win32/ChangeLog 2006-08-14 03:31:44 UTC
(rev 63697)
+++ trunk/mcs/class/corlib/Microsoft.Win32/ChangeLog 2006-08-14 03:49:08 UTC
(rev 63698)
@@ -1,3 +1,15 @@
+2006-08-13 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * Registry.cs (SetValue, GetValue): implement.
+
+ * UnixRegistryApi.cs (KeyHandler.LoadKey, KeyHandler.Save): Add
+ support for qwords.
+
+ (KeyHandler.Save): Do not save the entries if they have been
+ deleted/dropped. Fixes a crash.
+
+ (UnixRegistryApi.DeleteKey): bug fix, call ToUnix on the keyname.
+
2006-08-12 Gert Driesen <[EMAIL PROTECTED]>
* Registry.cs: Fixed copy/paste bug.
Modified: trunk/mcs/class/corlib/Microsoft.Win32/Registry.cs
===================================================================
--- trunk/mcs/class/corlib/Microsoft.Win32/Registry.cs 2006-08-14 03:31:44 UTC
(rev 63697)
+++ trunk/mcs/class/corlib/Microsoft.Win32/Registry.cs 2006-08-14 03:49:08 UTC
(rev 63698)
@@ -2,11 +2,12 @@
// Microsoft.Win32.Registry.cs
//
// Author:
+// Miguel de Icaza ([EMAIL PROTECTED])
// stubbed out by Alexandre Pigolkine ([EMAIL PROTECTED])
//
//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -32,7 +33,13 @@
namespace Microsoft.Win32
{
- public sealed class Registry
+ public
+#if NET_2_0
+ sealed
+#else
+ sealed static
+#endif
+ class Registry
{
private Registry () { }
public static readonly RegistryKey ClassesRoot = new
RegistryKey (
@@ -49,5 +56,74 @@
RegistryHive.PerformanceData,
"HKEY_PERFORMANCE_DATA");
public static readonly RegistryKey Users = new RegistryKey (
RegistryHive.Users, "HKEY_USERS");
+
+#if NET_2_0
+ static RegistryKey ToKey (string keyName, bool setting)
+ {
+ if (keyName == null)
+ throw new ArgumentException ("Not a valid
registry key name", "keyName");
+
+ RegistryKey key = null;
+ string [] keys = keyName.Split ('\\');
+
+ switch (keys [0]){
+ case "HKEY_CLASSES_ROOT":
+ key = ClassesRoot;
+ break;
+ case "HKEY_CURRENT_CONFIG":
+ key = CurrentConfig;
+ break;
+ case "HKEY_CURRENT_USER":
+ key = CurrentUser;
+ break;
+ case "HKEY_DYN_DATA":
+ key = DynData;
+ break;
+ case "HKEY_LOCAL_MACHINE":
+ key = LocalMachine;
+ break;
+ case "HKEY_PERFORMANCE_DATA":
+ key = PerformanceData;
+ break;
+ case "HKEY_USERS":
+ key = Users;
+ break;
+ default:
+ throw new ArgumentException ("Keyname does not
start with a valid registry root", "keyName");
+ }
+
+ for (int i = 1; i < keys.Length; i++){
+ RegistryKey nkey = key.OpenSubKey (keys [i],
true);
+ if (nkey == null){
+ if (!setting)
+ return null;
+ nkey = key.CreateSubKey (keys [i]);
+ }
+ key = nkey;
+ }
+ return key;
+ }
+
+ public static void SetValue (string keyName, string valueName,
object value)
+ {
+ RegistryKey key = ToKey (keyName, true);
+ if (valueName.Length > 255)
+ throw new ArgumentException ("valueName is
larger than 255 characters", "valueName");
+
+ if (key == null)
+ throw new ArgumentException ("cant locate that
keyName", "keyName");
+
+ key.SetValue (valueName, value);
+ }
+
+ public static object GetValue (string keyName, string
valueName, object defaultValue)
+ {
+ RegistryKey key = ToKey (keyName, false);
+ if (key == null)
+ return defaultValue;
+
+ return key.GetValue (valueName, defaultValue);
+ }
+#endif
}
}
Modified: trunk/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs
===================================================================
--- trunk/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs 2006-08-14
03:31:44 UTC (rev 63697)
+++ trunk/mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs 2006-08-14
03:49:08 UTC (rev 63698)
@@ -55,6 +55,7 @@
public Hashtable values;
string file;
bool dirty;
+ bool valid;
KeyHandler (RegistryKey rkey, string basedir)
{
@@ -119,6 +120,9 @@
case "string":
values [name] = se.Text;
break;
+ case "qword":
+ values [name] = Int64.Parse (se.Text);
+ break;
case "string-array":
ArrayList sa = new ArrayList ();
if (se.Children != null){
@@ -206,6 +210,7 @@
KeyHandler k = (KeyHandler) key_to_handler [rkey];
if (k == null)
return;
+ k.valid = false;
dir_to_key.Remove (k.Dir);
key_to_handler.Remove (rkey);
}
@@ -213,8 +218,8 @@
public static void Drop (string dir)
{
if (dir_to_key.Contains (dir)){
- key_to_handler.Remove (dir_to_key [dir]);
- dir_to_key.Remove (dir);
+ RegistryKey rkey = (RegistryKey) dir_to_key
[dir];
+ Drop (rkey);
}
}
@@ -259,6 +264,9 @@
void Save ()
{
+ if (!valid)
+ return;
+
if (!File.Exists (file) && values.Count == 0)
return;
@@ -275,6 +283,9 @@
} else if (val is int){
value.AddAttribute ("type", "int");
value.Text = val.ToString ();
+ } else if (val is long){
+ value.AddAttribute ("type", "qword");
+ value.Text = val.ToString ();
} else if (val is byte []){
value.AddAttribute ("type",
"bytearray");
value.Text = Convert.ToBase64String
((byte[]) val);
@@ -405,8 +416,8 @@
public void DeleteKey (RegistryKey rkey, string keyname, bool
throw_if_missing)
{
KeyHandler self = KeyHandler.Lookup (rkey);
- string dir = Path.Combine (self.Dir, keyname);
-
+ string dir = Path.Combine (self.Dir, ToUnix (keyname));
+
if (Directory.Exists (dir)){
Directory.Delete (dir, true);
KeyHandler.Drop (dir);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches