/// <summary>
        /// Retrieve the Multimedia device ID. If the entry 'DefaultTokenId' is defined in the registry
        /// under 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput' then a multimedia device is looked
        /// for with this token. Otherwise, picks the default WAVE_MAPPER is returned.
        /// </summary>
        internal static int DefaultDeviceOut()
        {
            int device = -1;

            using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput"))
            {
                if (tokenCategory != null)
                {
                    string deviceName;
                    if (tokenCategory.TryGetString(_defaultTokenIdValueName, out deviceName))
                    {
                        int pos = deviceName.IndexOf('\\');
                        if (pos > 0 && pos < deviceName.Length)
                        {
                            using (RegistryDataKey deviceKey = RegistryDataKey.Create(deviceName.Substring(pos + 1), Registry.LocalMachine))
                            {
                                if (deviceKey != null)
                                {
                                    device = AudioDeviceOut.GetDevicedId(deviceKey.Name);
                                }
                            }
                        }
                    }
                }
            }

            return(device);
        }
Exemple #2
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);
            }
        }
        private static ObjectToken DefaultToken(string category, string defaultTokenIdValueName)
        {
            ObjectToken token = GetPreference(category, defaultTokenIdValueName);

            if (token != null)
            {
                // Now do special check to see if we have another token from the same vendor with a
                // more recent version - if so use that.

                // First lets change the category to LOCAL_MACHINE
                using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(category))
                {
                    if (tokenCategory != null)
                    {
                        if (token != null)
                        {
                            foreach (ObjectToken tokenSeed in (IEnumerable <ObjectToken>)tokenCategory)
                            {
                                token = GetHighestTokenVersion(token, tokenSeed, s_asVersionDefault);
                            }
                        }
                        else
                        {
                            // If there wasn't a default, just pick one with the proper culture
                            string[] sCultureId = new string[] { string.Format(CultureInfo.InvariantCulture, "{0:x}", CultureInfo.CurrentUICulture.LCID) };

                            foreach (ObjectToken tokenSeed in (IEnumerable <ObjectToken>)tokenCategory)
                            {
                                if (tokenSeed.MatchesAttributes(sCultureId))
                                {
                                    token = tokenSeed;
                                    break;
                                }
                            }

                            // Still nothing, picks the first one
                            if (token == null)
                            {
                                foreach (ObjectToken tokenSeed in (IEnumerable <ObjectToken>)tokenCategory)
                                {
                                    token = tokenSeed;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(token);
        }
Exemple #4
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);
        }
        /// <summary>
        /// Try to get the preferred token for a category
        /// </summary>
        private static ObjectToken GetPreference(string category, string defaultLocation)
        {
            ObjectToken token = null;

            using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(category))
            {
                if (tokenCategory != null)
                {
                    string sToken;
                    if (tokenCategory.TryGetString(defaultLocation, out sToken))
                    {
                        token = tokenCategory.OpenToken(sToken);
                    }
                }
            }
            return(token);
        }
Exemple #6
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);
            }
        }