Inno Setup-使用通配符注册表项设置DefaultDir? [英] Inno Setup - Setting DefaultDir using wildcard registry entry?

查看:147
本文介绍了Inno Setup-使用通配符注册表项设置DefaultDir?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've recently started using Inno Setup to try and create a simple .exe installer for a game modification.

在大多数情况下,我的安装程序都能正常运行,但是目前这有点基本.我真正希望安装程序执行的操作是自动找到该Mod设计的游戏的安装目录(战争黎明-黑暗十字军),因此用户无需手动浏览到该目录.

I've got the installer working fine for the most part, but it's a little basic at the moment. What I would really like the installer to do is to automatically find the install directory of the game the mod is designed for (Dawn of War - Dark Crusade) so the user doesn't need to browse to it manually.

我已阅读Inno安装程序可以根据注册表项设置DefaultDir.但是,尽管目标"游戏确实创建了一个包含其安装目录的注册表项,但该游戏可以以数字方式(通过Steam)或物理购买,并且根据购买的格式来创建不同的注册表项.两种格式,但是如果存在多种可能的注册表项格式,我不知道如何设置DefaultDir.

I've read that Inno installer can set a DefaultDir as per a registry entry. However, while the 'target' game does create a registry entry containing its install directory, the game can be purchased either digitally (through Steam) or physically, and it creates different registry entries depending on the format it's bought in. My mod works with either format, but I don't know how to set the DefaultDir if there's more than one possible registry key format.

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

Is there some sort of 'wilcard' function that will return the game's install directory from its registry entry without my having to enter the exact, full registry key value (ie, some sort of registry wildcard)? Or of searching for the two possible values it could have, then defaulting to {src} if it doesn't find either?

推荐答案

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

You can assign value of a DefaultDirName directive through the [Code] section. For instance, the following pseudo-script shows how to query two string values in registry and return the first found to the DefaultDirName directive. If none of the queried registry values is found, a default constant value is returned:

[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;

这篇关于Inno Setup-使用通配符注册表项设置DefaultDir?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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