mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Changed shortcut cancellation logic
This commit is contained in:
parent
b062331c3d
commit
965f73377b
@ -25,6 +25,13 @@ namespace DisplayMagician {
|
|||||||
Uplay
|
Uplay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ApplyProfileResult
|
||||||
|
{
|
||||||
|
Successful,
|
||||||
|
Cancelled,
|
||||||
|
Error
|
||||||
|
}
|
||||||
|
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician");
|
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.
|
// 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");
|
logger.Debug($"Program/ApplyProfile: Starting");
|
||||||
|
|
||||||
@ -511,7 +518,7 @@ namespace DisplayMagician {
|
|||||||
if (!profile.IsPossible)
|
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.");
|
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)
|
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.");
|
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
|
try
|
||||||
@ -552,7 +559,7 @@ namespace DisplayMagician {
|
|||||||
|
|
||||||
if (timeoutForm.ShowDialog() == DialogResult.Cancel)
|
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
|
// We only want to do the topology change if the profile we're on now
|
||||||
@ -612,7 +619,7 @@ namespace DisplayMagician {
|
|||||||
if (!applyTopologyTask.IsCompleted)
|
if (!applyTopologyTask.IsCompleted)
|
||||||
{
|
{
|
||||||
logger.Debug($"Program/ApplyProfile: Failed to complete applying or removing the NVIDIA Surround profile");
|
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");
|
logger.Debug($"Program/ApplyProfile: Applying Profile PathInfo stage failed to complete");
|
||||||
|
|
||||||
if (!applyPathInfoTask.IsCompleted)
|
if (!applyPathInfoTask.IsCompleted)
|
||||||
return false;
|
return ApplyProfileResult.Error;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -653,13 +660,13 @@ namespace DisplayMagician {
|
|||||||
Console.WriteLine($"ProfileRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
Console.WriteLine($"ProfileRepository/ApplyTopology exception: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
|
||||||
{
|
{
|
||||||
logger.Debug($"Program/ApplyProfile: Failed to complete changing the Windows Display layout");
|
logger.Debug($"Program/ApplyProfile: Failed to complete changing the Windows Display layout");
|
||||||
return false;
|
return ApplyProfileResult.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileRepository.UpdateActiveProfile();
|
ProfileRepository.UpdateActiveProfile();
|
||||||
|
|
||||||
return true;
|
return ApplyProfileResult.Successful;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool LoadGamesInBackground()
|
public static bool LoadGamesInBackground()
|
||||||
|
@ -604,11 +604,20 @@ namespace DisplayMagician
|
|||||||
{
|
{
|
||||||
logger.Info($"ShortcutRepository/RunShortcut: Changing to the {rollbackProfile.Name} profile.");
|
logger.Info($"ShortcutRepository/RunShortcut: Changing to the {rollbackProfile.Name} profile.");
|
||||||
// Apply the 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");
|
Console.WriteLine($"ERROR - Cannot apply '{shortcutToUse.ProfileToUse.Name}' Display Profile");
|
||||||
logger.Error($"ShortcutRepository/RunShortcut: 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
|
// record the old audio device
|
||||||
@ -1393,12 +1402,21 @@ namespace DisplayMagician
|
|||||||
{
|
{
|
||||||
logger.Debug($"ShortcutRepository/RunShortcut: Rolling back display profile to {rollbackProfile.Name}");
|
logger.Debug($"ShortcutRepository/RunShortcut: Rolling back display profile to {rollbackProfile.Name}");
|
||||||
|
|
||||||
//if (!ProfileRepository.ApplyProfile(rollbackProfile))
|
ApplyProfileResult result = Program.ApplyProfile(rollbackProfile);
|
||||||
if (!Program.ApplyProfile(rollbackProfile))
|
|
||||||
|
if (result == ApplyProfileResult.Error)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"ERROR - Cannot revert back to '{rollbackProfile.Name}' Display Profile");
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace DisplayMagician.UIForms
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply the Profile
|
// Apply the Profile
|
||||||
if (Program.ApplyProfile(_selectedProfile))
|
if (Program.ApplyProfile(_selectedProfile) == ApplyProfileResult.Successful)
|
||||||
{
|
{
|
||||||
ChangeSelectedProfile(_selectedProfile);
|
ChangeSelectedProfile(_selectedProfile);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ using NvAPIWrapper.Native.GPU;
|
|||||||
namespace DisplayMagicianShared
|
namespace DisplayMagicianShared
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public static class ProfileRepository
|
public static class ProfileRepository
|
||||||
{
|
{
|
||||||
#region Class Variables
|
#region Class Variables
|
||||||
|
Loading…
Reference in New Issue
Block a user