Code archives/Miscellaneous/Auto build numbers

This code has been declared by its author to be Public Domain code.

Download source code

Auto build numbers by matibee2012
Giving your app a build number is useful for support and updates and this is the method I derived for incrementing and providing a build number automatically.

There is another way documented on BB.com but as far as I know it involves tweaking the bmk module whereas this workaround runs on a plain blitzmax installation.

It works by reading and writing to a blitzmax source file that should be unique to your project. Each time the app is run in debug mode it increments the build number. Then, when your code is compiled in release mode for the outside world the build number is locked into it and no output to the .bmx file occurs.

Step 1. Create a "version.bmx" file for your project and give it a single line at the top of the file..

Global AutoBuildNumber$ = "0.0.0"


Step 2. Add the code below to your project.

Step 3. INCLUDE version.bmx into your source. Do not use import.

That's it. You can call up the global variable AutoBuildNumber$ in your app to display the version number.

For the version numbers I've used the format Version.Major.Minor. You may set the Version number (the first part) manually at any time by editing version.bmx, and leave the code to worry about the Major and Minor build numbers.
?DEBUG
	' choose a destination file here..
	
	IncrementAutoBuildNumber( "version.bmx" )

	' the destination file must already exist, and primed with the opening line..
	' Global AutoBuildNumber$ = "0.0.0"

	Function IncrementAutoBuildNumber( file$ )
		
		Local f:TStream = ReadFile( file$ )
		Local a$ = ReadLine(f)

		If ( Len(a$) = 0 )
			a$ = "Global AutoBuildNumber$" + "~q0.0.0~q"
		End If 
			
		CloseStream(f)
		
		Local q:Int = Instr( a$, "~q" ) + 1
		a$ = Mid$(a$, q, Len(a$) - q)
		'Print a$
		
		Local b$[] = a$.Split( "." )
		Local minor:Int = b$[1].ToInt()
		Local prefix:Int = b$[2].ToInt()
		
		prefix :+ 1
		If ( prefix > 9999 )
			minor :+ 1
			prefix = 0
		End If 	
		
		f = WriteFile( file$ )
		If ( f = Null ) Then 
			Notify ( "Auto build number failed" )
			Return 
		End If 
		
		WriteLine( f, "Global AutoBuildNumber$ = ~q" + b$[0] + "." + minor + "." + prefix + "~q" )
		CloseFile( f )
		
	End Function 
?

Comments

None.

Code Archives Forum