Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

inno-setup

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?

like image 378
rogerdpack Avatar asked Jan 25 '13 21:01

rogerdpack


1 Answers

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.

like image 118
Miral Avatar answered Sep 17 '22 17:09

Miral