Inno Setup预处理程序可以使用FileOpen读取文件,但不能使用ReadIni [英] Inno Setup preprocessor can read a file using FileOpen, but not using ReadIni

查看:164
本文介绍了Inno Setup预处理程序可以使用FileOpen读取文件,但不能使用ReadIni的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对下面提到的现有职位的澄清要求
如何声明Inno设置通过从文件中读取预处理器变量

This is a clarification required to the existing post mentioned below
How to declare an Inno Setup preprocessor variable by reading from a file

使用FileOpen.txt文件读取值可以很好地工作,而使用ReadIni读取.ini文件则返回一个空字符串.

Reading value from .txt file using FileOpen works perfectly fine, while reading .ini file using ReadIni returns an empty string.

从txt文件读取的代码是:

The code for reading from txt file is:

#define VerFile FileOpen("common\GlobalConfig.txt")
#define AppVer FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile

txt文件具有字符串 Innovation .

The txt file has the string Innovation.

从ini文件读取的代码是:

The code for reading from ini file is:

#define AppVer ReadIni("common\GlobalConfig.ini", "Productname", "Product")

ini文件的内容为:

The content of the ini file is:

[Productname]
Product=Innovation

两个文件都位于相同的文件夹位置.

Both the files are in the same folder location.

该文件使用UTF-8编码,而没有BOM.我也检查了其他类型的编码,但它只返回空.我是用记事本++创建的.

The file is encoded with UTF-8 without BOM. I've checked with other types of encoding too, but it is returning only empty. I created with Notepad++.

提前谢谢!

推荐答案

ReadIni中的相对路径被解析为当前工作目录,特别是在Inno Setup IDE中不是脚本目录.

The relative paths in ReadIni are resolved to the current working directory, what particularly in Inno Setup IDE is not the script directory.

通过使用SourcePath 预定义变量来使用绝对路径:

Use absolute paths by using SourcePath predefined variable:

#define AppVer ReadIni(SourcePath + "\common\GlobalConfig.ini", "Productname", "Product")

对于FileOpen,ISPP会自动执行此操作,但对于ReadIni,则不会自动执行该操作.

For FileOpen ISPP does that automatically, but not for ReadIni.

虽然不是您的情况,但另一种可能性是INI文件有问题.必须为不带BOM的UTF-8/ASCII或不带BOM的UTF-16 LE.

While not your case, another possibility is that there's something wrong with the INI file. It has to be UTF-8/ASCII without BOM or UTF-16 LE (with or without BOM).

这篇关于Inno Setup预处理程序可以使用FileOpen读取文件,但不能使用ReadIni的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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