Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

UrlDownloadToFile Progress


  • Please log in to reply
57 replies to this topic
PAR
  • Guests
  • Last active:
  • Joined: --
Anyone know why this doesn't work for me. I am running Windows 7 with IE 8. I get the return code :- c0000005 from the
DLLCall into urlmon\URLDownloadToFileA

??

Uberi As Guest
  • Guests
  • Last active:
  • Joined: --
I believe 0xC0000005 means Access Violation, which means an attempt to access nonaccessable resources was made.

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

I had tried that.. unreliable.

Has anyone found a reliable way to force URLDownloadToFile to bypass the cache and always download from the URL?


Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Nov 02 2019 08:38 PM
  • Joined: 20 May 2012

What do you mean exactly?, i just adapted the Lexikos had forked for the "old" Update.ahk Script...

Spoiler

Why ahkscript.org? - autohotkey.com is outdated

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
Hope it helps: Download (Bin, ToString und ToFile)
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

What do you mean exactly?, i just adapted the Lexikos had forked for the "old" Update.ahk Script...

Spoiler

 
Here is what I did.
1. ran the below script to download autohotkeyinstall.exe to the script folder.
2. disconnected from the internet. (to make it impossible to be mistaken where the file came from when the script is ran a second time)
3. deleted autohotkeyinstall.exe from the script folder.
4. ran the below script again
5. the script finished in less then 1 second and the script pulled autohotkeyinstall.exe from the cache and put it in the script folder.
sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
sFile := A_ScriptDir . "\AutoHotkeyInstall.exe"

Progress, % "M W" . A_ScreenWidth//2, 0, 0 of 0
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
	NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)

DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
	If A_EventInfo = 6
	Progress, % p := 100 * nProgress//nProgressMax, %p%, % nProgress . " of " . nProgressMax
	Return 0
}
Your code works properly.
thanks
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

joedf
  • Administrators
  • 986 posts
  • AutoHotkey Foundation
  • Last active: Nov 02 2019 08:38 PM
  • Joined: 20 May 2012
Hoorrah! I love solutions! :)
(especially H2O) :p
Why ahkscript.org? - autohotkey.com is outdated

MontagesNmore
  • Members
  • 13 posts
  • Last active: Apr 22 2016 02:25 AM
  • Joined: 13 Nov 2013

I know this is an old post, but can you explain better on how I can use this code to implement an auto update feature for my program that I am building? I would like to add the auto update feature as well, so when my program is a new version to update itself as well.

 

Thanks!



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Here is what I did.

1. ran the below script to download autohotkeyinstall.exe to the script folder.

2. disconnected from the internet. (to make it impossible to be mistaken where the file came from when the script is ran a second time)

3. deleted autohotkeyinstall.exe from the script folder.

4. ran the below script again

5. the script finished in less then 1 second and the script pulled autohotkeyinstall.exe from the cache and put it in the script folder.

sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
sFile := A_ScriptDir . "\AutoHotkeyInstall.exe"

Progress, % "M W" . A_ScreenWidth//2, 0, 0 of 0
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
	NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)

DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
	If A_EventInfo = 6
	Progress, % p := 100 * nProgress//nProgressMax, %p%, % nProgress . " of " . nProgressMax
	Return 0
}

You code works properly.

thanks

I'm confused by this post datalife, is this the current code YOU wrote that DOES work or is this code you're having problems with?  I'm looking for a very simple function which will DL a file from the internet and show a progress bar.  This code seems to do that and do it well yes?



garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

this works for me

;- XP netbook AHK_L 32bit OK
;-------- saved at Donnerstag, 25. April 2013 18:59:42 user DataLife --------------
;-------- http://www.autohotkey.com/board/topic/17915-urldownloadtofile-progress/page-4 ---
sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
SplitPath, surl, name, dir, ext, name_no_ext, drive
sFile=%a_desktop%\%name%
ifexist,%sFile%
   filedelete,%sFile%

    Gui, 3:Add, Progress, x10   y20  w450  h25  cBlue vMyProgress
    Gui, 3:Add, Edit    , x10   y50  w100  h25  vEdit11
    Gui, 3:Add, Edit    , x120  y50  w100  h25  vEdit12
    Gui, 3:Show,          x400 y400 w500  h100   ,Download
    gosub,dnl
return

esc::exitapp
3Guiclose:
exitapp


dnl:
a:=a_tickcount
;-------
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
	NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)
;-------
delta:=((a_tickcount-a)/1000)
GuiControl,3:,Edit12, %delta% -sec
return

;------- function -----------
DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
	If A_EventInfo = 6
        {
        p := 100 * nProgress//nProgressMax
        GuiControl,3:,MyProgress, %p%
        GuiControl,3:,Edit11, %p%
        }
	Return 0
}
return
;----------------------------------
;======================= END script =====================================================



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

 

this works for me

