Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
</configuration>
2 changes: 1 addition & 1 deletion DisplayProfileManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>DisplayProfileManager</RootNamespace>
<AssemblyName>DisplayProfileManager</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down
32 changes: 20 additions & 12 deletions src/Helpers/AudioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,20 +557,28 @@ private static string GetDeviceNameViaWin32SystemDevicesWMI(IDevice device)
{
searcher.Options.Timeout = TimeSpan.FromSeconds(5);

ManagementObjectCollection results = searcher.Get();

foreach (var wmiDevice in results)
{
var deviceName = wmiDevice["Name"]?.ToString();
var wmiDeviceId = wmiDevice["DeviceID"]?.ToString();

// CRITICAL: Only process devices that could be related to our target device
if (IsBluetoothDeviceFromWmiProperties(deviceName))
using (ManagementObjectCollection results = searcher.Get())
{
foreach (ManagementObject wmiDevice in results)
{
// Enhanced device-specific correlation
if (IsDeviceSpecificallyRelated(targetDeviceId, wmiDeviceId))
try
{
var deviceName = wmiDevice["Name"]?.ToString();
var wmiDeviceId = wmiDevice["DeviceID"]?.ToString();

// CRITICAL: Only process devices that could be related to our target device
if (IsBluetoothDeviceFromWmiProperties(deviceName))
{
// Enhanced device-specific correlation
if (IsDeviceSpecificallyRelated(targetDeviceId, wmiDeviceId))
{
return deviceName;
}
}
}
finally
{
return deviceName;
wmiDevice.Dispose();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/DisplayConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public struct DISPLAYCONFIG_PATH_TARGET_INFO
public uint scaling;
public DISPLAYCONFIG_RATIONAL refreshRate;
public uint scanLineOrdering;
[MarshalAs(UnmanagedType.Bool)]
public bool targetAvailable;
public uint statusFlags;
}
Expand Down
75 changes: 44 additions & 31 deletions src/Helpers/DisplayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,28 @@ public static List<MonitorInfo> GetMonitorsFromWin32PnPEntity()
{
foreach (ManagementObject obj in collection)
{
var monitor = new MonitorInfo
try
{
Name = obj["Name"]?.ToString() ?? "",
DeviceID = obj["DeviceID"]?.ToString() ?? "",
PnPDeviceID = obj["PNPDeviceID"]?.ToString() ?? "",
Description = obj["Description"]?.ToString() ?? "",
Manufacturer = obj["Manufacturer"]?.ToString() ?? ""
};

logger.Debug($"WMI Win32PnPEntity Monitor: Name='{monitor.Name}', DeviceID='{monitor.DeviceID}', PnPDeviceID='{monitor.PnPDeviceID}'");

// Filter out non-monitor devices
if (!string.IsNullOrEmpty(monitor.Name))
var monitor = new MonitorInfo
{
Name = obj["Name"]?.ToString() ?? "",
DeviceID = obj["DeviceID"]?.ToString() ?? "",
PnPDeviceID = obj["PNPDeviceID"]?.ToString() ?? "",
Description = obj["Description"]?.ToString() ?? "",
Manufacturer = obj["Manufacturer"]?.ToString() ?? ""
};

logger.Debug($"WMI Win32PnPEntity Monitor: Name='{monitor.Name}', DeviceID='{monitor.DeviceID}', PnPDeviceID='{monitor.PnPDeviceID}'");

// Filter out non-monitor devices
if (!string.IsNullOrEmpty(monitor.Name))
{
monitors.Add(monitor);
}
}
finally
{
monitors.Add(monitor);
obj.Dispose();
}
}
}
Expand Down Expand Up @@ -435,27 +442,33 @@ public static List<MonitorIdInfo> GetMonitorIDsFromWmiMonitorID()
{
foreach (ManagementObject obj in collection)
{
var monitorId = new MonitorIdInfo
try
{
InstanceName = obj["InstanceName"]?.ToString() ?? "",
// ManufacturerName, ProductCodeID, SerialNumberID are returned as ushort[] (UTF-16 words)
ManufacturerName = ArrayUshortToString(obj["ManufacturerName"] as ushort[]),
ProductCodeID = ArrayUshortToHexString(obj["ProductCodeID"] as ushort[]),
SerialNumberID = ArrayUshortToString(obj["SerialNumberID"] as ushort[]),
};

logger.Debug($"WMI WmiMonitorID Monitor: " +
$"InstanceName='{monitorId.InstanceName}', " +
$"ManufacturerName='{monitorId.ManufacturerName}', " +
$"ProductCodeID='{monitorId.ProductCodeID}', " +
$"SerialNumberID='{monitorId.SerialNumberID}'");

// Filter out non-monitor devices
if (!string.IsNullOrEmpty(monitorId.InstanceName))
var monitorId = new MonitorIdInfo
{
InstanceName = obj["InstanceName"]?.ToString() ?? "",
// ManufacturerName, ProductCodeID, SerialNumberID are returned as ushort[] (UTF-16 words)
ManufacturerName = ArrayUshortToString(obj["ManufacturerName"] as ushort[]),
ProductCodeID = ArrayUshortToHexString(obj["ProductCodeID"] as ushort[]),
SerialNumberID = ArrayUshortToString(obj["SerialNumberID"] as ushort[]),
};

logger.Debug($"WMI WmiMonitorID Monitor: " +
$"InstanceName='{monitorId.InstanceName}', " +
$"ManufacturerName='{monitorId.ManufacturerName}', " +
$"ProductCodeID='{monitorId.ProductCodeID}', " +
$"SerialNumberID='{monitorId.SerialNumberID}'");

// Filter out non-monitor devices
if (!string.IsNullOrEmpty(monitorId.InstanceName))
{
monitorIDs.Add(monitorId);
}
}
finally
{
monitorIDs.Add(monitorId);
obj.Dispose();
}

}
}
}
Expand Down