/// <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); }
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); } }
/// <summary> /// Takes two tokens and compares them using version info. /// Note only tokens that match on Vendor, ProductLine, Language get compared, the pfDidCompare flag indicates this /// </summary> private static int CompareTokenVersions(ObjectToken token1, ObjectToken token2, out bool pfDidCompare) { pfDidCompare = false; RegistryDataKey attributes1 = null; RegistryDataKey attributes2 = null; attributes1 = token1.Attributes; attributes2 = token2.Attributes; // get vendor, version, language, product line for token 1 if (attributes1 != null) { string vendor1; string productLine1; string version1; string language1; attributes1.TryGetString("Vendor", out vendor1); attributes1.TryGetString("ProductLine", out productLine1); attributes1.TryGetString("Version", out version1); attributes1.TryGetString("Language", out language1); // get vendor, version, language, product line for token 2 if (attributes2 != null) { string vendor2; string productLine2; string version2; string language2; attributes2.TryGetString("Vendor", out vendor2); attributes2.TryGetString("ProductLine", out productLine2); attributes2.TryGetString("Version", out version2); attributes2.TryGetString("Language", out language2); if (((string.IsNullOrEmpty(vendor1) && string.IsNullOrEmpty(vendor2)) || (!string.IsNullOrEmpty(vendor1) && !string.IsNullOrEmpty(vendor2) && vendor1 == vendor2)) && ((string.IsNullOrEmpty(productLine1) && string.IsNullOrEmpty(productLine2)) || (!string.IsNullOrEmpty(productLine1) && !string.IsNullOrEmpty(productLine2) && productLine1 == productLine2)) && ((string.IsNullOrEmpty(language1) && string.IsNullOrEmpty(language2)) || (!string.IsNullOrEmpty(language1) && !string.IsNullOrEmpty(language2) && language1 == language2))) { pfDidCompare = true; return(CompareVersions(version1, version2)); } else { return(-1); } } else { return(1); } } else { return(-1); } }
private static int CompareTokenVersions(ObjectToken token1, ObjectToken token2, out bool pfDidCompare) { pfDidCompare = false; RegistryDataKey registryDataKey = null; RegistryDataKey registryDataKey2 = null; registryDataKey = token1.Attributes; registryDataKey2 = token2.Attributes; if (registryDataKey != null) { string value; registryDataKey.TryGetString("Vendor", out value); string value2; registryDataKey.TryGetString("ProductLine", out value2); string value3; registryDataKey.TryGetString("Version", out value3); string value4; registryDataKey.TryGetString("Language", out value4); if (registryDataKey2 != null) { string value5; registryDataKey2.TryGetString("Vendor", out value5); string value6; registryDataKey2.TryGetString("ProductLine", out value6); string value7; registryDataKey2.TryGetString("Version", out value7); string value8; registryDataKey2.TryGetString("Language", out value8); if (((string.IsNullOrEmpty(value) && string.IsNullOrEmpty(value5)) || (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(value5) && value == value5)) && ((string.IsNullOrEmpty(value2) && string.IsNullOrEmpty(value6)) || (!string.IsNullOrEmpty(value2) && !string.IsNullOrEmpty(value6) && value2 == value6)) && ((string.IsNullOrEmpty(value4) && string.IsNullOrEmpty(value8)) || (!string.IsNullOrEmpty(value4) && !string.IsNullOrEmpty(value8) && value4 == value8))) { pfDidCompare = true; return(CompareVersions(value3, value7)); } return(-1); } return(1); } return(-1); }
protected override void Dispose(bool disposing) { try { if (disposing) { if (_disposeSapiObjectToken && _sapiObjectToken != null) { Marshal.ReleaseComObject(_sapiObjectToken); _sapiObjectToken = null; } if (_attributes != null) { _attributes.Dispose(); _attributes = null; } } } finally { base.Dispose(disposing); } }
internal static ObjectTokenCategory Create(string sCategoryId) { RegistryDataKey key = RegistryDataKey.Open(sCategoryId, true); return(new ObjectTokenCategory(sCategoryId, key)); }
protected ObjectTokenCategory(string keyId, RegistryDataKey key) : base(keyId, key) { }