如何通过读取文件来声明Inno Setup预处理程序变量 [英] How to declare an Inno Setup preprocessor variable by reading from a file

查看:134
本文介绍了如何通过读取文件来声明Inno Setup预处理程序变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道您可以在Inno Setup中执行此操作:

Ok I know you can do this in Inno Setup:

#define AppVer "0.0.11"

然后像使用它

[Setup]
AppVerName={#AppVer}

现在假设我有一个名为VERSION的文件,其内容为"0.0.11".

Now imagine I have a file named VERSION whose contents are "0.0.11".

是否以某种方式将文件VERSION的内容导入Inno Setup预处理器变量?

Is there a way the contents of the file VERSION into the Inno Setup preprocessor variable somehow?

推荐答案

使用ISPP的GetFileVersion函数是首选方法(因为毕竟安装程序版本应与应用程序版本匹配).因此,如果这实际上是您想要做的,则应该接受jachguate的回答.

Using ISPP's GetFileVersion function is the preferred method (since your installer version should match your application's version, after all). So if this is what you actually wanted to do, you should accept jachguate's answer.

如果您确实想从文本文件而不是从可执行文件中读取版本,则有两种可能性:

In case you really do want to read the version from a text file instead of from the executable file, then there are two possibilities:

第一个:如果您可以修改文件的内部格式,则可以使它看起来像一个INI文件,从而可以大大简化事情:

The first: If you can modify the internal format of the file, then you can simplify things considerably by making it look like an INI file:

[Version]
Ver=0.0.11

鉴于此,您可以使用ISPP的ReadIni函数来检索版本:

Given this, you can use ISPP's ReadIni function to retrieve the version:

#define AppVer ReadIni("ver.ini", "Version", "Ver", "unknown")

如果不能更改文件格式,第二种选择是使用FileOpenFileReadFileClose ISPP函数,例如:

The second alternative, if you can't change the file format, is to use the FileOpen, FileRead, and FileClose ISPP functions, eg:

#define VerFile FileOpen("ver.txt")
#define AppVer FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile

不过,我重复一遍:最好从可执行文件本身获取应用程序版本.一方面,这有助于确保所有内容都匹配.

I repeat, though: it's better to get the app version from the executable file itself instead. This helps to ensure that everything matches up, for one thing.

这篇关于如何通过读取文件来声明Inno Setup预处理程序变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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