2009-11-21 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Mon, 23 Nov 2009 03:45:10 +0000 (03:45 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 23 Nov 2009 03:45:10 +0000 (03:45 -0000)
* RegistryKey.cs: Implement a GetValueKind and a handful of
methods.

svn path=/trunk/mcs/; revision=146699

mcs/class/corlib/Microsoft.Win32/ChangeLog
mcs/class/corlib/Microsoft.Win32/IRegistryApi.cs
mcs/class/corlib/Microsoft.Win32/Registry.cs
mcs/class/corlib/Microsoft.Win32/RegistryKey.cs
mcs/class/corlib/Microsoft.Win32/UnixRegistryApi.cs
mcs/class/corlib/Microsoft.Win32/Win32RegistryApi.cs

index 8021c54e7c568da88aee6191b41e2f8e3068fedb..f68af6dc2f3e3e8afe474795943ad5fc6197f22f 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-21  Miguel de Icaza  <miguel@novell.com>
+
+       * RegistryKey.cs: Implement a GetValueKind and a handful of
+       methods. 
+
 2009-04-25  Sebastien Pouliot  <sebastien@ximian.com>
 
        * *.cs: Exclude the files for the NET_2_1 profile, since they are
index ff9aae40dd216db4ed07c70ae48b839493c33986..15a488c3ca16c66571af555ec0d3c3e292ffb880 100644 (file)
@@ -46,6 +46,7 @@ namespace Microsoft.Win32 {
                void Close (RegistryKey rkey);
 
                object GetValue (RegistryKey rkey, string name, object default_value, RegistryValueOptions options);
+               RegistryValueKind GetValueKind (RegistryKey rkey, string name);
                void SetValue (RegistryKey rkey, string name, object value);
 
                int SubKeyCount (RegistryKey rkey);
index 5ec79d08d6581d7c136b4ffa503f5460d4f67285..e5041ac28978396b892fbf0928a76ffee0297d1e 100644 (file)
@@ -45,6 +45,8 @@ namespace Microsoft.Win32
                                RegistryHive.CurrentConfig);
                public static readonly RegistryKey CurrentUser = new RegistryKey (
                                RegistryHive.CurrentUser);
+
+               [Obsolete ("Use PerformanceData instead")]
                public static readonly RegistryKey DynData = new RegistryKey (
                                RegistryHive.DynData);
                public static readonly RegistryKey LocalMachine = new RegistryKey (
index 1ca8a8c5d4d314e52f5cdd0795a92fd156e70f46..d23341cd8485632f8a22e1d53adc669ac3cd9990 100644 (file)
@@ -273,7 +273,7 @@ namespace Microsoft.Win32
                [ComVisible (false)]
                public RegistryValueKind GetValueKind (string name)
                {
-                       throw new NotImplementedException ();
+                       return RegistryApi.GetValueKind (this, name);
                }
 
                /// <summary>
@@ -291,15 +291,17 @@ namespace Microsoft.Win32
                }
 
                [ComVisible (false)]
+               [MonoLimitation ("permissionCheck is ignored in Mono")]
                public RegistryKey CreateSubKey (string subkey, RegistryKeyPermissionCheck permissionCheck)
                {
-                       throw new NotImplementedException ();
+                       return CreateSubKey (subkey);
                }
 
                [ComVisible (false)]
+               [MonoLimitation ("permissionCheck and registrySecurity are ignored in Mono")]
                public RegistryKey CreateSubKey (string subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
                {
-                       throw new NotImplementedException ();
+                       return CreateSubKey (subkey);
                }
                
                /// <summary>
@@ -433,15 +435,17 @@ namespace Microsoft.Win32
                }
 
                [ComVisible (false)]
+               [MonoLimitation ("permissionCheck is ignored in Mono")]
                public RegistryKey OpenSubKey (string name, RegistryKeyPermissionCheck permissionCheck)
                {
-                       throw new NotImplementedException ();
+                       return OpenSubKey (name);
                }
                
                [ComVisible (false)]
+               [MonoLimitation ("permissionCheck and rights are ignored in Mono")]
                public RegistryKey OpenSubKey (string name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
                {
-                       throw new NotImplementedException ();
+                       return OpenSubKey (name);
                }
                
                public void SetAccessControl (RegistrySecurity registrySecurity)
index c32ff8f7a70443963a3e133ed2da1ca863aadb3c..f8f159ae7d39ee1300fd63a1aa12fc383d53a739 100644 (file)
@@ -308,6 +308,29 @@ namespace Microsoft.Win32 {
                        }
                }
 
+               public RegistryValueKind GetValueKind (string name)
+               {
+                       if (name == null)
+                               return RegistryValueKind.Unknown;
+                       object value = values [name];
+                       if (value == null)
+                               return RegistryValueKind.Unknown;
+
+                       if (value is int)
+                               return RegistryValueKind.DWord;
+                       if (value is string [])
+                               return RegistryValueKind.MultiString;
+                       if (value is long)
+                               return RegistryValueKind.QWord;
+                       if (value is byte [])
+                               return RegistryValueKind.Binary;
+                       if (value is string)
+                               return RegistryValueKind.String;
+                       if (value is ExpandString)
+                               return RegistryValueKind.ExpandString;
+                       return RegistryValueKind.Unknown;
+               }
+               
                public object GetValue (string name, RegistryValueOptions options)
                {
                        if (IsMarkedForDeletion)
@@ -729,6 +752,17 @@ namespace Microsoft.Win32 {
                                throw RegistryKey.CreateMarkedForDeletionException ();
                        return self.Ensure (rkey, ToUnix (keyname), writable);
                }
+
+               public RegistryValueKind GetValueKind (RegistryKey rkey, string name)
+               {
+                       KeyHandler self = KeyHandler.Lookup (rkey, true);
+                       if (self != null) 
+                               return self.GetValueKind (name);
+
+                       // key was removed since it was opened or it does not exist.
+                       return RegistryValueKind.Unknown;
+               }
+               
        }
 }
 
index 22ad8406c0543de77cbde4b97df1b0105e1a10ed..d36f079f64282d9f44387fd2bcb7c903c01f01f0 100644 (file)
@@ -139,6 +139,20 @@ namespace Microsoft.Win32
                        return key.Handle != null;
                }
 
+               public RegistryValueKind GetValueKind (RegistryKey rkey, string name)
+               {
+                       RegistryValueKind type = 0;
+                       int size = 0;
+                       object obj = null;
+                       IntPtr handle = GetHandle (rkey);
+                       int result = RegQueryValueEx (handle, name, IntPtr.Zero, ref type, IntPtr.Zero, ref size);
+
+                       if (result == Win32ResultCode.FileNotFound || result == Win32ResultCode.MarkedForDeletion) 
+                               return RegistryValueKind.Unknown;
+
+                       return type;
+               }
+               
                /// <summary>
                /// Acctually read a registry value. Requires knowledge of the
                /// value's type and size.