steam-deck-tools/SteamController/Helpers/SteamManager.cs
Kamil Trzciński 10d6c055da Add Process and Steam detection
- This makes to autmatically swittch to controller
  when Playnite Fullscreen is in use.
- This makes to automatically disable when Steam
  is in Big Picture or running Game
- Indicate current status with well distinguishable icons
- Expose all options via Context Menu
2022-11-26 10:19:50 +01:00

61 lines
1.7 KiB
C#

using System.Diagnostics;
using Microsoft.Win32;
namespace SteamController.Helpers
{
internal static class SteamManager
{
public const String SteamKey = @"Software\Valve\Steam";
public const String RunningAppIDValue = @"RunningAppID";
public const String BigPictureInForegroundValue = @"BigPictureInForeground";
public const String ActiveProcessKey = @"Software\Valve\Steam\ActiveProcess";
public const String PIDValue = @"pid";
public static bool? IsRunning
{
get
{
var value = GetValue<int>(ActiveProcessKey, PIDValue);
if (value is null)
return null;
if (Process.GetProcessById(value.Value) is null)
return false;
return true;
}
}
public static bool? IsBigPictureMode
{
get
{
var value = GetValue<int>(SteamKey, BigPictureInForegroundValue);
return value.HasValue ? value != 0 : null;
}
}
public static bool? IsRunningGame
{
get
{
var value = GetValue<int>(SteamKey, RunningAppIDValue);
return value.HasValue ? value != 0 : null;
}
}
private static T? GetValue<T>(string key, string value) where T : struct
{
try
{
using (var registryKey = Registry.CurrentUser.OpenSubKey(key))
{
return registryKey?.GetValue(value) as T?;
}
}
catch (Exception)
{
return null;
}
}
}
}