Game Is Running
This Pre-Execute Script will prevent a Node from starting a new file if a game is currently being played.
It checks some user defined directories
- C:\Program Files (x86)\Steam\steamapps\common
- C:\Games
Update these to suit your own requirements.
If a process if found running in one of those folders, then this script will stop the node from processing a file.
string[] gamePaths = new string[]
{
@"C:\Program Files (x86)\Steam\steamapps\common",
@"C:\Games"
};
var runningGames = Process.GetProcesses()
.Select(process =>
{
try
{
string processPath = process.MainModule?.FileName ?? string.Empty;
return new { process.ProcessName, processPath };
}
catch
{
// Ignore processes that we cannot access the path for
return null;
}
})
.Where(x => x != null && gamePaths.Any(path => x.processPath.StartsWith(path, StringComparison.OrdinalIgnoreCase)))
.ToList();
if (runningGames.Any())
{
StringBuilder log = new ();
log.AppendLine("The following game(s) are currently running from the specified game libraries:");
foreach (var game in runningGames)
{
log.AppendLine($"- {game.ProcessName} ({game.processPath})");
}
Logger.ILog(log.ToString());
SendNotification("Information", "Stream Game running", log.ToString());
return false;
}
else
{
Logger.ILog("No game is running from the specified game libraries.");
return false;
}