diff --git a/DisplayMagicianShared/NVIDIA/SurroundTopology.cs b/DisplayMagicianShared/NVIDIA/SurroundTopology.cs index cbd95dd..36a3488 100644 --- a/DisplayMagicianShared/NVIDIA/SurroundTopology.cs +++ b/DisplayMagicianShared/NVIDIA/SurroundTopology.cs @@ -52,19 +52,63 @@ namespace DisplayMagicianShared.NVIDIA public static SurroundTopology FromPathTargetInfo(PathTargetInfo pathTargetInfo) { // We go through the code if only the path belongs to a NVIDIA virtual surround display - // TODO: Should we try to resolve every target info to be sure? - if (!string.Equals( - pathTargetInfo.DisplayTarget.EDIDManufactureCode, - "NVS", - StringComparison.InvariantCultureIgnoreCase - ) && - !string.Equals( - pathTargetInfo.DisplayTarget.FriendlyName, - "NV Surround", - StringComparison.InvariantCultureIgnoreCase - ) && - !pathTargetInfo.DisplayTarget.DevicePath.ToLower().Contains("&UID5120".ToLower())) + // and is not null + if (pathTargetInfo == null) { + SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The PathTargetInfo object supplied was null, so we have to return null back."); + return null; + } + + string EDIDManufactureCode = ""; + string friendlyName = ""; + bool devicePathContainsUID5120 = false; + bool isNvidiaSurround = false; + try + { + EDIDManufactureCode = pathTargetInfo.DisplayTarget.EDIDManufactureCode; + SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed EDIDManufactureCode of {EDIDManufactureCode}."); + if (string.Equals(EDIDManufactureCode, "NVS", StringComparison.InvariantCultureIgnoreCase)) + { + isNvidiaSurround = true; + } + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access EDIDManufactureCode."); + } + + try + { + friendlyName = pathTargetInfo.DisplayTarget.FriendlyName; + SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed Display FriendlyName of {friendlyName}."); + if (string.Equals(friendlyName, "NV Surround", StringComparison.InvariantCultureIgnoreCase)) + { + isNvidiaSurround = true; + } + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access friendlyName."); + } + + try + { + devicePathContainsUID5120 = pathTargetInfo.DisplayTarget.DevicePath.ToLower().Contains("&UID5120".ToLower()); + SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Testing if the Display DevicePath contains UID5120 = {devicePathContainsUID5120}."); + if (devicePathContainsUID5120) + { + isNvidiaSurround = true; + } + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to access friendlyName."); + } + + // If the checks haven't passed, then we return null + if (!isNvidiaSurround) + { + SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: As far as we can tell, this isn't an NVIDIA Surround window, so we're returning null."); return null; } @@ -116,11 +160,12 @@ namespace DisplayMagicianShared.NVIDIA } } } - catch + catch (Exception ex) { - // ignored + SharedLogger.logger.Warn(ex, $"SurroundTopology/FromPathTargetInfo: Exception trying to get the Grid Topology from the NVIDIA driver."); } - + // if we get here, then we've failed to get the NVIDIA Grid Topology + SharedLogger.logger.Warn($"SurroundTopology/FromPathTargetInfo: We've tried to get the Grid Topology from the NVIDIA driver but we can't!"); return null; } diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 140c034..f8cda05 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -511,14 +511,20 @@ namespace DisplayMagicianShared int validDisplayCount = 0; //validDisplayCount = (from connectedDisplay in ProfileRepository.ConnectedDisplayIdentifiers select connectedDisplay == profileDisplayIdentifier).Count(); - + foreach (string profileDisplayIdentifier in ProfileDisplayIdentifiers) { // If this profile has a display that isn't currently available then we need to say it's a no! - //if (ProfileRepository.ConnectedDisplayIdentifiers.Contains(profileDisplayIdentifier)) - //validDisplayCount = (from connectedDisplay in ProfileRepository.ConnectedDisplayIdentifiers select connectedDisplay == profileDisplayIdentifier).Count(); if (ProfileRepository.ConnectedDisplayIdentifiers.Any(s => profileDisplayIdentifier.Equals(s))) + { + SharedLogger.logger.Trace($"ProfileItem/RefreshPossbility: We found the display in the profile {Name} with profileDisplayIdentifier {profileDisplayIdentifier} is connected now."); validDisplayCount++; + } + else + { + SharedLogger.logger.Warn($"ProfileItem/RefreshPossbility: We found the display in the profile {Name} with profileDisplayIdentifier {profileDisplayIdentifier} is NOT currently connected, so this profile cannot be used."); + } + } if (validDisplayCount == ProfileDisplayIdentifiers.Count) { diff --git a/DisplayMagicianShared/Topology/PathTarget.cs b/DisplayMagicianShared/Topology/PathTarget.cs index 3a44984..91063ce 100644 --- a/DisplayMagicianShared/Topology/PathTarget.cs +++ b/DisplayMagicianShared/Topology/PathTarget.cs @@ -18,23 +18,48 @@ namespace DisplayMagicianShared.Topology if (index > 0) { DevicePath = DevicePath.Substring(0, index).TrimEnd('#'); + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the DevicePath of {DevicePath}."); } FrequencyInMillihertz = targetInfo.FrequencyInMillihertz; + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the FrequencyInMillihertz of {FrequencyInMillihertz}."); Rotation = targetInfo.Rotation.ToRotation(); + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the Rotation of {Rotation}."); Scaling = targetInfo.Scaling.ToScaling(); + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the Scaling of {Scaling}."); ScanLineOrdering = targetInfo.ScanLineOrdering.ToScanLineOrdering(); + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the ScanLineOrdering of {ScanLineOrdering}."); try { DisplayName = targetInfo.DisplayTarget.FriendlyName; + SharedLogger.logger.Trace($"PathTarget/PathTarget: Grabbed the DisplayName of {DisplayName}."); + } - catch + catch (Exception ex) { + SharedLogger.logger.Warn(ex, $"PathTarget/PathTarget: Exception grabbing the DisplayName of {DisplayName} from the TargetInfo DisplayTarget."); DisplayName = null; } - SurroundTopology = surround ?? SurroundTopology.FromPathTargetInfo(targetInfo); + if (surround != null) + { + try + { + SurroundTopology = SurroundTopology.FromPathTargetInfo(targetInfo); + SharedLogger.logger.Trace($"PathTarget/PathTarget: The SurroundTopology object supplied was not null, and we found {SurroundTopology.Displays.Count()} displays involved in it {SurroundTopology.Columns}x{SurroundTopology.Rows}"); + } + catch (Exception ex) + { + SharedLogger.logger.Error(ex, $"PathTarget/PathTarget: A SurroundTopology object was supplied, but we had an exception getting the SurroundTopology from the PathTargetInfo object."); + } + + } + else + { + SharedLogger.logger.Trace($"PathTarget/PathTarget: This PathTarget doesn't use NVIDIA surround technology, so leaving the SurroundTopology null."); + } + }