diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index e6d0e2d..a5431c8 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -25,6 +25,13 @@ namespace DisplayMagician { Uplay } + public enum ApplyProfileResult + { + Successful, + Cancelled, + Error + } + internal static class Program { internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); @@ -501,7 +508,7 @@ namespace DisplayMagician { } // ApplyProfile lives here so that the UI works. - public static bool ApplyProfile(ProfileItem profile) + public static ApplyProfileResult ApplyProfile(ProfileItem profile) { logger.Debug($"Program/ApplyProfile: Starting"); @@ -511,7 +518,7 @@ namespace DisplayMagician { if (!profile.IsPossible) { logger.Debug($"Program/ApplyProfile: The supplied profile {profile.Name} isn't currently possible to use, so we can't apply it. This means a display that existed before has been removed, or moved."); - return false; + return ApplyProfileResult.Error; } @@ -519,7 +526,7 @@ namespace DisplayMagician { if (profile.UUID == ProfileRepository.GetActiveProfile().UUID) { logger.Debug($"Program/ApplyProfile: The supplied profile {profile.Name} is currently in use, so we don't need to apply it."); - return false; + return ApplyProfileResult.Successful; } try @@ -552,7 +559,7 @@ namespace DisplayMagician { if (timeoutForm.ShowDialog() == DialogResult.Cancel) { - return false; + return ApplyProfileResult.Cancelled; } // We only want to do the topology change if the profile we're on now @@ -612,7 +619,7 @@ namespace DisplayMagician { if (!applyTopologyTask.IsCompleted) { logger.Debug($"Program/ApplyProfile: Failed to complete applying or removing the NVIDIA Surround profile"); - return false; + return ApplyProfileResult.Error; } } @@ -645,7 +652,7 @@ namespace DisplayMagician { logger.Debug($"Program/ApplyProfile: Applying Profile PathInfo stage failed to complete"); if (!applyPathInfoTask.IsCompleted) - return false; + return ApplyProfileResult.Error; } catch (Exception ex) @@ -653,13 +660,13 @@ namespace DisplayMagician { Console.WriteLine($"ProfileRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); { logger.Debug($"Program/ApplyProfile: Failed to complete changing the Windows Display layout"); - return false; + return ApplyProfileResult.Error; } } ProfileRepository.UpdateActiveProfile(); - return true; + return ApplyProfileResult.Successful; } public static bool LoadGamesInBackground() diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index 7919ecf..182ad00 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -604,11 +604,20 @@ namespace DisplayMagician { logger.Info($"ShortcutRepository/RunShortcut: Changing to the {rollbackProfile.Name} profile."); // Apply the Profile! - if (!Program.ApplyProfile(shortcutToUse.ProfileToUse)) + ApplyProfileResult result = Program.ApplyProfile(shortcutToUse.ProfileToUse); + if (result == ApplyProfileResult.Error) { Console.WriteLine($"ERROR - Cannot apply '{shortcutToUse.ProfileToUse.Name}' Display Profile"); logger.Error($"ShortcutRepository/RunShortcut: Cannot apply '{shortcutToUse.ProfileToUse.Name}' Display Profile"); + return; } + else if (result == ApplyProfileResult.Cancelled) + { + Console.WriteLine($"ERROR - User cancelled applying '{shortcutToUse.ProfileToUse.Name}' Display Profile"); + logger.Error($"ShortcutRepository/RunShortcut: User cancelled applying '{shortcutToUse.ProfileToUse.Name}' Display Profile"); + return; + } + } // record the old audio device @@ -1393,12 +1402,21 @@ namespace DisplayMagician { logger.Debug($"ShortcutRepository/RunShortcut: Rolling back display profile to {rollbackProfile.Name}"); - //if (!ProfileRepository.ApplyProfile(rollbackProfile)) - if (!Program.ApplyProfile(rollbackProfile)) + ApplyProfileResult result = Program.ApplyProfile(rollbackProfile); + + if (result == ApplyProfileResult.Error) { Console.WriteLine($"ERROR - Cannot revert back to '{rollbackProfile.Name}' Display Profile"); - logger.Error($"ShortcutRepository/RunShortcut: Rolling back display profile to {rollbackProfile.Name}"); + logger.Error($"ShortcutRepository/RunShortcut: Error rolling back display profile to {rollbackProfile.Name}"); + return; } + else if (result == ApplyProfileResult.Cancelled) + { + Console.WriteLine($"ERROR - User cancelled revert back to '{rollbackProfile.Name}' Display Profile"); + logger.Error($"ShortcutRepository/RunShortcut: User cancelled rolling back display profile to {rollbackProfile.Name}"); + return; + } + } } diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 6d5f116..6ce5f83 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -51,7 +51,7 @@ namespace DisplayMagician.UIForms } // Apply the Profile - if (Program.ApplyProfile(_selectedProfile)) + if (Program.ApplyProfile(_selectedProfile) == ApplyProfileResult.Successful) { ChangeSelectedProfile(_selectedProfile); } diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index a37ce54..d40868d 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -16,6 +16,7 @@ using NvAPIWrapper.Native.GPU; namespace DisplayMagicianShared { + public static class ProfileRepository { #region Class Variables