Initial partial creation of cancel logic

This code eventually will be used to allow the user to cancel waiting for the game/app. This won't work at the moment though as we actually monitor for the game on the UI thread (a big no no). I'll have to fix this in an upcoming update, but for now we'll leave it here.
This commit is contained in:
Terry MacDonald 2021-09-09 20:53:41 +12:00
parent 67bb58ae57
commit 914ee2cc06
3 changed files with 44 additions and 5 deletions

View File

@ -31,6 +31,7 @@ namespace DisplayMagician
//public static Dictionary<string, bool> _shortcutWarningLookup = new Dictionary<string, bool>(); //public static Dictionary<string, bool> _shortcutWarningLookup = new Dictionary<string, bool>();
//public static Dictionary<string, bool> _shortcutErrorLookup = new Dictionary<string, bool>(); //public static Dictionary<string, bool> _shortcutErrorLookup = new Dictionary<string, bool>();
private static bool _shortcutsLoaded = false; private static bool _shortcutsLoaded = false;
private static bool _cancelWait = false;
// Other constants that are useful // Other constants that are useful
private static string AppShortcutStoragePath = Path.Combine(Program.AppDataPath, $"Shortcuts"); private static string AppShortcutStoragePath = Path.Combine(Program.AppDataPath, $"Shortcuts");
private static string _shortcutStorageJsonFileName = Path.Combine(AppShortcutStoragePath, $"Shortcuts_{Version.ToString(2)}.json"); private static string _shortcutStorageJsonFileName = Path.Combine(AppShortcutStoragePath, $"Shortcuts_{Version.ToString(2)}.json");
@ -97,6 +98,11 @@ namespace DisplayMagician
get => new Version(1, 0, 0); get => new Version(1, 0, 0);
} }
public static bool CancelWait {
get => _cancelWait;
set => _cancelWait = value;
}
#endregion #endregion
#region Class Methods #region Class Methods
@ -1448,9 +1454,15 @@ namespace DisplayMagician
break; break;
} }
if (_cancelWait)
{
logger.Debug($"ShortcutRepository/RunShortcut: User requested we stop waiting. Exiting loop while waiting for {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} to close.");
break;
}
// Send a message to windows so that it doesn't think // Send a message to windows so that it doesn't think
// we're locked and try to kill us // we're locked and try to kill us
System.Threading.Thread.CurrentThread.Join(0); Thread.CurrentThread.Join(0);
Thread.Sleep(1000); Thread.Sleep(1000);
} }
logger.Debug($"ShortcutRepository/RunShortcut: {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} has exited."); logger.Debug($"ShortcutRepository/RunShortcut: {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} has exited.");
@ -1511,9 +1523,17 @@ namespace DisplayMagician
break; break;
} }
if (_cancelWait)
{
logger.Debug($"ShortcutRepository/RunShortcut: User requested we stop waiting. Exiting loop while waiting for {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} to close.");
break;
}
// Send a message to windows so that it doesn't think // Send a message to windows so that it doesn't think
// we're locked and try to kill us // we're locked and try to kill us
System.Threading.Thread.CurrentThread.Join(0); Thread.CurrentThread.Join(0);
// Pause for a second
Thread.Sleep(1000); Thread.Sleep(1000);
} }
logger.Debug($"ShortcutRepository/RunShortcut: Alternative Game Executable {altGameProcessToMonitor} has exited."); logger.Debug($"ShortcutRepository/RunShortcut: Alternative Game Executable {altGameProcessToMonitor} has exited.");
@ -1635,9 +1655,15 @@ namespace DisplayMagician
break; break;
} }
if (_cancelWait)
{
logger.Debug($"ShortcutRepository/RunShortcut: User requested we stop waiting. Exiting loop while waiting for {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} to close.");
break;
}
// Send a message to windows so that it doesn't think // Send a message to windows so that it doesn't think
// we're locked and try to kill us // we're locked and try to kill us
System.Threading.Thread.CurrentThread.Join(0); Thread.CurrentThread.Join(0);
Thread.Sleep(1000); Thread.Sleep(1000);
} }
logger.Debug($"ShortcutRepository/RunShortcut: {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} has exited."); logger.Debug($"ShortcutRepository/RunShortcut: {gameLibraryToUse.GameLibraryName} Game {gameToRun.Name} has exited.");

View File

@ -246,7 +246,7 @@
this.tsmi_delete.Text = "Delete Shortcut..."; this.tsmi_delete.Text = "Delete Shortcut...";
this.tsmi_delete.Click += new System.EventHandler(this.tsmi_delete_Click); this.tsmi_delete.Click += new System.EventHandler(this.tsmi_delete_Click);
// //
// lbl_masked_form // lbl_mask
// //
this.lbl_mask.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.lbl_mask.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
@ -255,7 +255,7 @@
this.lbl_mask.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lbl_mask.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_mask.ForeColor = System.Drawing.Color.White; this.lbl_mask.ForeColor = System.Drawing.Color.White;
this.lbl_mask.Location = new System.Drawing.Point(360, 306); this.lbl_mask.Location = new System.Drawing.Point(360, 306);
this.lbl_mask.Name = "lbl_masked_form"; this.lbl_mask.Name = "lbl_mask";
this.lbl_mask.Size = new System.Drawing.Size(415, 104); this.lbl_mask.Size = new System.Drawing.Size(415, 104);
this.lbl_mask.TabIndex = 33; this.lbl_mask.TabIndex = 33;
this.lbl_mask.Text = "lbl_masked_form"; this.lbl_mask.Text = "lbl_masked_form";
@ -289,6 +289,7 @@
this.Text = "DisplayMagician - Game Shortcuts"; this.Text = "DisplayMagician - Game Shortcuts";
this.Activated += new System.EventHandler(this.ShortcutLibraryForm_Activated); this.Activated += new System.EventHandler(this.ShortcutLibraryForm_Activated);
this.Load += new System.EventHandler(this.ShortcutLibraryForm_Load); this.Load += new System.EventHandler(this.ShortcutLibraryForm_Load);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ShortcutLibraryForm_KeyPress);
this.cms_shortcuts.ResumeLayout(false); this.cms_shortcuts.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@ -468,5 +468,17 @@ namespace DisplayMagician.UIForms
{ {
btn_delete.PerformClick(); btn_delete.PerformClick();
} }
private void ShortcutLibraryForm_KeyPress(object sender, KeyPressEventArgs e)
{
if (lbl_mask.Visible == true)
{
if (e.KeyChar == 27)
{
// We set the CancelWait to be true on ShortcutRespository, and it will be picked up bythe shortcut check.
ShortcutRepository.CancelWait = true;
}
}
}
} }
} }