Fixed failed waiting for game close

Added a 5 second delay before the start of
the monitoring for game closure. This is to
allow the games to be spawned by the game
library (e.g. Steam).
This commit is contained in:
Terry MacDonald 2020-12-11 11:43:51 +13:00
parent 41c48f6ef2
commit 58c8a7f9d2

View File

@ -702,7 +702,8 @@ namespace DisplayMagician
notifyIcon.Text = $"DisplayMagician: Running {steamGameToRun.Name.Substring(0, 41)}..."; notifyIcon.Text = $"DisplayMagician: Running {steamGameToRun.Name.Substring(0, 41)}...";
Application.DoEvents(); Application.DoEvents();
// Wait 5 seconds for the game process to spawn
Thread.Sleep(5000);
// Wait for the game to exit // Wait for the game to exit
Console.WriteLine($"Waiting for {steamGameToRun.Name} to exit."); Console.WriteLine($"Waiting for {steamGameToRun.Name} to exit.");
logger.Info($"ShortcutRepository/RunShortcut - waiting for Steam Game {steamGameToRun.Name} to exit."); logger.Info($"ShortcutRepository/RunShortcut - waiting for Steam Game {steamGameToRun.Name} to exit.");
@ -724,14 +725,14 @@ namespace DisplayMagician
// If the game is a Uplay Game we check for that // If the game is a Uplay Game we check for that
else if (shortcutToUse.GameLibrary.Equals(SupportedGameLibrary.Uplay)) else if (shortcutToUse.GameLibrary.Equals(SupportedGameLibrary.Uplay))
{ {
// We now need to get the SteamGame info // We now need to get the Uplay Game info
UplayGame uplayGameToRun = UplayLibrary.GetUplayGame(shortcutToUse.GameAppId); UplayGame uplayGameToRun = UplayLibrary.GetUplayGame(shortcutToUse.GameAppId);
// If the GameAppID matches a Steam game, then lets run it // If the GameAppID matches a Uplay game, then lets run it
if (uplayGameToRun is UplayGame) if (uplayGameToRun is UplayGame)
{ {
// Prepare to start the steam game using the URI interface // Prepare to start the Uplay game using the URI interface
// as used by Steam for it's own desktop shortcuts. // as used by Uplay for it's own desktop shortcuts.
var address = $"uplay://launch/{uplayGameToRun.Id}"; var address = $"uplay://launch/{uplayGameToRun.Id}";
logger.Debug($"ShortcutRepository/RunShortcut Uplay launch address is {address}"); logger.Debug($"ShortcutRepository/RunShortcut Uplay launch address is {address}");
if (shortcutToUse.GameArgumentsRequired) if (shortcutToUse.GameArgumentsRequired)
@ -747,7 +748,7 @@ namespace DisplayMagician
Console.WriteLine($"Starting Uplay Game: {uplayGameToRun.Name}"); Console.WriteLine($"Starting Uplay Game: {uplayGameToRun.Name}");
var uplayProcess = Process.Start(address); var uplayProcess = Process.Start(address);
// Wait for Steam game to update if needed // Wait for Uplay game to update if needed
var ticks = 0; var ticks = 0;
while (ticks < shortcutToUse.StartTimeout * 1000) while (ticks < shortcutToUse.StartTimeout * 1000)
{ {
@ -760,7 +761,7 @@ namespace DisplayMagician
} }
// Store the Steam Process ID for later // Store the Uplay Process ID for later
IPCService.GetInstance().HoldProcessId = uplayProcess?.Id ?? 0; IPCService.GetInstance().HoldProcessId = uplayProcess?.Id ?? 0;
IPCService.GetInstance().Status = InstanceStatus.OnHold; IPCService.GetInstance().Status = InstanceStatus.OnHold;
@ -771,6 +772,8 @@ namespace DisplayMagician
notifyIcon.Text = $"DisplayMagician: Running {uplayGameToRun.Name.Substring(0, 41)}..."; notifyIcon.Text = $"DisplayMagician: Running {uplayGameToRun.Name.Substring(0, 41)}...";
Application.DoEvents(); Application.DoEvents();
// Wait 5 seconds for the game process to spawn
Thread.Sleep(5000);
// Wait for the game to exit // Wait for the game to exit
Console.WriteLine($"Waiting for {uplayGameToRun.Name} to exit."); Console.WriteLine($"Waiting for {uplayGameToRun.Name} to exit.");
logger.Info($"ShortcutRepository/RunShortcut - waiting for Uplay Game {uplayGameToRun.Name} to exit."); logger.Info($"ShortcutRepository/RunShortcut - waiting for Uplay Game {uplayGameToRun.Name} to exit.");