registry - 使用 Inno Setup 安装 mod/plugin 时如何从注册表中获取目标游戏/应用程序的安装路径?
问题描述
我想为游戏的mod创建安装程序。我需要检测安装游戏的位置。我知道注册表中游戏的路径在哪里。但是游戏可以在另一个启动器中——Steam、GOG。如何按顺序检测?
例如:
- 如果我有 Steam 版本,需要从注册表中检测安装路径以进行 Steam
- 如果我有 GOG 版本需要从 GOG 的注册表中检测安装路径
- 如果我有两个版本(Steam 和 GOG),那么默认安装路径将是 steam 版本
- 如果我没有任何版本,那么用户自己选择目的地
注册表项:
蒸汽:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150] "InstallLocation"="E:\\Games\\Software\\Steam\\steamapps\\common\\Titan Quest Anniversary Edition"
高格:
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GOG.com\Games\1196955511] "path"="D:\\Titan Quest GOG"
我知道如何检测一条路径
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150, InstallLocation}
但我不知道如何检测到多少条路径。
解决方案
[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\Games\1196955511',
'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;