如何在 Inno Setup 中从 INF 文件读取自定义值?
使用 Inno Setup 创建的安装程序可以通过 /LOADINF 选项读取 INI 文件。是否可以通过这个INI文件读取自定义变量?是否有函数可以获取此选项给出的 INI 文件的名称? (然后可以使用 INI 实用程序函数。)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代码
从命令行参数提供文件 INI 文件名。
如果 INF 文件位于安装文件夹中,请使用此代码
The code
provides the file INI file name from the command line parameters.
Use this code if the INF file is in the setup folder
我们只需使用
ParamStr(i)
函数迭代命令行参数,并查找以“/LOADINF=
”开头的参数,然后从那里提取文件名。最初我们遇到的一个问题是文件名可能是相对路径描述符(例如只是文件名)。但是,如果您使用压缩,则当前工作目录将是
%TEMP%
文件夹中的某个子文件夹,而不是 setup.exe 所在的目录。因此,您应该确保检测到这一点,并在必要时在给定的文件名前面添加AddBackslash(ExpandConstant('{src}'))
。We simply iterate over the commandline arguments using the
ParamStr(i)
function and look for an argument starting with "/LOADINF=
" and then extract the file name from there.One gotcha that got us initially was that the file name might be a relative path descriptor (e.g. just the file name). However, if you use compression then the current working directory will be some sub-folder in your
%TEMP%
folder rather than the directory where your setup.exe is. You should therefore make sure to detect this and prepend the given file name withAddBackslash(ExpandConstant('{src}'))
if necessary.