Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the setup filename be derived from the executable file version number?

Tags:

inno-setup

Is it possible to get Inno Setup to read the file version of the main executable file and set the name of the created setup to something like "myapp_setup_1_0_3708_19805.exe"?

like image 749
Keith Nicholas Avatar asked Feb 24 '10 22:02

Keith Nicholas


4 Answers

You should be able to do it like this:

(I haven't tried this recently but it certainly worked back in 2007 when I was using InnoSetup in this way. It might need some slight changes if Inno's syntax has changed since then.)

#define MainBinaryName  "MyMainFile.exe"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AVF1            Copy(AppVersion, 1, Pos(".", AppVersion) - 1) + "_" + Copy(AppVersion, Pos(".", AppVersion) + 1)
#define AVF2            Copy(AVF1,       1, Pos(".", AVF1      ) - 1) + "_" + Copy(AVF1      , Pos(".", AVF1      ) + 1)
#define AppVersionFile  Copy(AVF2,       1, Pos(".", AVF2      ) - 1) + "_" + Copy(AVF2      , Pos(".", AVF2      ) + 1)

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

If MyMainFile.exe was version 1.2.3.4 then that should call the finished installer setup_mytool_1_2_3_4.exe

The AVF1, AVF2, etc. stuff is just there to replace the dots (.) in the version number with underscores (_) to avoid causing problems with things that can't cope with lots of dots in a filename.

like image 104
Leo Davidson Avatar answered Oct 13 '22 22:10

Leo Davidson


; Get the App Version from Main Program
; This Is Full App Version Major.Minor.Build.Revision
; Store First 3 Parts of Version in ShortAppVersion to be used for SBS Assembly Installation Major.Minor.Build
#dim Version[4]
#expr ParseVersion("MainProgram.exe", Version[0], Version[1], Version[2], Version[3])
#define AppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2]) + "." + Str(Version[3])
#define ShortAppVersion Str(Version[0]) + "." + Str(Version[1]) + "." + Str(Version[2])
like image 24
Prads Avatar answered Oct 13 '22 23:10

Prads


GetFileVersion() (described in other answers) returns a string of the form "Major.Minor.Rev.Build." If you want access to the individual elements so that you can format the string yourself (say, if you only want "Major.Minor" or "Major.Minor.Rev"), you can use the following approach from the jrsoftware.innosetup mailing list:

#define VerMajor
#define VerMinor
#define VerRev
#define VerBuild
#define FullVersion=ParseVersion('PathTo.exe', VerMajor, VerMinor, VerRev, VerBuild)
#define MyAppVersion = Str(VerMajor) + "." + Str(VerMinor)
like image 2
TypeIA Avatar answered Oct 13 '22 22:10

TypeIA


A much cleaner way of doing this involves using the StringChange function, which allows replacing the dots with something else:

#define MainBinaryName  "MyMainFile.exe"
#define SourcePath      "Path/To/File"
#define SetupBaseName   "setup_mytool_"
#define AppVersion      GetFileVersion(AddBackslash(SourcePath) + MainBinaryName)
#define AppVersionFile  StringChange(AppVersion, ".", "_")

[Setup]
OutputBaseFilename={#SetupBaseName + AppVersionFile}

Also, if you don't want to show all four version numbers (e.g. you want it to say 1.0.1 instead of 1.0.1.0), you can replace the AppVersion line with the following:

#define NumberOfVersionPoints  3
#define AppVersion             Copy(GetFileVersion(AddBackslash(SourcePath) + MainBinaryName), 0, NumberOfVersionPoints * 2 - 1)
like image 1
Thunderforge Avatar answered Oct 13 '22 22:10

Thunderforge