/// <summary> /// Checks if the current game is in the specified state /// </summary> /// <param name="gameState">the state to check if the game is in</param> /// <param name="forceUpdate">whether to pull the latest state information from the registry</param> /// <returns>true if the game is in the specified state, otherwise false</returns> private bool CheckGameState(SteamGameState gameState, bool forceUpdate = true) { // Update to latest registry value if forced update if (forceUpdate) { UpdateGameState(gameState); } // Game can be muliple states thanks to bitwise operators return((_gameStates & gameState) != 0); }
// Gets the latest info of the specified state for the current game from the registry private bool UpdateGameState(SteamGameState gameState) { int? statusValue = WinRegistry.GetValueAsInt(_registryLocation, gameState.ToString()); bool isValid = statusValue.HasValue && statusValue.Value == 1; if (isValid) { _gameStates |= gameState; Console.WriteLine("Game is " + gameState.ToString()); } // else status key in registry is either invalid or false else { // Clears this bit flag from the status _gameStates &= ~gameState; Console.WriteLine("Game is NOT " + gameState.ToString()); } return(isValid); }