From 86776f1aba1e2d139e2eb1a88e7993ef08b53fdb Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Tue, 13 Oct 2020 21:25:10 +1300 Subject: [PATCH] SteamGame.IsRunning now works correctly Changed from using the Steam 'Running' Registry Key to using an actual Process detection method. Now works reliably and waits as expected! --- HeliosPlus/GameLibraries/SteamGame.cs | 12 ++++++++++-- HeliosPlus/ShortcutRepository.cs | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/HeliosPlus/GameLibraries/SteamGame.cs b/HeliosPlus/GameLibraries/SteamGame.cs index 2cc00b8..25a0cd3 100644 --- a/HeliosPlus/GameLibraries/SteamGame.cs +++ b/HeliosPlus/GameLibraries/SteamGame.cs @@ -25,6 +25,7 @@ using HeliosPlus.GameLibraries.SteamAppInfoParser; using TsudaKageyu; using System.Drawing.IconLib; using System.Drawing.IconLib.Exceptions; +using System.Diagnostics; namespace HeliosPlus.GameLibraries { @@ -40,6 +41,7 @@ namespace HeliosPlus.GameLibraries private string _steamGameName; private string _steamGamePath; private string _steamGameExe; + private string _steamGameProcessName; private string _steamGameIconPath; private static List _allInstalledSteamGames = null; @@ -67,6 +69,7 @@ namespace HeliosPlus.GameLibraries _steamGameName = steamGameName; _steamGamePath = steamGamePath; _steamGameExe = steamGameExe; + _steamGameProcessName = Path.GetFileNameWithoutExtension(_steamGameExe); _steamGameIconPath = steamGameIconPath; } @@ -89,7 +92,7 @@ namespace HeliosPlus.GameLibraries { get { - try + /*try { using ( var key = Registry.CurrentUser.OpenSubKey(_gameRegistryKey, RegistryKeyPermissionCheck.ReadSubTree)) @@ -116,7 +119,12 @@ namespace HeliosPlus.GameLibraries if (ex.Source != null) Console.WriteLine("IOException source: {0} - Message: {1}", ex.Source, ex.Message); throw; - } + }*/ + + bool isRunning = Process.GetProcessesByName(_steamGameProcessName) + .FirstOrDefault(p => p.MainModule.FileName + .StartsWith(GamePath,StringComparison.OrdinalIgnoreCase)) != default(Process); + return isRunning; } } diff --git a/HeliosPlus/ShortcutRepository.cs b/HeliosPlus/ShortcutRepository.cs index c8d5850..4b5cf2e 100644 --- a/HeliosPlus/ShortcutRepository.cs +++ b/HeliosPlus/ShortcutRepository.cs @@ -679,6 +679,9 @@ namespace HeliosPlus }*/ // Wait for the game to exit + + + if (steamGameToRun.IsRunning) { while (true) @@ -690,6 +693,7 @@ namespace HeliosPlus Thread.Sleep(300); } + Console.WriteLine($"{steamGameToRun.GameName} has been exited. Now continuing with cleanup tasks."); } // Remove the status notification icon from the status area