;- XP netbook AHK_L 32bit OK
;-------- saved at Donnerstag, 25. April 2013 18:59:42 user DataLife --------------
;-------- http://www.autohotkey.com/board/topic/17915-urldownloadtofile-progress/page-4 ---
sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
SplitPath, surl, name, dir, ext, name_no_ext, drive
sFile=%a_desktop%\%name%
ifexist,%sFile%
   filedelete,%sFile%

    Gui, 3:Add, Progress, x10   y20  w450  h25  cBlue vMyProgress
    Gui, 3:Add, Edit    , x10   y50  w100  h25  vEdit11
    Gui, 3:Add, Edit    , x120  y50  w100  h25  vEdit12
    Gui, 3:Show,          x400 y400 w500  h100   ,Download
    gosub,dnl
return

esc::exitapp
3Guiclose:
exitapp


dnl:
a:=a_tickcount
;-------
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
	NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)
;-------
delta:=((a_tickcount-a)/1000)
GuiControl,3:,Edit12, %delta% -sec
return

;------- function -----------
DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
	If A_EventInfo = 6
        {
        p := 100 * nProgress//nProgressMax
        GuiControl,3:,MyProgress, %p%
        GuiControl,3:,Edit11, %p%
        }
	Return 0
}
return
;----------------------------------
;======================= END script =====================================================

where is this script from?



DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

I'm confused by this post datalife, is this the current code YOU wrote that DOES work or is this code you're having problems with?  I'm looking for a very simple function which will DL a file from the internet and show a progress bar.  This code seems to do that and do it well yes?


It does not work as expected.

Do this....

1. Run the above script. Link here http://www.autohotke...e-4#entry584441 (AutoHotkeyInstall.exe downloads fine)
2. Delete AutoHotkeyInstall.exe
3. Disconnect your computer from the internet
4. Run the script again. This time the script runs in about 1 second and AutoHotkeyInstall.exe is copied from the cache folder instead of being downloaded again.

The file should never be pulled from the cache in my opinion. Especially it should not be pulled from the cache when there is no internet connection.

The script posted by joedf overcomes the issue of pulling the previously downloaded file from the cache.
http://www.autohotke...e-4#entry584346

Edited by DataLife, 09 March 2015 - 04:11 AM.

Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

Skrell, script is from Datalife , which worked , but today not .. (?)

here a script from user Bruttosozialprodukt

; - from user 'Bruttosozialprodukt'
;-------- http://www.autohotkey.com/board/topic/101007-super-simple-download-with-progress-bar/ ---

;Example 1 - Download a firefox setup with a progressbar and overwrite it if it already exists on the disk:

a:=a_tickcount
Url  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
SplitPath, url, name, dir, ext, name_no_ext, drive
name:= name
fd1=%a_desktop%\TEST
ifnotexist,%fd1%
 filecreatedir,%fd1%

where=%fd1%\%name%
where:= where
DownloadFile(url,where)
delta:=((a_tickcount-a)/1000)
msgbox, 262208,Downloaded ,Downloaded in %delta% seconds
run,%fd1%
return

/*
;- Example 2 - Download Autohotkey with a progressbar and don't overwrite it if it already exists:

Url            = http://ahkscript.org/download/ahk-install.exe
DownloadAs     = AutoHotkey_L Installer.exe
Overwrite      := False
UseProgressBar := True
DownloadFile(Url, DownloadAs, Overwrite, UseProgressBar)
return
*/
;-------------------------------------------------------------------


DownloadFile(UrlToFile, _SaveFileAs, Overwrite := True, UseProgressBar := True) {
    ;Check if the file already exists and if we must not overwrite it
      If (!Overwrite && FileExist(_SaveFileAs))
          Return
    ;Check if the user wants a progressbar
      If (UseProgressBar) {
          ;Make variables global that we need later when creating a timer
            Global SaveFileAs := _SaveFileAs, FinalSize
          ;Initialize the WinHttpRequest Object
            WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
          ;Download the headers
            WebRequest.Open("HEAD", UrlToFile)
            WebRequest.Send()
          ;Store the header which holds the file size in a variable:
            FinalSize := WebRequest.GetResponseHeader("Content-Length")
            Progress, H80, , Downloading..., %UrlToFile% Download
            SetTimer, UpdateProgressBar, 100
      }
    ;Download the file
      UrlDownloadToFile, %UrlToFile%, %_SaveFileAs%
    ;Remove the timer and the progressbar  because the download has finished
      If (UseProgressBar) {
          Progress, Off
          SetTimer, UpdateProgressBar, Off
      }
}

UpdateProgressBar:
    ;Get the current filesize and tick
      CurrentSize := FileOpen(SaveFileAs, "r").Length ;FileGetSize wouldn't return reliable results
      CurrentSizeTick := A_TickCount
    ;Calculate the downloadspeed
      Speed := Round((CurrentSize/1024-LastSize/1024)/((CurrentSizeTick-LastSizeTick)/1000)) . " Kb/s"
    ;Save the current filesize and tick for the next time
      LastSizeTick := CurrentSizeTick
      LastSize := FileOpen(SaveFileAs, "r").Length
    ;Calculate percent done
      PercentDone := Round(CurrentSize/FinalSize*100)
    ;Update the ProgressBar
      Progress, %PercentDone%, %PercentDone%`% Done, Downloading...  (%Speed%), Downloading %SaveFileAs% (%PercentDone%`%)
Return
;=================== end script =====================================================================