问题
I would like to create installer for mod of the game. And I need to detect where is installed the game. I know where is path of the game in registry. But the game can be in another launchers - Steam, GOG. How to detect in order?
For example:
- If I have steam version need to detect path of installation from registry for steam
- If I have GOG version need to detect path of installation from registry for GOG
- If I have both versions (Steam and GOG) then default path of installation will be for steam version
- If I don't have any versions then user own choose destination
Registry keys:
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\Games\1196955511] "path"="D:\\Titan Quest GOG"
I know how detect one path
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 475150, InstallLocation}
But I don't know how detect many paths.
回答1:
Use a 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\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;
来源:https://stackoverflow.com/questions/56576172/how-to-get-path-of-installation-of-target-game-application-from-registry-when-in