Inno Setup 预处理器可以使用 FileOpen 读取文件,但不能使用 ReadIni

Inno Setup preprocessor can read a file using FileOpen, but not using ReadIni

这是对下面提到的现有 post 的澄清
How to declare an Inno Setup preprocessor variable by reading from a file

使用 FileOpen.txt 文件读取值工作得很好,而使用 ReadIni returns 空字符串读取 .ini 文件。

读取txt文件的代码为:

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

txt 文件包含字符串 Innovation

读取ini文件的代码为:

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

ini文件内容为:

[Productname]
Product=Innovation

两个文件都在同一文件夹位置。

该文件使用无 BOM 的 UTF-8 编码。我也检查过其他类型的编码,但它只返回空的。我用Notepad++创建的。

提前致谢!

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

使用绝对路径 SourcePath predefined variable:

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

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


虽然不是你的情况,但另一种可能是 INI 文件有问题。它必须是 UTF-8/ASCII 没有 BOM 或 UTF-16 LE(有或没有 BOM)。