2013-03-25 171 views
4

我最近开始使用Inno Setup来尝试为游戏修改创建一个简单的.exe安装程序。Inno Setup - 使用通配符注册表项设置DefaultDir?

我的安装程序大部分工作正常,但目前有点基本。我真正喜欢安装程序要做的是自动找到mod所设计游戏的安装目录(战争黎明 - 黑暗十字军),这样用户就不需要手动浏览它。

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

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

回答

4

您可以通过[Code]部分指定DefaultDirName指令的值。例如,以下伪脚本显示了如何在注册表中查询两个字符串值,并将找到的第一个返回给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; 
+3

您可能希望'ExpandConstant'为默认名称。 – Miral 2013-03-25 19:44:26

4

除了使用[Code]其他地方一样回答,您还可以嵌套注册表常量:

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

这将使用供应商1的路径(如果存在);否则它会尝试Vendor2的路径,并且只有当它找不到其中的任何一个时,它才会回退到某个默认值。

+0

我喜欢这种方式。 [1] – TLama 2013-03-26 01:25:46