private static RegistryKey FindHIDPathKey(string hidPath, BluetoothAddress address = default(BluetoothAddress))
        {
            foreach (string keyName in WiimoteConstants.RegKeys)
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName);
                if (key == null)
                {
                    continue;
                }

                IEnumerable <RegistryKey> subKeys;
                if (address.IsInvalid)
                {
                    subKeys = key.EnumerateSubKeys();
                }
                else
                {
                    subKeys = key.EnumerateSubKeys(n => n.ContainsMac(address));
                }

                foreach (RegistryKey subKey in subKeys)
                {
                    string prefix = subKey.GetValue("ParentIdPrefix") as string;
                    if (prefix != null && hidPath.Contains(prefix))
                    {
                        // This is it, we've located the correct devicePath entry
                        return(subKey);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public static IEnumerable <Tuple <string, string> > EnumerateSubKeys(this RegistryKey key, string subKey, bool recursive = false, bool failOnSecurityException = false)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (string.IsNullOrEmpty(subKey))
            {
                foreach (var tuple in key.EnumerateSubKeys(recursive, failOnSecurityException))
                {
                    yield return(tuple);
                }
            }
            else
            {
                using (RegistryKey openedSubKey = key.OpenSubKeyInternal(subKey, failOnSecurityException))
                {
                    if (openedSubKey != null)
                    {
                        foreach (var tuple in openedSubKey.EnumerateSubKeys(recursive, failOnSecurityException))
                        {
                            yield return(tuple);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static IEnumerable <Tuple <string, string> > EnumerateSubKeys(this RegistryKey key, bool recursive = false, bool failOnSecurityException = false)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            foreach (var subKey in key.GetSubKeyNames())
            {
                yield return(new Tuple <string, string>(key.Name, subKey));

                if (recursive)
                {
                    using (RegistryKey openedSubKey = key.OpenSubKeyInternal(subKey, failOnSecurityException))
                    {
                        if (openedSubKey != null)
                        {
                            foreach (var subSubKeyTuple in openedSubKey.EnumerateSubKeys(recursive))
                            {
                                yield return(subSubKeyTuple);
                            }
                        }
                    }
                }
            }
        }