From ae9e35db4fee2f129018e768e0b9e8a96fbba5de Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Thu, 16 Jun 2022 21:45:23 +1200 Subject: [PATCH] Updated so stores all adapters on the machine for a profile This has been done to ensure that the profile will still work even if the profile is a cloned profile. There were some circumstances where if an adapter had one display, and that display was a clone of another display, then the list of adapters we store wouldn't include the adapter related to the cloned display. This would mean that the profile wouldn't be patched properly when it was loaded, and would fail. This is now hopefully fixed with this change. Also updated to v1.8.1 --- CCDInfo/Program.cs | 4 +-- CCDInfo/Properties/AssemblyInfo.cs | 4 +-- CCDInfo/WinLibrary.cs | 43 ++++++++++++++++-------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/CCDInfo/Program.cs b/CCDInfo/Program.cs index c1aea57..13cc738 100644 --- a/CCDInfo/Program.cs +++ b/CCDInfo/Program.cs @@ -45,10 +45,10 @@ static void Main(string[] args) NLog.LogManager.Configuration = config; // Start the Log file - SharedLogger.logger.Info($"CCDInfo/Main: Starting CCDInfo v1.8.0"); + SharedLogger.logger.Info($"CCDInfo/Main: Starting CCDInfo v1.8.1"); - Console.WriteLine($"\nCCDInfo v1.8.0"); + Console.WriteLine($"\nCCDInfo v1.8.1"); Console.WriteLine($"=============="); Console.WriteLine($"By Terry MacDonald 2022\n"); diff --git a/CCDInfo/Properties/AssemblyInfo.cs b/CCDInfo/Properties/AssemblyInfo.cs index 4376872..b497618 100644 --- a/CCDInfo/Properties/AssemblyInfo.cs +++ b/CCDInfo/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +[assembly: AssemblyVersion("1.8.1.0")] +[assembly: AssemblyFileVersion("1.8.1.0")] diff --git a/CCDInfo/WinLibrary.cs b/CCDInfo/WinLibrary.cs index f060aa4..992cd41 100644 --- a/CCDInfo/WinLibrary.cs +++ b/CCDInfo/WinLibrary.cs @@ -254,7 +254,7 @@ public void PatchWindowsDisplayConfig(ref WINDOWS_DISPLAY_CONFIG savedDisplayCon { Dictionary adapterOldToNewMap = new Dictionary(); - Dictionary currentAdapterMap = GetCurrentAdapterIDs(); + Dictionary currentAdapterMap = GetAllAdapterIDs(); try { SharedLogger.logger.Trace("WinLibrary/PatchWindowsDisplayConfig: Going through the list of adapters we stored in the config to figure out the old adapterIDs"); @@ -668,7 +668,7 @@ private WINDOWS_DISPLAY_CONFIG GetWindowsDisplayConfig(QDC selector = QDC.QDC_ON paths[i].TargetInfo.ModeInfoIdx = CCDImport.DISPLAYCONFIG_PATH_MODE_IDX_INVALID; } - // Get adapter ID for later + /*// Get adapter ID for later SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get adapter name for adapter {paths[i].TargetInfo.AdapterId.Value}."); if (!windowsDisplayConfig.DisplayAdapters.ContainsKey(paths[i].TargetInfo.AdapterId.Value)) { @@ -695,7 +695,7 @@ private WINDOWS_DISPLAY_CONFIG GetWindowsDisplayConfig(QDC selector = QDC.QDC_ON // We already have the adapter name SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: We already have the adapter name {windowsDisplayConfig.DisplayAdapters[paths[i].TargetInfo.AdapterId.Value]} for adapter {paths[i].TargetInfo.AdapterId.Value} so skipping storing it."); //gotAdapterName = true; - } + }*/ // Get advanced color info @@ -774,6 +774,9 @@ private WINDOWS_DISPLAY_CONFIG GetWindowsDisplayConfig(QDC selector = QDC.QDC_ON } } + // Get all the DisplayAdapters currently in the system + // This will be used for windows to translate the adapter details beween reboots + windowsDisplayConfig.DisplayAdapters = GetAllAdapterIDs(); // Go through the list of physicalTargetIdsAvailable // ignore the ones that were found @@ -2132,7 +2135,7 @@ private List GetSomeDisplayIdentifiers(QDC selector = QDC.QDC_ONLY_ACTIV return displayIdentifiers; } - public List GetCurrentPCIVideoCardVendors() + public List GetAllPCIVideoCardVendors() { SharedLogger.logger.Trace($"WinLibrary/GetCurrentPCIVideoCardVendors: Getting the current PCI vendor ids for the videocards reported to Windows"); List videoCardVendorIds = new List(); @@ -2283,56 +2286,56 @@ public List GetCurrentPCIVideoCardVendors() } - public Dictionary GetCurrentAdapterIDs() + public Dictionary GetAllAdapterIDs() { - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Getting the current adapter ids for the videocards Windows knows about"); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Getting the current adapter ids for the videocards Windows knows about"); Dictionary currentAdapterMap = new Dictionary(); - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Testing whether the display configuration is valid (allowing tweaks)."); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Testing whether the display configuration is valid (allowing tweaks)."); // Get the size of the largest All Paths and Modes arrays int pathCount = 0; int modeCount = 0; WIN32STATUS err = CCDImport.GetDisplayConfigBufferSizes(QDC.QDC_ALL_PATHS, out pathCount, out modeCount); if (err != WIN32STATUS.ERROR_SUCCESS) { - SharedLogger.logger.Error($"WinLibrary/GetCurrentAdapterIDs: ERROR - GetDisplayConfigBufferSizes returned WIN32STATUS {err} when trying to get the maximum path and mode sizes"); - throw new WinLibraryException($"GetCurrentAdapterIDs returned WIN32STATUS {err} when trying to get the maximum path and mode sizes"); + SharedLogger.logger.Error($"WinLibrary/GetAllAdapterIDs: ERROR - GetDisplayConfigBufferSizes returned WIN32STATUS {err} when trying to get the maximum path and mode sizes"); + throw new WinLibraryException($"GetAllAdapterIDs returned WIN32STATUS {err} when trying to get the maximum path and mode sizes"); } - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Getting the current Display Config path and mode arrays"); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Getting the current Display Config path and mode arrays"); var paths = new DISPLAYCONFIG_PATH_INFO[pathCount]; var modes = new DISPLAYCONFIG_MODE_INFO[modeCount]; err = CCDImport.QueryDisplayConfig(QDC.QDC_ALL_PATHS, ref pathCount, paths, ref modeCount, modes, IntPtr.Zero); if (err == WIN32STATUS.ERROR_INSUFFICIENT_BUFFER) { - SharedLogger.logger.Warn($"WinLibrary/GetCurrentAdapterIDs: The displays were modified between GetDisplayConfigBufferSizes and QueryDisplayConfig so we need to get the buffer sizes again."); - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Getting the size of the largest Active Paths and Modes arrays"); + SharedLogger.logger.Warn($"WinLibrary/GetAllAdapterIDs: The displays were modified between GetDisplayConfigBufferSizes and QueryDisplayConfig so we need to get the buffer sizes again."); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Getting the size of the largest Active Paths and Modes arrays"); // Screen changed in between GetDisplayConfigBufferSizes and QueryDisplayConfig, so we need to get buffer sizes again // as per https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-querydisplayconfig err = CCDImport.GetDisplayConfigBufferSizes(QDC.QDC_ALL_PATHS, out pathCount, out modeCount); if (err != WIN32STATUS.ERROR_SUCCESS) { - SharedLogger.logger.Error($"WinLibrary/GetCurrentAdapterIDs: ERROR - GetDisplayConfigBufferSizes returned WIN32STATUS {err} when trying to get the maximum path and mode sizes again"); + SharedLogger.logger.Error($"WinLibrary/GetAllAdapterIDs: ERROR - GetDisplayConfigBufferSizes returned WIN32STATUS {err} when trying to get the maximum path and mode sizes again"); throw new WinLibraryException($"GetDisplayConfigBufferSizes returned WIN32STATUS {err} when trying to get the maximum path and mode sizes again"); } - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Getting the current Display Config path and mode arrays"); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Getting the current Display Config path and mode arrays"); paths = new DISPLAYCONFIG_PATH_INFO[pathCount]; modes = new DISPLAYCONFIG_MODE_INFO[modeCount]; err = CCDImport.QueryDisplayConfig(QDC.QDC_ALL_PATHS, ref pathCount, paths, ref modeCount, modes, IntPtr.Zero); if (err == WIN32STATUS.ERROR_INSUFFICIENT_BUFFER) { - SharedLogger.logger.Error($"WinLibrary/GetCurrentAdapterIDs: ERROR - The displays were still modified between GetDisplayConfigBufferSizes and QueryDisplayConfig, even though we tried twice. Something is wrong."); + SharedLogger.logger.Error($"WinLibrary/GetAllAdapterIDs: ERROR - The displays were still modified between GetDisplayConfigBufferSizes and QueryDisplayConfig, even though we tried twice. Something is wrong."); throw new WinLibraryException($"The displays were still modified between GetDisplayConfigBufferSizes and QueryDisplayConfig, even though we tried twice. Something is wrong."); } else if (err != WIN32STATUS.ERROR_SUCCESS) { - SharedLogger.logger.Error($"WinLibrary/GetCurrentAdapterIDs: ERROR - QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays again"); + SharedLogger.logger.Error($"WinLibrary/GetAllAdapterIDs: ERROR - QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays again"); throw new WinLibraryException($"QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays again."); } } else if (err != WIN32STATUS.ERROR_SUCCESS) { - SharedLogger.logger.Error($"WinLibrary/GetCurrentAdapterIDs: ERROR - QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays"); + SharedLogger.logger.Error($"WinLibrary/GetAllAdapterIDs: ERROR - QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays"); throw new WinLibraryException($"QueryDisplayConfig returned WIN32STATUS {err} when trying to query all available displays."); } @@ -2341,7 +2344,7 @@ public List GetCurrentPCIVideoCardVendors() if (path.TargetInfo.TargetAvailable == false) { // We want to skip this one cause it's not valid - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Skipping path due to TargetAvailable not existing in display #{path.TargetInfo.Id}"); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Skipping path due to TargetAvailable not existing in display #{path.TargetInfo.Id}"); continue; } @@ -2354,12 +2357,12 @@ public List GetCurrentPCIVideoCardVendors() err = CCDImport.DisplayConfigGetDeviceInfo(ref adapterInfo); if (err == WIN32STATUS.ERROR_SUCCESS) { - SharedLogger.logger.Trace($"WinLibrary/GetCurrentAdapterIDs: Successfully got the display name info from {path.TargetInfo.Id}."); + SharedLogger.logger.Trace($"WinLibrary/GetAllAdapterIDs: Successfully got the display name info from {path.TargetInfo.Id}."); currentAdapterMap[path.TargetInfo.AdapterId.Value] = adapterInfo.AdapterDevicePath; } else { - SharedLogger.logger.Warn($"WinLibrary/GetCurrentAdapterIDs: WARNING - DisplayConfigGetDeviceInfo returned WIN32STATUS {err} when trying to get the target info for display #{path.TargetInfo.Id}"); + SharedLogger.logger.Warn($"WinLibrary/GetAllAdapterIDs: WARNING - DisplayConfigGetDeviceInfo returned WIN32STATUS {err} when trying to get the target info for display #{path.TargetInfo.Id}"); } }