buymeapc Posted June 12, 2009 Share Posted June 12, 2009 I'm trying to create a download resume script for an executable posted on a website. I've been following this posting and the OP says it was figured out, but I just don't know where to go from there since there was no follow up. I guess I just need a good kick in the right direction...Here's what I have so far...it's for downloading a game update from EVE Online's website:Thanks...expandcollapse popup#include <IE.au3> #include <String.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> ;Eve Test Local $Form1, $Progress1 Local $oIE, $oLink, $oLinks, $oTable, $aTableData Local $size, $download, $newbuild, $bytes, $conn, $dl, $h, $sock, $listen Local $ini = "C:\Games\EVE\common.ini" Local $build = IniRead($ini, "main", "build", "85476") ;Create a GUI with a progress indicator for download status Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Eve Online Update", 294, 56, 192, 124) $Progress1 = GUICtrlCreateProgress(8, 8, 275, 20) $Label1 = GUICtrlCreateLabel(".", 50, 36, 275) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;Create a 'behind-the-scenes' browser object GUICtrlSetData($Label1, "Getting download information...") $oIE = _IECreate("http://www.eveonline.com/patches/patches.asp?s=&system=win&edition=&n="&$build, 0, 0, 1) _IELoadWait($oIE) ;Grab all the links on the page so we can specifically grab the exe's link $oLinks = _IELinkGetCollection($oIE) ;Grab all the table info to set the build variables with the proper info $oTable = _IETableGetCollection($oIE, 0) $aTableData = _IETableWriteToArray($oTable) For $oLink In $oLinks If StringInStr($oLink.href, ".exe") Then $download = $oLink.href Next ;Set the latest build's version to a variable GUICtrlSetData($Label1, "Getting latest build info...") $newbuild = StringSplit($aTableData[1][1], " ") _IEQuit($oIE) ;Check to see if the version needs updating. If it's up to date, then exit. If $build == $newbuild[7] Then Exit ;---------------------- ;Attempting a resume... ;---------------------- ;Get the size of the patch $size =InetGetSize($download) ;Check to see if the patch has been downloaded - partially or not If FileExists(@TempDir&"\evepatch "&$build&" to "&$newbuild[7]&".exe") = 1 Then $bytes = FileGetSize(@TempDir&"\evepatch "&$build&" to "&$newbuild[7]&".exe") TCPStartup() $ip = TCPNameToIP("www.eveonline.com") $conn = TCPConnect($ip, 80) If $conn = -1 Or @error Then MsgBox(0, "", "TCP Error") Exit EndIf GUICtrlSetData($Progress1, Ceiling($bytes/$size)*100) $string = StringSplit($download, "/") ;MsgBox(0, "", $download & @CRLF & "/"&$string[4]&"/"&$string[5]) $h = "GET /"&$string[4]&"/"&$string[5]&" HTTP/1.0" & @CRLF $h &= "Referer: "&$download & @CRLF $h &= "Range: bytes=" & $bytes & "-" & @CRLF $h &= "User-Agent: AutoIt3" & @CRLF $h &= "Host: " & @IPAddress2 & @CRLF $h &= "Pragma: no-cache" & @CRLF $h &= @CRLF MsgBox(0, "", $h) TCPSend($conn, $h) $listen = TCPListen(@IPAddress2, 80) While 1 $sock = TCPAccept($listen) If $sock > -1 Then $data = "" While not @error FileWrite(@TempDir&"\evepatch "&$build&" to "&$newbuild[7]&".exe", $data) $data = TCPRecv($sock, 2048) GUICtrlSetData($Label1, "Downloading..."&($bytes/1024)&"kb of "&Round($size/1024, 0)&"kb") GUICtrlSetData($Progress1, Ceiling($bytes/$size)*100) WEnd TCPCloseSocket($sock) EndIf Sleep(50) WEnd Else ;Start Downloading the patch and show the progress bar. GUICtrlSetData($Label1, "Starting download...") InetGet($download, @TempDir&"\evepatch "&$build&" to "&$newbuild[7]&".exe", 1, 1) ;Loop showing the active status of the progress bar While @InetGetActive GUICtrlSetData($Label1, "Downloading..."&(@InetGetBytesRead/1024)&"kb of "&Round($size/1024, 0)&"kb") GUICtrlSetData($Progress1, Ceiling((@InetGetBytesRead/$size)*100)) Sleep(100) Wend EndIf GUISetState(@SW_HIDE) Run(@TempDir&"\evepatch "&$build&" to "&$newbuild[7]&".exe", @TempDir) Opt("WinTitleMatchMode", 1) WinWait("EVE Online Update", "") ;_FileWriteLog($patchlog, "Update for EVE found...") $title = WinGetTitle("EVE Online Update", "") $patchversion = _StringBetween($title, "EVE Online Update ", " Setup") ControlClick("EVE Online Update", "", "Button2") Sleep(5000) If WinExists("EVE Online Update", "The Update Wizard will install") = 1 Then ControlClick("EVE Online Update", "The Update Wizard will install", "Button1") WinWait("EVE Online Update", "Installation Complete") ControlClick("EVE Online Update", "Installation Complete", "Button2") WinWait("EVE Online Update", "Completing the EVE Online Update", 20) ControlClick("EVE Online Update", "Completing the EVE Online Update", "Button2") Link to comment Share on other sites More sharing options...
DCCD Posted June 12, 2009 Share Posted June 12, 2009 I actually made this, but I don't think this will work Correctly!! give it a try!! NB: uses the pause key to change the value of $Pause #include <GUIConstants.au3> AdlibEnable("DL") ; this keeps running at all times till you exit. HotKeySet("{pause}", "pauseset"); uses the pause key to change the value of $Pause $Pause = -1 Func pauseset() $Pause = $Pause * - 1 EndFunc ;==>pauseset ; $GUI = GUICreate("GUI", 400, 60, -1, -1) $GUIProgress = GUICtrlCreateProgress(10, 10, 380, 40) GUISetState(@SW_SHOW) DL() Func DL() $total = InetGetSize("http://www.informs-sim.org/wsc05papers/015.pdf") InetGet("http://www.informs-sim.org/wsc05papers/015.pdf", "015.pdf", 1, 1) While $Pause = -1 If @InetgetBytesRead <> "-1" Then If @error = -1 Then ExitLoop $count = @InetgetBytesRead $iPercentage = Round(($count / $total) * 100) GUICtrlSetData($GUIProgress, $iPercentage) EndIf WEnd EndFunc ;==>DL While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group Link to comment Share on other sites More sharing options...
buymeapc Posted June 15, 2009 Author Share Posted June 15, 2009 Thanks for the reply, but I don't think this will resume a previously started download. I need to be able to start a download, then quit the script. Then when the script is started again, it will start the download right where it was before without having to re-download the file all over again. Link to comment Share on other sites More sharing options...
DCCD Posted June 15, 2009 Share Posted June 15, 2009 InetGet() if you call the function again before a download is complete it will fail [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group Link to comment Share on other sites More sharing options...
buymeapc Posted June 17, 2009 Author Share Posted June 17, 2009 InetGet() is great for when I start the download, but I want to resume from where the download stopped when the script is restarted. I'm looking to use HTTP/1.1 to resume the download for the file. The GET command should work, but I can't get the details right. Any ideas? Link to comment Share on other sites More sharing options...
NiVZ Posted June 17, 2009 Share Posted June 17, 2009 (edited) Hello,not something I've tried or know anything about. Found an interesting link about it here:http://benramsey.com/archives/206-partial-...range-requests/Only thing I can see is in your code, the first $h = line where you setup the GET request, you've specified HTTP/1.0 - should this not be HTTP/1.1 as only HTTP/1.1 supports resumes ie:change: $h = "GET /"&$string[4]&"/"&$string[5]&" HTTP/1.0" & @CRLFto: $h = "GET /"&$string[4]&"/"&$string[5]&" HTTP/1.1" & @CRLFYou might also want to try using the Microsoft.XMLHTTP object to do the GET request.NiVZ Edited June 17, 2009 by NiVZ 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