From 6565e2f2cc4988d276014be2029ac3dc788ddd36 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Fri, 21 May 2021 14:41:49 +1200 Subject: [PATCH] Fixed error when removing unsaved startprograms The startPrograms UI would error when someone tried to remove an unsaved startprogram from the FLP. This has now been resolved. Also managed to update a warning in the logs when a program starts and the original exe is a loader that loads another exe then closes itself. I've provided that warning in the log file now. --- DisplayMagician/ShortcutRepository.cs | 29 +------- .../UIForms/ShortcutForm.Designer.cs | 6 +- DisplayMagician/UIForms/ShortcutForm.cs | 11 ++- DisplayMagicianShared/ProfileRepository.cs | 74 +++++++++++++++++-- 4 files changed, 79 insertions(+), 41 deletions(-) diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index bf069ef..338d653 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -61,9 +61,6 @@ namespace DisplayMagician logger.Warn(ex, $"ShortcutRepository/ShortcutRepository: Exception while trying to initialise CoreAudioController. Audio Chipset on your computer is not supported. You will be unable to set audio settings."); } - //_audioController.DefaultPlaybackDevice.SetAsDefault(); - //_audioController.DefaultCaptureDevice.SetAsDefault(); - // Load the Shortcuts from storage LoadShortcuts(); @@ -84,30 +81,6 @@ namespace DisplayMagician } } - /*public static Dictionary ShortcutWarningLookup - { - get - { - if (!_shortcutsLoaded) - // Load the Shortcuts from storage if they need to be - LoadShortcuts(); - - return _shortcutWarningLookup; - } - } - - public static Dictionary ShortcutErrorLookup - { - get - { - if (!_shortcutsLoaded) - // Load the Shortcuts from storage if they need to be - LoadShortcuts(); - - return _shortcutErrorLookup; - } - }*/ - public static int ShortcutCount { get @@ -1646,7 +1619,7 @@ namespace DisplayMagician logger.Error(ex, $"ShortcutRepository/RunShortcut: Couldn't access the wait status for a process we're trying to stop."); } catch (InvalidOperationException ex) { - logger.Error(ex, $"ShortcutRepository/RunShortcut: Couldn't kill the process as there is no process associated with the Process object."); + logger.Error(ex, $"ShortcutRepository/RunShortcut: Couldn't kill the process as the proicess appears to have closed already. This can be caused if your {processToStop.ProcessName}.exe loaded another exe then closed itself. DisplayMagician cannot track that sort of behaviour."); } catch (SystemException ex) { diff --git a/DisplayMagician/UIForms/ShortcutForm.Designer.cs b/DisplayMagician/UIForms/ShortcutForm.Designer.cs index 5bc948a..19ad808 100644 --- a/DisplayMagician/UIForms/ShortcutForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutForm.Designer.cs @@ -343,11 +343,11 @@ namespace DisplayMagician.UIForms this.lbl_disabled_shortcut_audio_chipset.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); this.lbl_disabled_shortcut_audio_chipset.ForeColor = System.Drawing.Color.White; this.lbl_disabled_shortcut_audio_chipset.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.lbl_disabled_shortcut_audio_chipset.Location = new System.Drawing.Point(326, 298); + this.lbl_disabled_shortcut_audio_chipset.Location = new System.Drawing.Point(263, 298); this.lbl_disabled_shortcut_audio_chipset.Name = "lbl_disabled_shortcut_audio_chipset"; - this.lbl_disabled_shortcut_audio_chipset.Size = new System.Drawing.Size(430, 22); + this.lbl_disabled_shortcut_audio_chipset.Size = new System.Drawing.Size(557, 22); this.lbl_disabled_shortcut_audio_chipset.TabIndex = 34; - this.lbl_disabled_shortcut_audio_chipset.Text = "Unsupported Audio Chipset. Setting audio isn\'t supported :("; + this.lbl_disabled_shortcut_audio_chipset.Text = "Unsupported Audio Chipset. Setting audio isn\'t supported on your computer :("; this.lbl_disabled_shortcut_audio_chipset.Visible = false; // // gb_capture_settings diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index c7b82c2..2b73067 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -1965,8 +1965,10 @@ namespace DisplayMagician.UIForms public void RemoveStartProgram(StartProgramControl startProgramControlToRemove) { - // If we find the start program then we need to remove it from the list - _shortcutToEdit.StartPrograms.Remove(startProgramControlToRemove.StartProgram); + // If we find the start program then we need to remove it from the list (only if one was supplied) + if (_shortcutToEdit.StartPrograms != null && _shortcutToEdit.StartPrograms.Count > 0) + _shortcutToEdit.StartPrograms.Remove(startProgramControlToRemove.StartProgram); + // And we remove the program control passed in to this function as well flp_start_programs.SuspendLayout(); flp_start_programs.Controls.Remove(startProgramControlToRemove); @@ -2113,7 +2115,10 @@ namespace DisplayMagician.UIForms private void btn_add_new_start_program_Click(object sender, EventArgs e) { - StartProgram newStartProgram = new StartProgram() { }; + // Create a new startProgram with sensible defaults + StartProgram newStartProgram = new StartProgram() { + CloseOnFinish = true + }; StartProgramControl newStartProgramControl = new StartProgramControl(newStartProgram, flp_start_programs.Controls.Count); newStartProgramControl.Dock = DockStyle.None; newStartProgramControl.Width = flp_start_programs.Width - 40; diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index f46b90e..dae6197 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -12,6 +12,7 @@ using WindowsDisplayAPI; using System.Diagnostics; using System.Text.RegularExpressions; using NvAPIWrapper.Native.GPU; +using System.Windows.Forms; namespace DisplayMagicianShared { @@ -27,6 +28,7 @@ namespace DisplayMagicianShared public static Version _version = new Version(1, 0, 0); private static ProfileItem _currentProfile; private static List _connectedDisplayIdentifiers = new List(); + private static bool notifiedEDIDErrorToUser = false; // Other constants that are useful public static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); @@ -905,13 +907,26 @@ namespace DisplayMagicianShared foreach (Display attachedDisplay in attachedDisplayDevices) { - DisplayAdapter displayAdapter = attachedDisplay.Adapter; - PathDisplayAdapter pathDisplayAdapter = displayAdapter.ToPathDisplayAdapter(); - PathDisplaySource pathDisplaySource = attachedDisplay.ToPathDisplaySource(); - PathDisplayTarget pathDisplayTarget = attachedDisplay.ToPathDisplayTarget(); + DisplayAdapter displayAdapter = null; + PathDisplayAdapter pathDisplayAdapter = null; + PathDisplaySource pathDisplaySource = null; + PathDisplayTarget pathDisplayTarget = null; + try { + // We keep these lines here to detect if there is an exception so we can report it + // nicely to the user. + displayAdapter = attachedDisplay.Adapter; + pathDisplayAdapter = displayAdapter.ToPathDisplayAdapter(); + pathDisplaySource = attachedDisplay.ToPathDisplaySource(); + pathDisplayTarget = attachedDisplay.ToPathDisplayTarget(); + + // This line is just to force an EDID lookup first up so that we can deterine if there is an issue + // with the Monitor, and then tell the user + string EDIDManufacturerId = pathDisplayTarget.EDIDManufactureId.ToString(); + + // print some trace messages so we can figure out issues if needed later SharedLogger.logger.Trace($"ProfileRepository/GenerateProfileDisplayIdentifiers: ADDN : {attachedDisplay.DeviceName}"); SharedLogger.logger.Trace($"ProfileRepository/GenerateProfileDisplayIdentifiers: ADDFN : {attachedDisplay.DisplayFullName}"); SharedLogger.logger.Trace($"ProfileRepository/GenerateProfileDisplayIdentifiers: ADDIN : {attachedDisplay.DisplayName}"); @@ -953,6 +968,22 @@ namespace DisplayMagicianShared SharedLogger.logger.Trace($"ProfileRepository/GenerateProfileDisplayIdentifiers: PDTTI : {pathDisplayTarget.TargetId}"); SharedLogger.logger.Trace($"ProfileRepository/GenerateProfileDisplayIdentifiers: PDTVRS : {pathDisplayTarget.VirtualResolutionSupport}"); } + catch (WindowsDisplayAPI.Exceptions.InvalidEDIDInformation ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception while trying to get information from your monitor {attachedDisplay.DisplayFullName} about it's configuration. DisplayMagician may not be able to use this monitor!"); + if (!notifiedEDIDErrorToUser) + { + MessageBox.Show( + $"Your monitor {attachedDisplay.DisplayFullName} is not responding when we ask about it's configuration. DisplayMagician may not be able to use this monitor!", @"DisplayMagician cannot talk to your monitor", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + notifiedEDIDErrorToUser = true; + } + } + catch (WindowsDisplayAPI.Exceptions.TargetNotAvailableException ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception while we were trying to access the DisplayTarget to gather information about your display configuration."); + } catch (Exception ex) { SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception accessing one of the WindowsDisplayAPI items to print it out during a TRACE session"); @@ -982,6 +1013,10 @@ namespace DisplayMagicianShared try { displayInfo.Add(pathDisplayTarget.ConnectorInstance.ToString()); + } + catch (WindowsDisplayAPI.Exceptions.TargetNotAvailableException ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception2 while we were trying to access the DisplayTarget to gather information about your display configuration."); } catch (Exception ex) { @@ -1001,27 +1036,51 @@ namespace DisplayMagicianShared { displayInfo.Add(pathDisplayTarget.EDIDManufactureCode.ToString()); } + catch (WindowsDisplayAPI.Exceptions.InvalidEDIDInformation ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers2: Exception while trying to get information from your monitor {attachedDisplay.DisplayFullName} about it's configuration. DisplayMagician may not be able to use this monitor!"); + } + catch (WindowsDisplayAPI.Exceptions.TargetNotAvailableException ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers2: Exception while we were trying to access the DisplayTarget to gather information about your display configuration."); + } catch (Exception ex) { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting Windows Display EDID Manufacturer Code from video card. Substituting with a # instead"); + SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers2: Exception getting Windows Display EDID Manufacturer Code from video card. Substituting with a # instead"); displayInfo.Add("#"); } try { displayInfo.Add(pathDisplayTarget.EDIDManufactureId.ToString()); } + catch (WindowsDisplayAPI.Exceptions.InvalidEDIDInformation ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers3: Exception while trying to get information from your monitor {attachedDisplay.DisplayFullName} about it's configuration. DisplayMagician may not be able to use this monitor!"); + } + catch (WindowsDisplayAPI.Exceptions.TargetNotAvailableException ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers3: Exception while we were trying to access the DisplayTarget to gather information about your display configuration."); + } catch (Exception ex) { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting Windows Display EDID Manufacturer ID from video card. Substituting with a # instead"); + SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers3: Exception getting Windows Display EDID Manufacturer ID from video card. Substituting with a # instead"); displayInfo.Add("#"); } try { displayInfo.Add(pathDisplayTarget.EDIDProductCode.ToString()); } + catch (WindowsDisplayAPI.Exceptions.InvalidEDIDInformation ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers4: Exception while trying to get information from your monitor {attachedDisplay.DisplayFullName} about it's configuration. DisplayMagician may not be able to use this monitor!"); + } + catch (WindowsDisplayAPI.Exceptions.TargetNotAvailableException ex) + { + SharedLogger.logger.Error(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers4: Exception while we were trying to access the DisplayTarget to gather information about your display configuration."); + } catch (Exception ex) { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting Windows Display EDID Product Code from video card. Substituting with a # instead"); + SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers4: Exception getting Windows Display EDID Product Code from video card. Substituting with a # instead"); displayInfo.Add("#"); } try @@ -1039,6 +1098,7 @@ namespace DisplayMagicianShared // Add it to the list of display identifiers so we can return it displayIdentifiers.Add(displayIdentifier); SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}"); + } }