Jump to content

How to cancel a download


Recommended Posts

  • Developers

how can i cancel the  "InetGet($URL, $Filename, 1, 1)" command, without closing the GUI?

And is it possible to pause it?

<{POST_SNAPBACK}>

AFAIK the download can only be stopped by terminating the script. No pause option.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

i would like to see a Inetgetfilename, and not the hole URL, and fix the inetget command, it uses alot of cpu time..

<{POST_SNAPBACK}>

InetGetFilename? So you think that you should just be able to pass "myfile.exe" to InetGet and it know where to DL it from? Maybe I am not understanding you correctly, but you can't even access files on your computer without having the full Path come into play.

I use InetGet all the time in my scripts and only have issues with CPU when my loops are un-slept or if it doesn't find the destination... What exactly is your problem here?

*** Matt @ MPCS

Edited by Matt @ MPCS
Link to comment
Share on other sites

  • Developers

i would like to see a Inetgetfilename, and not the hole URL, and fix the inetget command, it uses alot of cpu time..

<{POST_SNAPBACK}>

Don't understand you first request but the CPU issue should be solved in the last unstable... see here : #39532

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

InetGetFilename? So you think that you should just be able to pass "myfile.exe" to InetGet and it know where to DL it from? Maybe I am not understanding you correctly, but you can't even access files on your computer without having the full Path come into play.

I dunno, just a thought... dont dont much about how to do it...

Link to comment
Share on other sites

Maybe if you provide some syntax we would be able to possibly help you fulfill this feature in the future. I don't really understand where you are going with it. It could be a good idea, just need an idea of what we are talking about here.

*** Matt @ MPCS

Link to comment
Share on other sites

So you are proposing something like:

InetGet("BF2-Lanvegas.rar", "BF2-Lanvegas.rar" )

That is InetGet(RemoteFile, LocalCached).

So you think AutoIt should search the internet for the file "BF2-Lanvegas.rar"? How else do you supose we know where the file is located on the internet?

*** Matt @ MPCS

Link to comment
Share on other sites

  • Developers

The way I read it that he wants to know be able to request autoit for the current file being downloaded.

Don't understand why though because you initiate it yourself and can only do one download at the time so it should be easy to keep track of yourself.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

well, thought it maybe were possible to takeout the filename from the full link, i guess that aint possible, though

So you can't download two files at the same time with Inetget?

<{POST_SNAPBACK}>

the source filename can be retrieved from the url:

$filename = StringTrimLeft($Url, StringInStr($Url, "/", 0, -1))

and a script can only download 1 file at a time. you would need to spawn multiple scripts to download multiple files concurrently.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks to JdeB for the idea.

;------ Start of download.au3 ------
;Compile this file so you you can use it as:
;Download.exe URL [Filename]
;URL        Url of the file you want to download
;Filename   (Optional) Location of the downloaded file
;
;Example:
;Run('download.exe http://www.ige.dk/files/Battlefield2/BF2-Lanvegas.rar "' & @DesktopDir & '"')

$Params = $CmdLine[0]
If $Params > 0 Then
   Select
      Case $Params = 1
         $Url = $CmdLine[1]
         $Filename = StringTrimLeft($Url, StringInStr($Url, "/", 0, -1))
         
      Case $Params = 2
         $Url = $CmdLine[1]
         $Filename = $CmdLine[2]
         
   EndSelect
   InetGet($Url, $Filename, 1)
   Exit 0
Else
   Exit 1
EndIf
;------ End of download.au3 ------


;Examples you could use with download.exe

;Example 1
;This will always download the file to the same directory as the script, even if download.exe is located in another folder
RunWait("download.exe http://www.ige.dk/files/Battlefield2/BF2-Lanvegas.rar", @ScriptDir)

;Example 2
;Same as example 1 only here it returns the PID of the download and continues the script.
;This way you can cancel it by using ProcessClose($PID_download) and you can start more downloads.
$PID_download = Run("download.exe http://www.ige.dk/files/Battlefield2/BF2-Lanvegas.rar " & @ScriptDir & "\BF2-Lanvegas.rar")
Link to comment
Share on other sites

When spawning multiple scripts it doesnt wait for the script to execute completely before going on? I guess it wouldnt make sense to, but for some reason I thought it did :-P

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

