Beispiel #1
0
        internal static int DefaultDeviceOut()
        {
            int result = -1;

            using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Speech\\AudioOutput"))
            {
                if (objectTokenCategory == null)
                {
                    return(result);
                }
                string value;
                if (!objectTokenCategory.TryGetString("DefaultTokenId", out value))
                {
                    return(result);
                }
                int num = value.IndexOf('\\');
                if (num <= 0)
                {
                    return(result);
                }
                if (num < value.Length)
                {
                    using (RegistryDataKey registryDataKey = RegistryDataKey.Create(value.Substring(num + 1), Registry.LocalMachine))
                    {
                        if (registryDataKey != null)
                        {
                            return(AudioDeviceOut.GetDevicedId(registryDataKey.Name));
                        }
                        return(result);
                    }
                }
                return(result);
            }
        }
Beispiel #2
0
        private static ObjectToken DefaultToken(string category, string defaultTokenIdValueName)
        {
            ObjectToken objectToken = GetPreference(category, defaultTokenIdValueName);

            if (objectToken != null)
            {
                using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create(category))
                {
                    if (objectTokenCategory == null)
                    {
                        return(objectToken);
                    }
                    if (objectToken != null)
                    {
                        foreach (ObjectToken item in (IEnumerable <ObjectToken>)objectTokenCategory)
                        {
                            objectToken = GetHighestTokenVersion(objectToken, item, asVersionDefault);
                        }
                        return(objectToken);
                    }
                    string[] sAttributes = new string[1]
                    {
                        string.Format(CultureInfo.InvariantCulture, "{0:x}", new object[1]
                        {
                            CultureInfo.CurrentUICulture.LCID
                        })
                    };
                    foreach (ObjectToken item2 in (IEnumerable <ObjectToken>)objectTokenCategory)
                    {
                        if (item2.MatchesAttributes(sAttributes))
                        {
                            objectToken = item2;
                            break;
                        }
                    }
                    if (objectToken == null)
                    {
                        using (IEnumerator <ObjectToken> enumerator3 = ((IEnumerable <ObjectToken>)objectTokenCategory).GetEnumerator())
                        {
                            if (enumerator3.MoveNext())
                            {
                                return(enumerator3.Current);
                            }
                            return(objectToken);
                        }
                    }
                    return(objectToken);
                }
            }
            return(objectToken);
        }
Beispiel #3
0
        private static ObjectToken GetPreference(string category, string defaultLocation)
        {
            ObjectToken result = null;

            using (ObjectTokenCategory objectTokenCategory = ObjectTokenCategory.Create(category))
            {
                if (objectTokenCategory == null)
                {
                    return(result);
                }
                string value;
                if (objectTokenCategory.TryGetString(defaultLocation, out value))
                {
                    return(objectTokenCategory.OpenToken(value));
                }
                return(result);
            }
        }