使用 Inno Setup 安装 mod/plugin 时如何从注册表获取目标游戏/应用程序的安装路径? [英] How to get path of installation of target game/application from registry when installing mod/plugin using Inno Setup?

查看:20
本文介绍了使用 Inno Setup 安装 mod/plugin 时如何从注册表获取目标游戏/应用程序的安装路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

例如:

  • 如果我有 Steam 版本,需要从 Steam 的注册表中检测安装路径
  • 如果我有GOG版本需要从注册表中检测GOG的安装路径
  • 如果我有两个版本(Steam 和 GOG),那么默认安装路径将是 Steam 版本
  • 如果我没有任何版本,则用户自己选择目的地

注册表项:

  • 蒸汽:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstallSteam App 475150] 
"InstallLocation"="E:\Games\Software\Steam\steamapps\common\Titan Quest Anniversary Edition" 

  • GOG:

  • GOG:

    [HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeGOG.comGames1196955511] 
    "path"="D:\Titan Quest GOG"
    

  • 我知道如何检测一条路径

    I know how detect one path

    DefaultDirName={reg:HKLMSOFTWAREMicrosoftWindowsCurrentVersionUninstallSteam App 475150, InstallLocation}
    

    但我不知道如何检测多条路径.

    But I don't know how detect many paths.

    推荐答案

    使用 脚本常量RegQueryStringValue 函数:

    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, 'SOFTWAREMicrosoftWindowsCurrentVersionUninstallSteam App 475150',
             'InstallLocation', InstallationPath) then
        begin
          Log('Detected Steam installation: ' + InstallationPath);
        end
          else
        if RegQueryStringValue(
             HKLM32, 'SOFTWAREGOG.comGames1196955511',
             'path', InstallationPath) then
        begin
          Log('Detected GOG installation: ' + InstallationPath);
        end
          else
        begin
          InstallationPath := 'C:yourdefaultpath';
          Log('No installation detected, using the default path: ' + InstallationPath);
        end;
      end;
      Result := InstallationPath;
    end;
    

    这篇关于使用 Inno Setup 安装 mod/plugin 时如何从注册表获取目标游戏/应用程序的安装路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