How to declare an Inno Setup preprocessor variable by reading from a file

rogerdpack picture rogerdpack · Jan 25, 2013 · Viewed 18.8k times · Source

Ok I know you can do this in Inno Setup:

#define AppVer "0.0.11"

Then use it like

[Setup]
AppVerName={#AppVer}

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

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

Answer

Miral picture Miral · Jan 27, 2013

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:

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

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

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

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.