SimpleVersionMacro

From ISXKB

Jump to: navigation, search

The following is a macro to simplify a version string.

Definition

;
; Inno Setup Preprocessor macro to simplify the version string.
;
;	The following situations are covered:
;
;	(1)	1.2.4.3	-> 1.2.4
;	(2)	1.2.4.0	-> 1.2.4
;	(3)	1.2.0.0	-> 1.2
;	(4)	1.0.0.0	-> 1.0
;	(5)	1.0.0.2	-> 1.0
;	(6)	1.3.0.1	-> 1.3
;

#define SimpleVersion(str S) \
	Local[0] = Pos (".0.0.", S), \
	/* (4) and (5) */ \
	(Local[0] > 0) ? Copy (S, 1, 3) : \
	( \
		Local[0] = Pos (".0.0", S), \
		/* (3) */ \
		(Local[0] > 0) ? Copy (S, 1, 3) : \
		( \
			Local[0] = Pos (".0", S), \
			/* (2) */ \
			(Local[0] > 5) ? Copy (S, 1, Local[0] - 1) : \
			( \
				Local[0] = Pos (".0.", S), \
				/* (6) */ \
				(Local[0] > 0) ? Copy (S, 1, 3) : \
				( \
					Copy (S, 1, 5) \
				) \
			) \
		) \
	);

Example

This is how the macro can be used.

#define MyAppVersion GetFileVersion(AddBackslash(SourcePath) + "MyApplication.exe")
#define MySimpleAppVersion SimpleVersion(MyAppVersion)

#pragma message "*** Version info ***
#pragma message "Detailed version info: " + MyAppVersion
#pragma message "Simple version info:   " + MySimpleAppVersion

[Setup]
AppID={#MyAppID}
AppName={#MyAppName}
AppVersion=SimpleVersion({#MyAppVersion})
AppVerName={#MyAppName} {#MySimpleAppVersion}

See also

Personal tools
Ads: