/// <summary> /// Gets the Steam process ID from the registry; returns 0 if Steam isn't running or isn't installed. /// </summary> /// <returns>Steam's process ID if it is running; otherwise, 0.</returns> public static int GetSteamPid() { if (!IsSteamInstalled) { return(0); } string pidRegKey; string pidRegName; if (SysNative.IsSystem64Bit()) { pidRegKey = @"HKEY_CURRENT_USER\Software\Valve\Steam\ActiveProcess"; pidRegName = "pid"; } else { pidRegKey = @"HKEY_LOCAL_MACHINE\Software\Valve\Steam"; pidRegName = "SteamPID"; } Logger.Info($"Attempting to retrieve Steam PID from registry value named '{pidRegName}' inside the key '{pidRegKey}'."); var pid = (int)Registry.GetValue(pidRegKey, pidRegName, -1); if (pid == -1) { Logger.Warning($"The Steam PID could not be retrieved because the registry value '{pidRegName}' or registry key '{pidRegKey}' was invalid or did not exist."); return(0); } Logger.Info($"The Steam PID value retrieved from the registry is '{pid}'."); return(pid); }
/// <summary> /// Retrieves the Source Mod installation path from the registry or returns null if not found. /// </summary> /// <returns>A string containing the Source Mod installation path.</returns> /// <exception cref="InvalidOperationException">Thrown when path could not be found.</exception> public static string GetSourceModPath() { string installPath; if (SysNative.IsSystem64Bit()) { installPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Valve\Steam", "SourceModInstallPath", null); } else { installPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Valve\Steam", "SourceModInstallPath", null); } if (installPath == null) { const string errorMsg = "No valid Steam ModInstallPath could be found."; Logger.Error(errorMsg); throw new InvalidOperationException(errorMsg); } installPath = installPath.Replace("/", @"\"); Logger.Info($"Setting Steam ModInstallPath to: '{installPath}'"); return(installPath); }