PartyPooper Posted June 30, 2008 Posted June 30, 2008 (edited) Got sick of my old internet file updater (INetUpdater UDF) and downloader (INetDownloader UDF) being so restrictive in it's functionality so I've created a whole new module and split up the functions so they can be used separately. I won't be maintaining the old one anymore because this module is superior. I've used ample commenting (probably too much) throughout the module to make it easy to follow and understand. I've tested it on several files, however, it may still contain bugs so let me know if you find any or have an idea for a better method of doing something. Unlike the old updater, this one has the ability to use either the locally produced progressbar window to show the status of a download or one of your own making in your own script (it passes back the size of the file).This module has the ability to compare file versions, compare file sizes, download files and automatically install updates using the following functions:_InetFile_VersionCheck_InetFile_SizeCheck_InetFile_Download_InetFile_InstallNOTE: If you intend using the default Remote Filename, you must compile your script before trying to check/download. The reason for doing this is because the @ScriptName macro changes filenames from "myscript.au3" to "myscript.exe" when called after compilation. If you don't compile it, you will end up trying to check the local "myscript.au3" against the remote "myscript.exe" and that won't work.Example of a simple usage:Automatically download and silently install an update of currently running script:Func Update() _InetFile_VersionCheck("www.mysite.com"); check for an update If Not @error Then; @error has not been set, therefore, there is an update available, download it _InetFile_Download("www.mysite.com"); download the update If Not @error Then; @error has not been set, therefore, the download was successful, install it _InetFile_Install(); automatically install the update EndIf EndIf EndFuncExamples of calls: _InetFile_VersionCheck("www.mysite.com") - checks currently running script for updates using defaults _InetFile_VersionCheck("www.mysite.com", "files", "myprogram.exe", "C:\Program Files\MyProg") - checks for an update of the file 'myprogram.exe' _InetFile_SizeCheck("www.mysite.com") - checks currently running script for file size change using defaults _InetFile_SizeCheck("www.mysite.com", "files", "myprogram.exe", "C:\Program Files\MyProg") - checks for a file size change of 'myprogram.exe' _InetFile_Download("www.mysite.com") - downloads currently running script displaying progress bar _InetFile_Download("www.mysite.com", "", "", "", 1) - downloads currently running script silently (no progress bar) _InetFile_Download("www.mysite.com", "files", "myprogram.exe", "C:\Program Files\MyProg") - downloads myprogram.exe displaying progress bar _InetFile_Download("www.mysite.com", "files", "myprogram.exe", "C:\Program Files\MyProg", 1) - downloads myprogram.exe silently (no progress bar) _InetFile_Install() - automatically install the currently running script. _InetFile_Install("", "" , "", 0) - drops a batchfile on to the desktop for a user to manually install the currently running script. _InetFile_Install("myprogram.exe", "C:\Program Files\MyProg") - creates an updating batchfile for "myprogram.exe"Edit1: Added the ability to suppress error messages and included them in the returned value (10 downloads)Edit2: Modified _InetFile_SizeCheck to allow checking and downloading of files regardless whether or not they exist locally (47 downloads)Edit3: Removed some code that prevented files being downloaded to @scriptdir. Hopefully, it won't break anything else (58 downloads)Edit4: Added $CmdLineRaw variable to _InetFile_Install batchfile routine so calling script command line options can be passed on when restarting after update (170 downloads)Edit5: Added error routine to _InetFile_Download to check for incomplete downloads (10 downloads) Edited December 17, 2008 by PartyPooper
PartyPooper Posted June 30, 2008 Author Posted June 30, 2008 (edited) I've updated the module and given it the optional ability to suppress error messages. They (the error messages) are now included as standard in the returned values. This will be useful for those that want to create their own error messages or those that want to embed an error message into a GUI rather than have a popup message box. Extracting the error message from the returned value is simple. It's been formatted as a direct substitution for the MsgBox function, but, you can use the elements however you wish. Here is a fictional example displaying the returned error message as a MsgBox: $s_RtnMsg = _InetFile_VersionCheck("www.mywebsite.com, "", "myprogram.exe", "", "", 1) If @error Then Local $a_Msg = StringSplit($s_RtnMsg, "|") MsgBox($a_Msg[1], $a_Msg[2], $a_Msg[3] & @CRLF & @CRLF & $a_Msg[4]) EndIf The StringSplit format is: $a_Msg[0] = number of elements in StringSplit $a_Msg[1] = MsgBox flag $a_Msg[2] = MsgBox title $a_Msg[3] = textual elements of MsgBox (header) $a_Msg[4] = textual elements of MsgBox (cause) Alternatively, you can ignore the returned error messages altogether: _InetFile_VersionCheck("www.mywebsite.com, "", "myprogram.exe") If @error Then ; do some error checking stuff of your own EndIf P.S. also squashed a small bug in the _InetFile_SizeCheck function Edited July 1, 2008 by PartyPooper
tlokz Posted July 1, 2008 Posted July 1, 2008 I can't seem to figure out how to do this.. I'm trying to have it check this site "http://files.aobot.org/T_LOKZz/vcf.ini"
PartyPooper Posted July 1, 2008 Author Posted July 1, 2008 (edited) What function and command line are you using? I notice you are using vcf.ini - unless you specified it, it won't work because the default is vcf.dat Edit: typo Edited July 1, 2008 by PartyPooper
PartyPooper Posted July 1, 2008 Author Posted July 1, 2008 Also, I checked out your vcf.ini and the format is correct only it is trying to find "Auto-Awesom.exe" which doesn't exist in that directory.
tlokz Posted July 1, 2008 Posted July 1, 2008 (edited) Also, I checked out your vcf.ini and the format is correct only it is trying to find "Auto-Awesom.exe" which doesn't exist in that directory.Lol Oh yea that would help wouldn't itEdit: This is whats in my script_InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini") Edited July 1, 2008 by tlokz
PartyPooper Posted July 1, 2008 Author Posted July 1, 2008 Lol Oh yea that would help wouldn't itEdit: This is whats in my script_InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini")That looks fine if this was part of the "Auto-Awesom.exe" program (I'm assuming by your vcf.ini that's the compiled script). I also assume that you ran the compiled script and not just the build from SciTE before trying to get it to check (the default @ScriptName macro changes from Auto-Awesom.au3 to Auto-Awesom.exe after compilation). I will put a note about this up in the first post in case it catches some people out.It should work once you put the remote file up.
tlokz Posted July 1, 2008 Posted July 1, 2008 (edited) That looks fine if this was part of the "Auto-Awesom.exe" program (I'm assuming by your vcf.ini that's the compiled script). I also assume that you ran the compiled script and not just the build from SciTE before trying to get it to check (the default @ScriptName macro changes from Auto-Awesom.au3 to Auto-Awesom.exe after compilation). I will put a note about this up in the first post in case it catches some people out.It should work once you put the remote file up.Yea I ran the compiled since I figured it gets the version number from the file versionedit: still doesn't work I put 4.6.0.2 up on the host with the ini to match and then change file version to 4.5.8.1 and compiled and ran and nothing Edited July 1, 2008 by tlokz
PartyPooper Posted July 1, 2008 Author Posted July 1, 2008 Ok, compile the following code as Auto-Awesom.exe and run it to see what's being returned: #include <InetFileUpdate.au3> #include <Array.au3> $s_RtnMsg = _InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini") _ArrayDisplay($s_RtnMsg) When I do it, it's reporting that the remote file version is 4.6.0.2 ($s_RtnMsg[1]) which is correct according to the vcf.ini file.
tlokz Posted July 1, 2008 Posted July 1, 2008 Ok, compile the following code as Auto-Awesom.exe and run it to see what's being returned: #include <InetFileUpdate.au3> #include <Array.au3> $s_RtnMsg = _InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini") _ArrayDisplay($s_RtnMsg) When I do it, it's reporting that the remote file version is 4.6.0.2 ($s_RtnMsg[1]) which is correct according to the vcf.ini file. Ok that worked, now how do u get it to check if its newer. Sorry for being such a noob
PartyPooper Posted July 2, 2008 Author Posted July 2, 2008 Damn, and I put so much time into providing what I thought was enough info - have a read of the module - it tells you... _InetFile_VersionCheck: ; Return values .: Success - sets @error 0 and returns an array where 0 = number of elements, 1 = remote file version, 2 = local file version ; Failure - either returns an appropriately formatted error message or a version array as above and sets @error: ; |@error = 1 (function parameter error) ; |@error = 2 (version / VCF error) ; |@error = 3 (file error) ; |@error = 4 (internet error) ; |@error = 5 (manual download required) ; |@error = 6 (no update available) ; |@error = 7 (you have a later version) If there hasn't been an error, the function ends with: If $i_Result = 0 Then; no update available Return SetError(6, 0, $a_RtnVal); return to calling script with versions ElseIf $i_Result = 1 Then; update available Return SetError(0, 0, $a_RtnVal); return to calling script with versions ElseIf $i_Result = -1 Then; you have a later version Return SetError(7, 0, $a_RtnVal); return to calling script with versions EndIf Translated: if @error=6 then there is no update available if @error=0 then there is an update available if @error=7 then you have a later version than the one being offered on the website If you have a look at the code I posted up in the first post, it shows you how to check for an update, download the update and automatically install it. It's all done by testing the @error macro. Here is a commented version (I'll edit the first post and include the comments so others can get an idea). If at any stage the @error gets set, the update won't proceed. Func Update() _InetFile_VersionCheck("www.mysite.com"); check for an update If Not @error Then; @error has not been set, therefore, there is an update available, download it _InetFile_Download("www.mysite.com"); download the update If Not @error Then; @error has not been set, therefore, the download was successful, install it _InetFile_Install(); automatically install the update EndIf EndIf EndFunc
tlokz Posted July 2, 2008 Posted July 2, 2008 (edited) Damn, and I put so much time into providing what I thought was enough info - have a read of the module - it tells you... _InetFile_VersionCheck: ; Return values .: Success - sets @error 0 and returns an array where 0 = number of elements, 1 = remote file version, 2 = local file version ; Failure - either returns an appropriately formatted error message or a version array as above and sets @error: ; |@error = 1 (function parameter error) ; |@error = 2 (version / VCF error) ; |@error = 3 (file error) ; |@error = 4 (internet error) ; |@error = 5 (manual download required) ; |@error = 6 (no update available) ; |@error = 7 (you have a later version) If there hasn't been an error, the function ends with: If $i_Result = 0 Then; no update available Return SetError(6, 0, $a_RtnVal); return to calling script with versions ElseIf $i_Result = 1 Then; update available Return SetError(0, 0, $a_RtnVal); return to calling script with versions ElseIf $i_Result = -1 Then; you have a later version Return SetError(7, 0, $a_RtnVal); return to calling script with versions EndIf Translated: if @error=6 then there is no update available if @error=0 then there is an update available if @error=7 then you have a later version than the one being offered on the website If you have a look at the code I posted up in the first post, it shows you how to check for an update, download the update and automatically install it. It's all done by testing the @error macro. Here is a commented version (I'll edit the first post and include the comments so others can get an idea). If at any stage the @error gets set, the update won't proceed. Func Update() _InetFile_VersionCheck("www.mysite.com"); check for an update If Not @error Then; @error has not been set, therefore, there is an update available, download it _InetFile_Download("www.mysite.com"); download the update If Not @error Then; @error has not been set, therefore, the download was successful, install it _InetFile_Install(); automatically install the update EndIf EndIf EndFunc Thanks on the great help.. I got it to work This is very nice and beats my old way of doing edit: also lol it keeps downloading even if I have latest version. _InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini") If Not @error Then; @error has not been set, therefore, there is an update available, download it _InetFile_Download("http://files.aobot.org", "T_LOKZz", "Auto-Awesom.exe", @TempDir) If Not @error Then; @error has not been set, therefore, the download was successful, install it _InetFile_Install(); automatically install the update EndIf EndIf Edited July 2, 2008 by tlokz
PartyPooper Posted July 2, 2008 Author Posted July 2, 2008 Thanks on the great help.. I got it to work This is very nice and beats my old way of doing edit: also lol it keeps downloading even if I have latest version. _InetFile_VersionCheck("http://files.aobot.org", "T_LOKZz", "", "", "vcf.ini") If Not @error Then; @error has not been set, therefore, there is an update available, download it _InetFile_Download("http://files.aobot.org", "T_LOKZz", "Auto-Awesom.exe", @TempDir) If Not @error Then; @error has not been set, therefore, the download was successful, install it _InetFile_Install(); automatically install the update EndIf EndIf That's because the actual file version of "Auto-Awesom.exe" you have on your remote site is not the same as the one in the vcf.ini and this creates an infinite loop as the program tries to get the two version numbers equal. :-) Make sure that the file you have on the remote site is the same one as indicated in the vcf.ini.
tlokz Posted July 2, 2008 Posted July 2, 2008 That's because the actual file version of "Auto-Awesom.exe" you have on your remote site is not the same as the one in the vcf.ini and this creates an infinite loop as the program tries to get the two version numbers equal. :-) Make sure that the file you have on the remote site is the same one as indicated in the vcf.ini.Thank you lol
PartyPooper Posted July 7, 2008 Author Posted July 7, 2008 Updated the _InetFile_SizeCheck function to allow downloading of files regardless whether or not they exist locally to check against (assumes a zero byte file). See first post.
PartyPooper Posted August 1, 2008 Author Posted August 1, 2008 Updated source to remove code that caused errors when downloading to @scriptdir - see first post.
storme Posted November 30, 2008 Posted November 30, 2008 (edited) G'day Just a quick question. If "_InetFile_VersionCheck("www.mysite.com")" checks the version of the currently running (Compiled) script against the VCF file on the server. How do I set the version when compiling script? I've checked the help file but can't find anything or if I open the search TOOO much. and when I check the compiled scripts properties the version is autoit's verison so "help"... BTW the script looks great and will come in handy if I can get it to work the way I want. :-) Thanks for the help. John Morrison Edited November 30, 2008 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
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