AJStevens Posted December 11, 2009 Share Posted December 11, 2009 (edited) Hi, I'm new to Autoit, in fact, so far only done a RunAs, and a file.reg registry importer, very simple scripts. I've searched the forum, and cobbled together a script, I actually need a multi-file downloader, with a current file progress and an overall progress, which I've managed to do (it works, not sure how well I've done it, I'm well open to suggestions with this code), however, I just cannot get the InetGet("abort") to work, I think it's because of the loop, and once it starts downloading, it pays no attention to the cancel button... I'd also like to enable/disable the Download and cancel buttons as appropriate. Would someone be so kind as to revise my code below with something that works, I will then read every inch of it, and consult the help file on each little bit used. That's how I best learn, by dissecting an example and reading each bit in the help file, bit by bit, I then begin to understand it and modify it to my own ends, this usually works until I come across something like this and I get stuck. Unfortunately, this only works with a working example. I also hope to adapt this to be able to read a webpage, learn what the current version is of the files, compare that to a dir listing, and if folder doesn't exist (meaning, not yet downloaded that version), then to download it. Hence the "Program Versions" which are used to make subfolders for the saved files. I like to keep previous versions, in case there's a bug in the new one (website doesn't appear to keep previous versions). Also allow the user to specify the beginning local path, username and password for authentication. Is it possible to have the option of the program "remembering" all of this with a "Remember Details" tick box for say being scheduled with Windows Scheduler? expandcollapse popup; Script Start ;Includes #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> ; Fill in your current license username and password. Local $sUserName = "username" Local $sPassword = "password" Local $sProtocol = "HTTP" Local $sServer = "download.website.com" Local $sLocalPath = "\\Server\Share$\Folder\" ; Program Versions Local $sBuildV4PSS = "4.0.686" Local $sBuildV4PAV = "4.0.686" Local $sBuildV3PSS = "3.0.746" Local $sBuildV3PAV = "3.0.746" Local $sBuildRA = "3.2.35" ; Remove trailing \ if present from Local Path $lpbs = StringInStr($sLocalPath, "\",0,-1) If StringLen($sLocalPath) = $lpbs Then $sLocalPath = StringTrimRight($sLocalPath, 1) EndIf Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Download Program Installers", 294, 123, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Progrpss1Label = GUICtrlCreateLabel("File Download Progrpss", 8, 8) $Progrpss1 = GUICtrlCreateProgrpss(8, 24, 275, 20) $Progrpss2Label = GUICtrlCreateLabel("Total Progrpss", 8, 52) $Progrpss2 = GUICtrlCreateProgrpss(8, 68, 275, 20) $Button2 = GUICtrlCreateButton("Cancel", 175, 94, 75, 20, 0) GUICtrlSetOnEvent(-1, "CancelPrpssed") $Button1 = GUICtrlCreateButton("Download", 58, 94, 75, 20, 0) GUICtrlSetOnEvent(-1, "Button1Click") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() ; Business Editions download("/download/win/pssbe/pssbe_nt32_enu.msi", "\Company\pss Program\Business Edition\Version 4\"&$sBuildV4PSS&"\pssbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((1/19)*100)) download("/download/win/pssbe/pssbe_nt64_enu.msi", "\Company\pss Program\Business Edition\Version 4\"&$sBuildV4PSS&"\pssbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((2/19)*100)) download("/download/win/v3pssbe/pssbe_nt32_enu.msi", "\Company\pss Program\Business Edition\Version 3\"&$sBuildV3PSS&"\pssbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((3/19)*100)) download("/download/win/v3pssbe/pssbe_nt64_enu.msi", "\Company\pss Program\Business Edition\Version 3\"&$sBuildV3PSS&"\pssbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((4/19)*100)) download("/download/win/pavbe/pavbe_nt32_enu.msi", "\Company\pav Program\Business Edition\Version 4\"&$sBuildV4PAV&"\pavbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((5/19)*100)) download("/download/win/pavbe/pavbe_nt64_enu.msi", "\Company\pav Program\Business Edition\Version 4\"&$sBuildV4PAV&"\pavbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((6/19)*100)) download("/download/win/v3pavbe/pavbe_nt32_enu.msi", "\Company\pav Program\Business Edition\Version 3\"&$sBuildV3PAV&"\pavbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((7/19)*100)) download("/download/win/v3pavbe/pavbe_nt64_enu.msi", "\Company\pav Program\Business Edition\Version 3\"&$sBuildV3PAV&"\pavbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((8/19)*100)) ; Home Editions download("/download/win/pss/pss_nt32_enu.msi", "\Company\pss Program\Home Edition\Version 4\"&$sBuildV4PSS&"\pssbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((9/19)*100)) download("/download/win/pss/pss_nt64_enu.msi", "\Company\pss Program\Home Edition\Version 4\"&$sBuildV4PSS&"\pssbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((10/19)*100)) download("/download/win/v3pss/pss_nt32_enu.msi", "\Company\pss Program\Home Edition\Version 3\"&$sBuildV3PSS&"\pssbe_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((11/19)*100)) download("/download/win/v3pss/pss_nt64_enu.msi", "\Company\pss Program\Home Edition\Version 3\"&$sBuildV3PSS&"\pssbe_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((12/19)*100)) download("/download/win/pav/pav_nt32_enu.msi", "\Company\pav Program\Home Edition\Version 4\"&$sBuildV4PAV&"\pav_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((13/19)*100)) download("/download/win/pav/pav_nt64_enu.msi", "\Company\pav Program\Home Edition\Version 4\"&$sBuildV4PAV&"\pav_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((14/19)*100)) download("/download/win/v3pav/pav_nt32_enu.msi", "\Company\pav Program\Home Edition\Version 3\"&$sBuildV3PAV&"\pav_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((15/19)*100)) download("/download/win/v3pav/pav_nt64_enu.msi", "\Company\pav Program\Home Edition\Version 3\"&$sBuildV3PAV&"\pav_nt64_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((16/19)*100)) ; Remote Administrator download("/download/ra/pra_server_nt32_enu.msi", "\Company\Program\pra Program Server NT 2000 XP 2003\"&$sBuildRA&"\pra_server_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((17/19)*100)) download("/download/ra/pra_console_nt32_enu.msi", "\Company\Program\pra Program Console NT 2000 XP 2003\"&$sBuildRA&"\pra_console_nt32_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((18/19)*100)) download("/download/ra/pra_console_9x_enu.msi ", "\Company\Program\pra Program Console 95 98 ME\"&$sBuildRA&"\pra_console_9x_enu.msi", $Progrpss1) GUICtrlSetData($Progrpss2,Ceiling((19/19)*100)) EndFunc Func Form1Close() Exit EndFunc func download($url, $target, $progrpss) $ftrim = StringInStr($target, "\",0,-1) $filename = StringTrimLeft($target, $ftrim) $ftrim = StringLen($target) - $ftrim $folder = StringTrimRight($target, $ftrim) DirCreate($sLocalPath&$folder) $Progrpss1LabelText = "Downloading: "&$filename GUICtrlSetData($Progrpss1Label,$Progrpss1LabelText) $url = $sProtocol&"://"&$sUserName&":"&$sPassword&"@"&$sServer&$url $target = $sLocalPath&$target $size =InetGetSize($url) $hDownload = InetGet($url, $target, 1, 1) ;1 = Forces a reload from the remote site, 1 = Return immediately and download in the background While Not InetGetInfo($hDownload, 2) ;2 = Set to True if the download is complete, False if the download is still ongoing. GUICtrlSetData($progrpss,Ceiling((InetGetInfo($hDownload, 0)/$size)*100)) ;0 = Bytes read so far (this is updated while the download progrpsses). Wend endfunc Func CancelPrpssed() InetGet("abort") EndFunc ;==>CancelPrpssed Edited December 11, 2009 by AJStevens 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