使用 Inno Setup 安装 mod/plugin 时,如何从注册表中获取目标 game/application 的安装路径?

How to get path of installation of target game/application from registry when installing mod/plugin using Inno Setup?

我想为 mod 游戏创建安装程序。我需要检测游戏的安装位置。我知道注册表中游戏的路径在哪里。但游戏可以在另一个启动器中 - Steam、GOG。如何按顺序检测?

例如:

注册表项:

我知道如何检测一条路径

DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150, InstallLocation}

但是不知道怎么检测多条路径

使用 scripted constant and RegQueryStringValue function:

[Setup]
DefaultDirName={code:GetInstallationPath}

[Code]
var
  InstallationPath: string;

function GetInstallationPath(Param: string): string;
begin
  { Detected path is cached, as this gets called multiple times }
  if InstallationPath = '' then
  begin
    if RegQueryStringValue(
         HKLM64, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150',
         'InstallLocation', InstallationPath) then
    begin
      Log('Detected Steam installation: ' + InstallationPath);
    end
      else
    if RegQueryStringValue(
         HKLM32, 'SOFTWARE\GOG.com\Games96955511',
         'path', InstallationPath) then
    begin
      Log('Detected GOG installation: ' + InstallationPath);
    end
      else
    begin
      InstallationPath := 'C:\your\default\path';
      Log('No installation detected, using the default path: ' + InstallationPath);
    end;
  end;
  Result := InstallationPath;
end;