Inno Setup - 使用通配符注册表项设置DefaultDir?

时间:2013-03-25 10:54:57

标签: registry inno-setup wildcard

我最近开始使用Inno Setup尝试为游戏修改创建一个简单的.exe安装程序。

我的安装程序大部分工作正常,但目前它有点基础。我真的希望安装程序能够自动找到mod为其设计的游戏的安装目录(Dawn of War - Dark Crusade),这样用户就不需要手动浏览它了。

我已经读过Inno安装程序可以根据注册表项设置DefaultDir。然而,虽然“目标”游戏确实创建了一个包含其安装目录的注册表项,但游戏可以通过数字方式(通过Steam)或物理方式购买,并根据其购买的格式创建不同的注册表项。我的mod可以使用格式,但如果有多种可能的注册表键格式,我不知道如何设置DefaultDir。

是否存在某种'wilcard'功能,它将从其注册表项返回游戏的安装目录,而无需输入完整的注册表项值(即某种注册表通配符)?或者搜索它可能具有的两个可能的值,如果找不到,则默认为{src}?

2 个答案:

答案 0 :(得分:4)

您可以通过DefaultDirName部分指定[Code]指令的值。例如,以下伪脚本显示如何在注册表中查询两个字符串值并将找到的第一个返回到DefaultDirName指令。如果未找到任何查询的注册表值,则返回默认常量值:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={code:GetDirName}

[Code]
function GetDirName(Value: string): string;
var          
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := '{pf}\Default Dir Name';
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'First Key', InstallPath) then
    Result := InstallPath
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'Second Key', InstallPath) then
    Result := InstallPath;
end;

答案 1 :(得分:4)

除了在其他地方使用[Code]之外,您还可以嵌套注册表常量:

DefaultDirName={reg:HKLM,Software\Vendor1\Application,InstallPath|{reg:HKLM,Software\Vendor2\Application,InstallPath|{pf}\DefaultInstallPath}}

这将使用Vendor1的路径(如果存在);如果它没有尝试Vendor2的路径,那么只有当它找不到其中任何一个时它才会回退到某个默认值。