Jump to content

Recommended Posts

Posted

So I'm trying to have autoit download a patch, then wait till its downloaded and execute it but it's trying to instantly launch it saying obviously the file isnt found as it hasnt started the download yet. here's the code, any idea why this is happening?

                    If ($patch1 > "0") Then
                        InetGet($url, "patch.exe", 1, 1)
                        $filesize = InetGetSize($url)
                        While @InetGetActive
                            TrayTip("Downloading patches", "Bytes = " & @InetGetBytesRead, 5, 16)
                            GUICtrlSetData($progress, (@InetGetBytesRead / $filesize) * 100)
                            Sleep(550)
                        WEnd
                        TrayTip("Updating Files", "Please Wait...", 5, 16)
                        ShellExecute("patch.exe")
                        Sleep(300)

Posted

Oh nice to note that the file downloads still even after windows says "hey this file doesn't exist" so its just not properly waiting till its downloaded to execute it.

Posted

I haven't used @InetGetActive so I'm not sure if that's what's causing it. I don't even see that macro in the help file. Here's an example of downloading a large(ish) file and executing it when the file is complete using InetGetInfo

#include <InetConstants.au3>

Global Const $sDownloadUrl = "https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe"
Global Const $sSaveAs = @ScriptDir & "\AutoIt V3 Setup.exe"

Global $iStartTimer = 0
Global $hDownload = 0
Global $iDownloadSize = 0
Global $iDownloadSpeed = 0
Global $iBytesRead = 0

ProgressOn("Downloading", "Downloading AutoIt V3 Setup", "", -1, -1, 16)

$iDownloadSize = InetGetSize($sDownloadUrl)
$hDownload = InetGet($sDownloadUrl, $sSaveAs, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

$iStartTimer = TimerInit()

While (Not InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE))
    Local $iPercent = ((InetGetInfo($hDownload, $INET_DOWNLOADREAD) * 100) / $iDownloadSize)
    $iBytesRead = InetGetInfo($hDownload, $INET_DOWNLOADREAD)

    ProgressSet($iPercent, Round($iPercent, 0) & "%" & @CRLF & "Downloaded " & Round(InetGetInfo($hDownload, $INET_DOWNLOADREAD) / 1048576, 2) & " of " & Round($iDownloadSize / 1048576, 2) & " MB (" & $iDownloadSpeed & "MB/s)")

    Sleep(200)

    $iDownloadSpeed = Round(((InetGetInfo($hDownload, $INET_DOWNLOADREAD) - $iBytesRead) / 1048576) * 5, 2)
WEnd

InetClose($hDownload)

ShellExecute($sSaveAs)

 

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
  • Recently Browsing   0 members

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