/// <summary>
/// Manages active games by keeping an eye on their processes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ScanProcesses(object sender, ElapsedEventArgs e)
{
if (!ProgramEnabled)
{
return;
}
var runningProcesses = Process.GetProcesses();
// If the currently active effect is a disabled game, get rid of it.
if (EffectManager.ActiveEffect != null)
{
EffectManager.DisableInactiveGame();
}
if (EffectManager.ActiveEffect is ProfilePreviewModel)
{
return;
}
// If the currently active effect is a no longer running game, get rid of it.
var activeGame = EffectManager.ActiveEffect as GameModel;
if (activeGame != null)
{
if (!runningProcesses.Any(p => p.ProcessName == activeGame.ProcessName && p.HasExited == false))
{
Logger.Info("Disabling game: {0}", activeGame.Name);
EffectManager.DisableGame(activeGame);
}
}
// Look for running games, stopping on the first one that's found.
var newGame = EffectManager.EnabledGames
.FirstOrDefault(g => runningProcesses
.Any(p => p.ProcessName == g.ProcessName && p.HasExited == false));
if (newGame == null || EffectManager.ActiveEffect == newGame)
{
return;
}
// If it's not already enabled, do so.
Logger.Info("Detected and enabling game: {0}", newGame.Name);
EffectManager.ChangeEffect(newGame, LoopManager);
}