You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何检测Delphi应用是否通过Steam Proton在Linux系统中运行?

Detecting Steam Proton (Linux) from a Delphi App

Great question! When your Windows-targeted app runs under Steam Proton on Linux, Proton's compatibility layer tricks the app into thinking it's still running natively on Windows—that's exactly why TOSVersion.Name keeps returning Windows instead of the actual Linux host.

Here are two reliable, easy-to-implement methods to detect if your app is running under Proton:

Method 1: Check Proton-Specific Environment Variables

Steam Proton sets several unique environment variables when launching Windows apps. You can check for these using Delphi's GetEnvironmentVariable function. If any of them exist, your app is running under Proton.

Delphi Code Example:

function IsRunningUnderProton: Boolean;
var
  EnvBuffer: array[0..255] of Char;
begin
  Result := False;

  // Check for common Proton/Steam Compat environment variables
  if GetEnvironmentVariable('STEAM_COMPAT_CLIENT_INSTALL_PATH', EnvBuffer, Length(EnvBuffer)) > 0 then
  begin
    Result := True;
    Exit;
  end;

  if GetEnvironmentVariable('STEAM_COMPAT_DATA_PATH', EnvBuffer, Length(EnvBuffer)) > 0 then
  begin
    Result := True;
    Exit;
  end;

  if GetEnvironmentVariable('PROTON_VERSION', EnvBuffer, Length(EnvBuffer)) > 0 then
  begin
    Result := True;
    Exit;
  end;
end;

Method 2: Check for Linux-System Files

Proton lets Windows apps access some Linux system files. You can try reading /proc/version—a file that exists on all Linux systems and contains details about the Linux kernel. If you can read this file and it mentions "Linux", you're running under Proton.

Delphi Code Example:

function IsRunningUnderProton: Boolean;
var
  ProcFile: TFileStream;
  ContentBuffer: array[0..1023] of Char;
  BytesRead: Integer;
begin
  Result := False;
  try
    // Attempt to open the Linux proc version file
    ProcFile := TFileStream.Create('/proc/version', fmOpenRead or fmShareDenyNone);
    try
      BytesRead := ProcFile.Read(ContentBuffer, SizeOf(ContentBuffer) - 1);
      if BytesRead > 0 then
      begin
        ContentBuffer[BytesRead] := #0;
        // Verify the file contains Linux kernel info
        if Pos('Linux', ContentBuffer) > 0 then
          Result := True;
      end;
    finally
      ProcFile.Free;
    end;
  except
    // If we can't open the file, we're likely on native Windows
    Result := False;
  end;
end;

Best Practice

For maximum accuracy, combine both methods: first check for the environment variables (fast and reliable), then fall back to the file check as a backup. This covers edge cases where some environment variables might not be set in rare Proton configurations.

Remember that TOSVersion will still report the Windows version that Proton is emulating (e.g., Windows 10), which can still be useful for your app's Windows-specific logic. The above functions just let you detect when that Windows environment is running on top of Linux via Proton.

内容的提问来源于stack exchange,提问作者Shaun Roselt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 12:47:45