GEOSoft Posted February 27, 2007 Posted February 27, 2007 (edited) I'm just cleaning out some old code and I thought someone might be able to use this. I used it to automatically increment the $Ver = 1.0.0.0 in my AutoIt scripts at compile time so I wouldn't have to remember to manually change it. Slight modification will adapt ir to other uses. The example is built into this code. Just copy it into a new au3 script file and run it. Make sure that you read the top portion of the script. expandcollapse popup;=============================================================================== ; ; Description: Auto-increment the script version number of an AutoIt script ; Parameter(s): $hMax - The number of digits allowed in each segment of the version number. Default is 2 ; Requirement(s): The script must include the line $Ver = "" ; (The blank string can be replaced with a version number) ; You must use the lines in the INI settings region from #cs to #ce inclusive. ; Change the "ver=" string to your current ver. (not a blank) Always use the format shown ; Return Value(s): The new version number ; Author(s): GEOSoft ; Example(s): Example code is included in this script ; Note(s): Just run this script and it will change the script version number in this file. ; To use it against another file just change $File to the proper path\filename ; The maximum value for $Ver is 99.99.99.99 ; ;=============================================================================== #Region <<======== INI Settings #cs [Version] Ver=1.0.0.0 #ce #EndRegion <<======== INI Settings #Region <<======== Example $File = @ScriptFullPath $hArray = '' $Ver = '' $Cur_Ver = String(IniRead($File,'Version','Ver','1.0.0.0')) IniWrite($File,'Version', 'Ver', _Increment($Cur_Ver)) _FileReadToArray($File,$hArray) $v = String(IniRead($File,'Version','Ver','')) $aFile = FileOpen($File, 2) For $I = 1 To $hArray[0] If StringLeft($hArray[$I], 6) = '$Ver =' Then $hArray[$I] = '$Ver = ' & Chr(34) & $v & Chr34() FileWriteLine($aFile,$hArray[$I]) Next FileClose($aFile) MsgBox(0,'TEST','The version now reads ' & String(IniRead($File,'Version','Ver',''))) #EndRegion <<======== Example Func _Increment($hVer, $hMax = 2) Local $Inc = 0, $Rtn = '' $cVer = StringSplit($hVer,'.') If $cVer[0] <> 4 Then Return SetError(2) Else $cVer[$cVer[0]] += 1 For $I = $cVer[0] to 1 Step -1 If StringLen($cVer[$I]) > $hMax Then If $I <> 1 Then $cVer[$I] = 0 If $I -1 = 0 Then ExitLoop $cVer[$I-1] += 1 EndIf Next For $I = 1 To $cVer[0] $Rtn = $Rtn & '.' & String($cVer[$I]) Next Return StringTrimLeft($Rtn, 1) EndIf EndFunc ;<===> _Increment() Func _FileReadToArray($sFilePath, ByRef $aArray) Local $hFile $hFile = FileOpen($sFilePath, 0) If $hFile = -1 Then SetError(1) Return 0 EndIf $aArray = StringSplit( StringStripCR( FileRead($hFile, FileGetSize($sFilePath))), @LF) FileClose($hFile) Return 1 EndFunc ;==>_FileReadToArray ;;=============<< End of Script >>============ BTW: do not depend on the default value of the IniRead. That's why the information says not to use a blank string in the ini section. If you do or you depend o IniRead then the ini line will be randomly placed within your script. Notice that what is readlly happening is that there is a readable INI section in the script (between the #cs and #ce tags) and that is being updated. Edited March 11, 2007 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
jvanegmond Posted February 28, 2007 Posted February 28, 2007 Do professional programmers increment their software version by one each time they run it? github.com/jvanegmond
Gene Posted February 28, 2007 Posted February 28, 2007 (edited) Do professional programmers increment their software version by one each time they run it? No. I don't think he embeds this in each script. I used to use a similar scheme. To put it into effect, the update script was separate from the script to be compliled. From Win Explorer I would run "Compile with Options" after a right click. The first time I compiled a given script, I would click the compiler's "Run" Tab then I pasted a call like "UpDateVerNo.exe "ScriptToBeCompiledFileName.au3"into the "Run Before" text box. Then when I clicked the "Compile" button the ScriptToBeCompiled would be updated just before it was compiled. Of course you would have to code the updater script to take the "ScriptToBeCompiledFileName" from its command line. The only problem with this was that if the compile failed for any reason, I had to reset the version number in the script that failed.That said, I don't use this method any more and all of the above is from memory. Since I started using Component Software's RCS I'm back to manually setting the version at compile time because I haven't figured out how to get the version out of it programmatically. Didn't say I couldn't, said I haven't.Gene{edit 2/28/07a} Left out a sentence.{edit 2/28/07b} I had another thought, you could create an edited version of @GEOSOFT's UDF to decrement the version if the "new" ScriptToBeCompiledFileName.EXE does not exist and call it from the "Run after" text box.You could also embed the ScriptToBeCompiledFileName.au3.ini file in your ScriptToBeCompiledFileName.au3 (the names of the compiler directives change when embeded and you'd need to look them up). Then turn on Auto Incremnt Version and the compiler wrapper would increment the version each time you compile using the wrapper. Edited February 28, 2007 by Gene [font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...
GEOSoft Posted March 4, 2007 Author Posted March 4, 2007 (edited) No. I don't think he embeds this in each script. I used to use a similar scheme. To put it into effect, the update script was separate from the script to be compliled. From Win Explorer I would run "Compile with Options" after a right click. The first time I compiled a given script, I would click the compiler's "Run" Tab then I pasted a call like "UpDateVerNo.exe "ScriptToBeCompiledFileName.au3"into the "Run Before" text box. Then when I clicked the "Compile" button the ScriptToBeCompiled would be updated just before it was compiled. Of course you would have to code the updater script to take the "ScriptToBeCompiledFileName" from its command line. The only problem with this was that if the compile failed for any reason, I had to reset the version number in the script that failed.That said, I don't use this method any more and all of the above is from memory. Since I started using Component Software's RCS I'm back to manually setting the version at compile time because I haven't figured out how to get the version out of it programmatically. Didn't say I couldn't, said I haven't.Gene{edit 2/28/07a} Left out a sentence.{edit 2/28/07b} I had another thought, you could create an edited version of @GEOSOFT's UDF to decrement the version if the "new" ScriptToBeCompiledFileName.EXE does not exist and call it from the "Run after" text box.You could also embed the ScriptToBeCompiledFileName.au3.ini file in your ScriptToBeCompiledFileName.au3 (the names of the compiler directives change when embeded and you'd need to look them up). Then turn on Auto Incremnt Version and the compiler wrapper would increment the version each time you compile using the wrapper.I Just put the Ini section into each script then when I run my auto-compiler I have the option of updating the version number at compile time and that is usually only done when I create a new setup file.Edit: I should have said that I place the INI section in ant script that I intend to compile. Not into every script. Edited March 4, 2007 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
sshrum Posted March 5, 2007 Posted March 5, 2007 Personally, I give my apps a version number but I use the build info (last modified date / time) more as a definative source of my versioning since I tend to have numerous copies of the same version but different build times. The version number only serves as a reminder to me that something semi-substatial was done and notated Sean Shrum :: http://www.shrum.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot'
GEOSoft Posted March 5, 2007 Author Posted March 5, 2007 Personally, I give my apps a version number but I use the build info (last modified date / time) more as a definative source of my versioning since I tend to have numerous copies of the same version but different build times.The version number only serves as a reminder to me that something semi-substatial was done and notatedThe reason I used it was because most of my GUI's are written thusly$ttl = "My App "$Ver = "1.0.0.0"GUICreate($Ttl & $Ver)Or If its not used in the GUI Titlebar then $Ver will be used in the "About" dialog George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
GEOSoft Posted March 11, 2007 Author Posted March 11, 2007 I have corrected the Parameter(s) in the function information section (copy/Paste error) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now