Fixing slight logic error during restructure

Managed to break some logic when trying to
add robustness.... effectively doing the
opposite of what I was trying to do :/. Now
*should* be fixed, but we shall see with more
testing.
This commit is contained in:
Terry MacDonald 2021-05-19 22:24:04 +12:00
parent 2096322cf0
commit 0dc7c9c0d1
3 changed files with 42 additions and 18 deletions

View File

@ -140,7 +140,6 @@
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "DisplayMagician - Please Wait"; this.Text = "DisplayMagician - Please Wait";
this.TopMost = true;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ApplyingProfileForm_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ApplyingProfileForm_FormClosing);
this.Load += new System.EventHandler(this.ApplyingProfileForm_Reposition); this.Load += new System.EventHandler(this.ApplyingProfileForm_Reposition);
this.Shown += new System.EventHandler(this.ApplyingProfileForm_Shown); this.Shown += new System.EventHandler(this.ApplyingProfileForm_Shown);

View File

@ -62,14 +62,18 @@ namespace DisplayMagicianShared.NVIDIA
string EDIDManufactureCode = ""; string EDIDManufactureCode = "";
string friendlyName = ""; string friendlyName = "";
bool devicePathContainsUID5120 = false; bool devicePathContainsUID5120 = false;
bool isNvidiaSurround = false; bool isNvidiaEDID = false;
bool isNvidiaDeviceName = false;
bool isNvidiaDevicePath = false;
try try
{ {
EDIDManufactureCode = pathTargetInfo.DisplayTarget.EDIDManufactureCode; EDIDManufactureCode = pathTargetInfo.DisplayTarget.EDIDManufactureCode;
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed EDIDManufactureCode of {EDIDManufactureCode}."); SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed EDIDManufactureCode of {EDIDManufactureCode}.");
if (string.Equals(EDIDManufactureCode, "NVS", StringComparison.InvariantCultureIgnoreCase)) if (string.Equals(EDIDManufactureCode, "NVS", StringComparison.InvariantCultureIgnoreCase))
{ {
isNvidiaSurround = true; SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The EDIDManufactureCode of {EDIDManufactureCode} matches 'NVS', so this is an NVIDIA surround topology.");
isNvidiaEDID = true;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -83,7 +87,8 @@ namespace DisplayMagicianShared.NVIDIA
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed Display FriendlyName of {friendlyName}."); SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Grabbed Display FriendlyName of {friendlyName}.");
if (string.Equals(friendlyName, "NV Surround", StringComparison.InvariantCultureIgnoreCase)) if (string.Equals(friendlyName, "NV Surround", StringComparison.InvariantCultureIgnoreCase))
{ {
isNvidiaSurround = true; SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The Display FriendlyName of {friendlyName} matches 'NV Surround', so this is an NVIDIA surround topology.");
isNvidiaDeviceName = true;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -97,7 +102,8 @@ namespace DisplayMagicianShared.NVIDIA
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Testing if the Display DevicePath contains UID5120 = {devicePathContainsUID5120}."); SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Testing if the Display DevicePath contains UID5120 = {devicePathContainsUID5120}.");
if (devicePathContainsUID5120) if (devicePathContainsUID5120)
{ {
isNvidiaSurround = true; SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The Device Path contains UID5120, so this is an NVIDIA surround topology.");
isNvidiaDevicePath = true;
} }
} }
catch (Exception ex) catch (Exception ex)
@ -106,15 +112,16 @@ namespace DisplayMagicianShared.NVIDIA
} }
// If the checks haven't passed, then we return null // If the checks haven't passed, then we return null
if (!isNvidiaSurround) if (!isNvidiaEDID && !isNvidiaDeviceName && !isNvidiaDevicePath)
{ {
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: As far as we can tell, this isn't an NVIDIA Surround window, so we're returning null."); SharedLogger.logger.Warn($"SurroundTopology/FromPathTargetInfo: As far as we can tell, this isn't an NVIDIA Surround window, so we're returning null.");
return null; return null;
} }
try try
{ {
// Get parent DisplayConfig PathInfo by checking display targets // Get parent DisplayConfig PathInfo by checking display targets
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Get parent DisplayConfig PathInfo by checking display targets.");
var correspondingWindowsPathInfo = var correspondingWindowsPathInfo =
PathInfo.GetActivePaths() PathInfo.GetActivePaths()
.FirstOrDefault( .FirstOrDefault(
@ -127,6 +134,7 @@ namespace DisplayMagicianShared.NVIDIA
{ {
// Get corresponding NvAPI PathInfo // Get corresponding NvAPI PathInfo
// If position is same, then the two paths are equal, after all position is whats important in path sources // If position is same, then the two paths are equal, after all position is whats important in path sources
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Get corresponding NvAPI PathInfo. If position is same, then the two paths are equal, after all position is whats important in path sources");
var correspondingNvidiaPathInfo = var correspondingNvidiaPathInfo =
NvAPIWrapper.Display.PathInfo.GetDisplaysConfig() NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()
.FirstOrDefault( .FirstOrDefault(
@ -140,12 +148,14 @@ namespace DisplayMagicianShared.NVIDIA
{ {
// Get corresponding NvAPI PathTargetInfo // Get corresponding NvAPI PathTargetInfo
// We now assume that there is only one target for a NvAPI PathInfo, in an other word, for now, it is not possible to have a cloned surround display // We now assume that there is only one target for a NvAPI PathInfo, in an other word, for now, it is not possible to have a cloned surround display
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Get corresponding NvAPI PathTargetInfo. We now assume that there is only one target for a NvAPI PathInfo, in an other word, for now, it is not possible to have a cloned surround display");
var correspondingNvidiaTargetInfo = correspondingNvidiaPathInfo.TargetsInfo.FirstOrDefault(); var correspondingNvidiaTargetInfo = correspondingNvidiaPathInfo.TargetsInfo.FirstOrDefault();
if (correspondingNvidiaTargetInfo != null) if (correspondingNvidiaTargetInfo != null)
{ {
// Get corresponding NvAPI Grid Topology // Get corresponding NvAPI Grid Topology
// We also assume that the NVS monitor uses a similar display id to one of real physical monitors // We also assume that the NVS monitor uses a similar display id to one of real physical monitors
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Get corresponding NvAPI Grid Topology. We also assume that the NVS monitor uses a similar display id to one of real physical monitors");
var correspondingNvidiaTopology = var correspondingNvidiaTopology =
GridTopology.GetGridTopologies() GridTopology.GetGridTopologies()
.FirstOrDefault( .FirstOrDefault(
@ -154,8 +164,14 @@ namespace DisplayMagicianShared.NVIDIA
if (correspondingNvidiaTopology != null) if (correspondingNvidiaTopology != null)
{ {
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: Return the new NVIDIA Topology SurroundTopology object");
return new SurroundTopology(correspondingNvidiaTopology); return new SurroundTopology(correspondingNvidiaTopology);
} }
else
{
SharedLogger.logger.Trace($"SurroundTopology/FromPathTargetInfo: The correspondingNvidiaTopology SurroundTopology object wa null, so nothing to return");
return null;
}
} }
} }
} }

View File

@ -44,20 +44,29 @@ namespace DisplayMagicianShared.Topology
if (surround != null) if (surround != null)
{ {
try SharedLogger.logger.Trace($"PathTarget/PathTarget: This PathTarget supplied an NVIDIA surround object, so using the SurroundTopology supplied.");
{ SurroundTopology = surround;
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 else
{ {
SharedLogger.logger.Trace($"PathTarget/PathTarget: This PathTarget doesn't use NVIDIA surround technology, so leaving the SurroundTopology null.");
try
{
SurroundTopology = SurroundTopology.FromPathTargetInfo(targetInfo);
if (SurroundTopology != null)
{
SharedLogger.logger.Trace($"PathTarget/PathTarget: The SurroundTopology object supplied was null, so we created one ourselves. We found {SurroundTopology.Displays.Count()} displays involved in it {SurroundTopology.Columns}x{SurroundTopology.Rows}");
}
else
{
SharedLogger.logger.Trace($"PathTarget/PathTarget: The SurroundTopology object supplied was null, so we tried to create one ourselves and failed. This is likely a non NVIDIA surround display profile.");
}
}
catch (Exception ex)
{
SharedLogger.logger.Error(ex, $"PathTarget/PathTarget: A SurroundTopology object was not supplied, but we had an exception getting our own SurroundTopology from the PathTargetInfo object.");
}
} }
} }