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!
This commit is contained in:
Terry MacDonald 2020-10-13 21:25:10 +13:00
parent 706c225dc7
commit 86776f1aba
2 changed files with 14 additions and 2 deletions

View File

@ -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<SteamGame> _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;
}
}

View File

@ -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