When spawning multiple scripts it doesnt wait for the script to execute completely before going on? I guess it wouldnt make sense to, but for some reason I thought it did :-P

JS

<{POST_SNAPBACK}>

What do you mean exactly?

Does the main script not wait? Use RunWait

Link to comment
Share on other sites

What do you mean exactly?

Does the main script not wait? Use RunWait

<{POST_SNAPBACK}>

NVM I actually had my question answered after reading another thread right after I posted this.

You can run scripts simultaneously using #include. I didnt think you could, but I wanted to confirm. I just read another thread confirming that. (It only makes logical sense that you cant).

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • Developers

Slimshady,

Took your script and modified it so that it will show a progress window and have a Cancel download option. It will also stack the progress windows so you can see multiple at the same time. the below script will have to be compiled with the latest Unstable.

;------ Start of download.au3 ------
;Compile this file so you you can use it as:
;Run('download.exe URL "Filename"')
;URL        Url of the file you want to download
;Filename   (Optional) Location of the downloaded file
;
;Example Command to put in your script:
;Run('download.exe http://www.xyz.com/file2download.exe "c:\temp files\targetfile.exe"')
;
#include <GUIConstants.au3>
;HttpSetProxy(1); Proxy settings....
Select
   Case $CmdLine[0] = 1
      $Url = $CmdLine[1]
      $Filename = StringTrimLeft($Url, StringInStr($Url, "/", 0, -1))
   Case $CmdLine[0] = 2
      $Url = $CmdLine[1]
      $Filename = $CmdLine[2]
   Case Else
      MsgBox(0 + 16, "Error", "Invalid number of commandline parameters:" & $CmdLine[0])
      Exit
EndSelect
; Set progress window (multiple windows will be showns below each other
_SetProgressBar ()
; Get size of Source file
ProgressSet(0, " Getting Source information..")
$Tsize = InetGetSize($Url)
; start download of file
If Not InetGet($Url, $Filename, 1, 1) Then
  ;MsgBox(0 + 16, "Error", "Error Downloading URL:" & $Url)
  ;SetError(2)
  ;Exit 0
EndIf
; update file download progress box till finished
While @InetGetActive
   $msg = GUIGetMsg()
   If $msg = $H_Cancel or $msg = $GUI_EVENT_CLOSE Then
      $rc = MsgBox(4100, "Cancel download ?", "Do you want to cancel the download ?")
      If $rc = 6 Then ExitLoop
   EndIf
   GUICtrlSetData($H_Progress, Int(@InetGetBytesRead / $Tsize * 100))
   GUICtrlSetData($H_Status2, Int(@InetGetBytesRead / $Tsize * 100) & " % Completed    downloaded " & Int(@InetGetBytesRead / 1000) & " of " & Int($Tsize / 1000) & "Kb")
   Sleep(50)
Wend
ProgressOff()
Exit 1
;---------------------------------------------
; set progress bar at its own unique position
;---------------------------------------------
Func _SetProgressBar ()
  ; Find first free number for downloads session
   $NbrDl = 0
   While WinExists("URLDOWNLOAD" & StringFormat("%00i", $NbrDl))
      $NbrDl = $NbrDl + 1
   Wend
  ; set the Autoit window to this unique number
   AutoItWinSetTitle("URLDOWNLOAD" & StringFormat("%00i", $NbrDl))
  ; ensure the download progress bar doesn't get outside the screen bounderies.
   $Progress_Y = 10 + 75 * $NbrDl
   If $Progress_Y + 100 > @DesktopHeight Then $Progress_Y = @DesktopHeight - 100
  ; set progressbox and enlarge it
   GUICreate($Filename, 450, 100, 10, $Progress_Y)
   Global $H_Status1 = GUICtrlCreateLabel("From:" & $Url, 5, 5, 440)
   Global $H_Progress = GUICtrlCreateProgress(5, 26, 440, 20)
   Global $H_Status2 = GUICtrlCreateLabel("Initialise", 5, 48, 440)
   Global $H_Cancel = GUICtrlCreateButton("Cancel download", 150, 72, 100, 25)
   GUICtrlSetData($H_Progress, 0)
   GUISetState(@SW_SHOW)
EndFunc  ;==>_SetProgressBar

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...