rajeshontheweb Posted June 12, 2009 Share Posted June 12, 2009 (edited) The Scite4Autoit3 AutoITWrapper uses a directive #AutoIt3Wrapper_Res_Fileversion=<Version Number> to set your application version. if your application is compiled you can get it from file get version, if not? this will help you... Func _GetAPPVersion() ; author rajesh v r Local $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFileHandle, $Line $ScriptFileHandle = FileOpen(@ScriptFullPath, 0) If $ScriptFileHandle = -1 Then SetError(@error, "File Could not be opened for reading") $retVal = "" Elseif StringInStr(FileReadLine($ScriptFileHandle, 1), "#Region ;**** Directives created by AutoIt3Wrapper_GUI ****") Then While 1 $Line = FileReadLine($ScriptFileHandle) If StringInStr($Line,"#AutoIt3Wrapper_Res_Fileversion=" )Then If Not StringInStr($Line,"StringInStr($Line,") Then $retVal = StringTrimLeft(StringStripWS($Line,3),32) ExitLoop Endif If StringInSTr($Line, "#EndRegion") then Exitloop If @error = -1 Then ExitLoop ; may never be used, coz we dont loop till end of script!!! EndIf WEnd EndIf EndIf Return $retVal EndFunc ;==>_GetAPPVersion > Wont work if u are not using the autoit wrapper gui directives. > wont work if u strip off all comment texts > <Edit> sorry, forgot to mention, this needs the autoitwrapper directives to be at the top of the script. will soon update it.. thx for reminding me, storme. Edited June 13, 2009 by rajeshontheweb Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
ResNullius Posted June 13, 2009 Share Posted June 13, 2009 (edited) How about with a RegExp? #AutoIt3Wrapper_Res_Fileversion=0.002;comment allowed? Yes, so don't want it returned as part of version Func _GetAPPVersion() Local $aVersion, $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFile = FileRead(@ScriptFullPath) $aVersion = StringRegExp($ScriptFile, "(?mi)(?:^\s*\#AutoIt3Wrapper_Res_Fileversion\s*?=\s*)(.*)(?:;.*\r)", 3) If IsArray($aVersion) then $retVal = $aVersion[0] $ScriptFile = "" $aVersion = "" EndIf Return $retVal EndFunc ;==>_GetAPPVersionAdmittedly, a FileReadLine() approach is probably faster on really long scripts...Edit: Watch out for line-wrapping Edited June 13, 2009 by ResNullius Link to comment Share on other sites More sharing options...
storme Posted June 13, 2009 Share Posted June 13, 2009 G'day rajeshontheweb Great concept and I will be using it in future scripts to check version numbers. Currently I ignore version control if it's not compiled, which has masked some logic errors. A couple of things to think on. - "#Region ;**** Directives created by AutoIt3Wrapper_GUI ***" may not be the first line in the script. I'd suggest puting it inside the while loop so it can be detected where ever it is. - There maybe spaces/tabs infront of "#AutoIt3Wrapper_Res_Fileversion=" so it maybe a good idea to trim these before checking. The Same with the version number it may have trailing spaces to that need to be removed. Well Done John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
rajeshontheweb Posted June 13, 2009 Author Share Posted June 13, 2009 strome, 2) StringStripWS($Line,3) does the stripping?? and thats the reason i didnt use stringleft, i use string in str instead. 1) one trouble was, for a basic start off, i had to let the user keep it at top. there is one bug i havent understood yet. when looping through full file contents of an active script, i didnt get to the end of file for a while !!! i tried to use file readline and post all to console, but after posting full file contents it still persists! so i have changed my mind to use some thing a little different. i am trying to use fileread to read full file contents if the first line doesnt contain the directives. but the reason i didnt use fileread in the first place was that if the script is big with too many lines, it will just waste the memory space. now that we have a regex check syntax (i am a big zero in regex) i will try to employ it. Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
storme Posted June 13, 2009 Share Posted June 13, 2009 2) StringStripWS($Line,3) does the stripping?? and thats the reason i didnt use stringleft, i use string in str instead.DOH! Sorry I missed that :-( 1) one trouble was, for a basic start off, i had to let the user keep it at top.I'm playing with your code to see if there is an easy way to handle this. If I come up with something I'll let you know. there is one bug i havent understood yet. when looping through full file contents of an active script, i didnt get to the end of file for a while !!!I think this could be your problem. You included If StringInStr($Line, "#EndRegion") Then ExitLoop If @error = -1 Then ExitLoop; may never be used, coz we dont loop till end of script!!! INSIDE the If StringInStr($Line,"#AutoIt3Wrapper_Res_Fileversion=" )Then So the WHILE 1 would never have exited. Anyway here is a modified verison of your script with the IF statements moved. See if this fixes your problem. Func _GetAPPVersion() ; author rajesh v r Local $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFileHandle, $Line $ScriptFileHandle = FileOpen(@ScriptFullPath, 0) If $ScriptFileHandle = -1 Then SetError(@error, "File Could not be opened for reading") $retVal = "" Elseif StringInStr(FileReadLine($ScriptFileHandle, 1), "#Region ;**** Directives created by AutoIt3Wrapper_GUI ****") Then While 1 $Line = FileReadLine($ScriptFileHandle) If @error = -1 Then ExitLoop ; may never be used, coz we dont loop till end of script!!! If StringInStr($Line,"#AutoIt3Wrapper_Res_Fileversion=" )Then If Not StringInStr($Line,"StringInStr($Line,") Then $retVal = StringTrimLeft(StringStripWS($Line,3),32) ExitLoop Endif EndIf If StringInSTr($Line, "#EndRegion") then Exitloop WEnd EndIf EndIf Return $retVal EndFunc ;==>_GetAPPVersion but the reason i didnt use fileread in the first place was that if the script is big with too many lines, it will just waste the memory space.I think the way you did it was fine. Reading an entire file into memory is a waste of time and memory. imho now that we have a regex check syntax (i am a big zero in regex) i will try to employ it.I'm Zero on regex as well. But IMHO I think the regex version (though elegant) would be a waste of resources for the reasons stated above. IE it reads in the entire file for something that maybe found in he first few lines. OF course it all depends on the size of the file. Hope this helps John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
storme Posted June 13, 2009 Share Posted June 13, 2009 G'day rajeshonthewebI couldn't help myself I did a bit of editing on your script to handle a few situations I thought it may encounter.Improvements (I hope!) to script :Removes ALL "white space" characters in the "AutoIt3Wrapper_Res_Fileversion" line"#Region ;**** Directives created by AutoIt3Wrapper_GUI ****" can now be anywhere in script not just the first lineFiles that don't have AutoIt3Wrapper_Res_Fileversion are handledIgnores "#AutoIt3Wrapper_Res_Fileversion" anywhere except the start of a lineHere is the edited version of your scriptFunc _GetAPPVersion() ; author rajesh v r ; http://www.autoitscript.com/forum/index.php?showtopic=96654 Local $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFileHandle, $Line, $DirectivesNotFound $ScriptFileHandle = FileOpen(@ScriptFullPath, 0) If $ScriptFileHandle = -1 Then SetError(@error, "File Could not be opened for reading") $retVal = "" Else $DirectivesNotFound = True While 1 $Line = FileReadLine($ScriptFileHandle) If @error Then ExitLoop ; may never be used, coz we dont loop till end of script!!! If $DirectivesNotFound Then If StringInStr(StringStripWS($Line, 3), "#Region ;**** Directives created by AutoIt3Wrapper_GUI ****") Then $DirectivesNotFound = False EndIf Else $Line = StringStripWS($Line, 8) ; Stripe ALL spaces from line If StringLeft($Line, 32) = "#AutoIt3Wrapper_Res_Fileversion=" Then $retVal = StringTrimLeft($Line, 32) ExitLoop EndIf If StringInStr($Line, "#EndRegion") Then ExitLoop EndIf WEnd EndIf EndIf Return $retVal EndFunc ;==>_GetAPPVersionHope you don't mind. Have fun!John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
ProgAndy Posted June 13, 2009 Share Posted June 13, 2009 (edited) why do you search for #Region ;**** Directives created by AutoIt3Wrapper_GUI ****" ? You can add the Version-directive without the Wrapper-GUI and then this line does not exist. Edited June 13, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
storme Posted June 13, 2009 Share Posted June 13, 2009 (edited) why do you search for #Region ;**** Directives created by AutoIt3Wrapper_GUI ****" ? You can add the Version-directive without the Wrapper-GUI and then this line does not exist. Good Point! I'd guess that most script writers would use the GUI though so it wouldn't be such a big problem. and those that don't use the GUI would know that the #Region statements have to be there for the script to work. Also "rajeshontheweb" used the #Region statements to short circuit the search so that the entire file didn't need to be searched if there wasn't a #AutoIt3Wrapper_Res_Fileversion in the #region section. BUT you do have a good point. How about this version that handles both situations? Func _GetAPPVersion() ; author rajesh v r ; http://www.autoitscript.com/forum/index.php?showtopic=96654 Local $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFileHandle, $Line, $DirectivesNotFound $ScriptFileHandle = FileOpen(@ScriptFullPath, 0) If $ScriptFileHandle = -1 Then SetError(@error, "File Could not be opened for reading") $retVal = "" Else $DirectivesNotFound = True While 1 $Line = FileReadLine($ScriptFileHandle) If @error Then ExitLoop ; may never be used, coz we dont loop till end of script!!! If $DirectivesNotFound Then If StringInStr(StringStripWS($Line, 3), "#Region ;**** Directives created by AutoIt3Wrapper_GUI ****") Then $DirectivesNotFound = False EndIf Else If StringInStr($Line, "#EndRegion") Then ExitLoop EndIf If StringLeft(StringStripWS($Line, 8), 32) = "#AutoIt3Wrapper_Res_Fileversion=" Then $retVal = StringTrimLeft($Line, 32) ExitLoop EndIf WEnd EndIf EndIf Return $retVal EndFunc ;==>_GetAPPVersion ?????? John Morrison Edited June 13, 2009 by storme Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
ProgAndy Posted June 13, 2009 Share Posted June 13, 2009 (edited) Good Point!I'd guess that most script writers would use the GUI though so it wouldn't be such a big problem. and those that don't use the GUI would know that the #Region statements have to be there for the script to work.Also "rajeshontheweb" used the #Region statements to short circuit the search so that the entire file didn't need to be searched if there wasn't a #AutoIt3Wrapper_Res_Fileversion in the #region section.Possibly you are right. If someone uses the directives without the GUI he should be able to edit this func, too So i don't know which one is better.One last thing: you missed to include a FileClose. Edited June 13, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
storme Posted June 13, 2009 Share Posted June 13, 2009 Possibly you are right. If someone uses the directives without the GUI he should be able to edit this func, too So i don't know which one is better.I prefer the second as it handles all of the situations without editing. So if either situation (expert/novice) uses the script it should be handled. One last thing: you missed to include a FileClose.DAM I'll blame that one on "rajeshontheweb" ..... it is his code. I'm just messing with it. Here is the new more-completerer version then the last complete version. Func _GetAPPVersion() ; author rajesh v r ; http://www.autoitscript.com/forum/index.php?showtopic=96654 Local $retVal If @Compiled Then $retVal = FileGetVersion(@ScriptFullPath, "FileVersion") Else Local $ScriptFileHandle, $Line, $DirectivesNotFound $ScriptFileHandle = FileOpen(@ScriptFullPath, 0) If $ScriptFileHandle = -1 Then SetError(@error, "File Could not be opened for reading") $retVal = "" Else $DirectivesNotFound = True While 1 $Line = FileReadLine($ScriptFileHandle) If @error Then ExitLoop ; may never be used, coz we dont loop till end of script!!! If $DirectivesNotFound Then If StringInStr(StringStripWS($Line, 3), "#Region ;**** Directives created by AutoIt3Wrapper_GUI ****") Then $DirectivesNotFound = False EndIf Else If StringInStr($Line, "#EndRegion") Then ExitLoop EndIf If StringLeft(StringStripWS($Line, 8), 32) = "#AutoIt3Wrapper_Res_Fileversion=" Then $retVal = StringTrimLeft($Line, 32) ExitLoop EndIf WEnd EndIf EndIf FileClose($ScriptFileHandle) Return $retVal EndFunc ;==>_GetAPPVersion Thanks for the help! John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
rajeshontheweb Posted June 11, 2011 Author Share Posted June 11, 2011 very sorry guys, didnt see the conversation at all. i have been hectic with other stuff and i hadnt seen this stuff even while i was busy in autoit itself. i will go through the above and get back to u soon. Started late is much better than having never started it!!!!Failure is another step towards success. I've been messing around with: Adding Entry to 'Hosts'File Information Lister (Logger)Yet Another AutoIT Error Handler Yet Another AutoIT Error Handler & Debugger Control your App's TaskBar Button YCurrency Ticker (Latest Release : 16 Apr 2009)_WinInetInternetCheckConnection UDF Symantec Definitions Lister UDF _GetLocalIPAddresses UDF UDF to get Special Folder Information WMI_NetworkAdapterConfiguration2Array WMI_CDRomDriveCapabilities _ScriptExists - Check if your au3 script is running!! Uninstaller UDF Get Version for your application (at script level or compiled stage) Uninstaller Pro - faster alternative to windows application removal applet Link to comment Share on other sites More sharing options...
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