使用 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。如何按顺序检测?
例如:
- 如果我有 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"
GOG:
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GOG.com\Games96955511]
"path"="D:\Titan Quest 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;
我想为 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"
GOG:
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GOG.com\Games96955511] "path"="D:\Titan Quest 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;