Skip to content

Portable Tool for an Ideal Windows Setup

-output of the normal name for Audio devices connected via USB

Greedeks088e2f6b5857
diff --git a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
index 575d5c9e..9d06fee5 100644
--- a/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
+++ b/.Source/GTweak/Utilities/Configuration/SystemDiagnostics.cs
@@ -163,11 +163,45 @@ namespace GTweak.Utilities.Configuration
HardwareData["Storage"] = HardwareData["Storage"].TrimEnd('\n');
}
+
private static void GetAudioDevices()
{
+ static (bool, string) IsUsbAudioDevice(string deviceID)
+ {
+ using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render"))
+ {
+ if (regKey != null)
+ {
+ foreach (string subKeyName in regKey.GetSubKeyNames())
+ {
+ using RegistryKey subKey = regKey.OpenSubKey(subKeyName + @"\Properties");
+ if (subKey != null)
+ {
+ if (subKey.GetValue("{a45c254e-df1c-4efd-8020-67d146a850e0},24")?.ToString() == "USB" && subKey.GetValue("{b3f8fa53-0004-438e-9003-51a46e139bfc},2")?.ToString()?.Contains(deviceID) == true)
+ {
+ string value = subKey.GetValue("{b3f8fa53-0004-438e-9003-51a46e139bfc},6")?.ToString();
+ return (true, value);
+ }
+ }
+ }
+ }
+ }
+ return (false, string.Empty);
+ }
+
HardwareData["Audio"] = string.Empty;
- foreach (var managementObj in new ManagementObjectSearcher(@"root\cimv2", "select Name, Caption, Description from Win32_SoundDevice", new EnumerationOptions { ReturnImmediately = true }).Get())
- HardwareData["Audio"] += $"{new[] { "Name", "Caption", "Description" }.Select(prop => (string)managementObj[prop]).FirstOrDefault(info => !string.IsNullOrEmpty(info))}\n" ?? string.Empty;
+ using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\cimv2", "SELECT DeviceID, Name, Caption, Description FROM Win32_SoundDevice", new EnumerationOptions { ReturnImmediately = true }))
+ {
+ foreach (ManagementObject managementObj in searcher.Get().Cast<ManagementObject>())
+ {
+ (bool isUsbDevice, string data) = IsUsbAudioDevice(managementObj["DeviceID"].ToString());
+
+ if (isUsbDevice && !string.IsNullOrEmpty(data))
+ HardwareData["Audio"] += $"{data}\n";
+ else
+ HardwareData["Audio"] += $"{new[] { "Name", "Caption", "Description" }.Select(prop => (string)managementObj[prop]).FirstOrDefault(info => !string.IsNullOrEmpty(info))}\n" ?? string.Empty;
+ }
+ }
HardwareData["Audio"] = HardwareData["Audio"].TrimEnd('\n');
}
diff --git a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
index ab495816..80ea51a9 100644
--- a/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
+++ b/.Source/GTweak/Utilities/Tweaks/SystemTweaks.cs
@@ -64,6 +64,7 @@ namespace GTweak.Utilities.Tweaks
try
{
+
using RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}", true);
if (registryKey == null)
@@ -72,15 +73,19 @@ namespace GTweak.Utilities.Tweaks
foreach (string keyname in registryKey.GetSubKeyNames())
{
using RegistryKey key = registryKey.OpenSubKey(keyname, true);
- if (key?.GetValue("DriverDesc")?.ToString() == "Realtek High Definition Audio")
+ if (key == null) continue;
+
+ if (key.GetValue("DriverDesc")?.ToString() == "Realtek High Definition Audio")
{
- using RegistryKey powerSettingsKey = key.OpenSubKey(@"PowerSettings", true);
+ using RegistryKey powerSettingsKey = key.OpenSubKey("PowerSettings", true);
byte[] conservationIdleTime = powerSettingsKey.GetValue("ConservationIdleTime") as byte[];
byte[] idlePowerState = powerSettingsKey.GetValue("IdlePowerState") as byte[];
byte[] performanceIdleTime = powerSettingsKey.GetValue("PerformanceIdleTime") as byte[];
systemV.TglButton7.StateNA = conservationIdleTime?[0].ToString() != "255" || idlePowerState?[0].ToString() != "0" || performanceIdleTime?[0].ToString() != "255";
+
+
}
}
}