Jump to content

Recommended Posts

Posted

After investigating, I found that one way to resume a download that has stopped for whatever reason is by using _WinHttpOpen.

But it is much easier to use InetGet to download the file , but it is not possible to resume the download in this way.
My question to the developers and senior people is, is it not possible to set the desired byte to continue the previous download?

I have seen an example to do this via _WinHttpOpen in the link below:
https://www.autoitscript.com/forum/topic/130005-how-can-stop-and-resume-for-download/?do=findComment&comment=903962

 

If FileExists($sDest) Then
    _WinHttpAddRequestHeaders($hRequest, "Range: bytes=" & FileGetSize($sDest) & "-")
EndIf

But I have secrets to do this through InetGet.

Please advise if possible.

Thanks

  • 2 weeks later...
Posted (edited)

But I did it with InetGet!

It is possible to continue downloading only on some servers and on others it is not possible

For example, the download link in the example has the possibility to continue downloading, and the commented link does not have the possibility to continue downloading.

 

 

;-----------
#RequireAdmin
#NoTrayIcon
;-----------
#pragma compile(ExecLevel, requireAdministrator)
;-----------
Opt("MustDeclareVars", 1)
;-----------
#include <GUIConstants.au3>
#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
;-----------
Global $sDest_path = "C:\Autoit_Downloader\"
Global $hDownload
Global $Status_Lable
Global $GUI_HWNDPARENT
Global $iBytesSize
Global $iBytesSize_Review
Global $iMBSize
Global $Internet_aReturn
Global $iMsg_Main
Global $BTN_Pause_And_Close
Global $Download_URL_Without_FileName
Global $Download_FileName_Without_URL
;-----------


_Main()

Func _Main()
        $GUI_HWNDPARENT = GUICreate("Autoit Downloader", 400, 130, -1, -1, $WS_POPUPWINDOW)
        GUIRegisterMsg($WM_NCHITTEST, "MoveGUI_Set")
        
        $Status_Lable = GUICtrlCreateLabel("", 20, 38, 350, 25)
        GUICtrlSetBkColor($Status_Lable, $GUI_BKCOLOR_TRANSPARENT)
        GUICtrlSetFont($Status_Lable, 14, $FW_NORMAL)
        ;GUICtrlSetBkColor($Status_Lable, 0x998877)
        
        $BTN_Pause_And_Close = GUICtrlCreateButton("Pause and Close", 150, 85, 100, 25)

        GUISetState(@SW_SHOW)

        IF Not (FileExists($sDest_path)) THEN
            DirCreate($sDest_path)
        ENDIF

        $Download_URL_Without_FileName = "https://dl.softgozar.com/Files/Software/"
        $Download_FileName_Without_URL = "Win11_23H2_Build_22631.2428_RTM_MSDN_VL_Softgozar.com.part1.rar"
        
        
        ;$Download_URL_Without_FileName = "https://edge10.83.ir.cdn.ir/win/"
        ;$Download_FileName_Without_URL = "Windows.11.v23H2.Build.22631.2428.x64-VL.part1.rar"
        

        While 1
            IF (_IsInternetConnected() == "False") Then
                GUICtrlSetData($Status_Lable, "Please check your internet connection.")
            Else
                GUICtrlSetData($Status_Lable, "Internet is connected.")
                ExitLoop
            ENDIF
            Sleep(1000)
        WEnd
        
        IF (FileExists($sDest_path & $Download_FileName_Without_URL)) Then
            MsgBox($MB_SYSTEMMODAL, "", "Download Continue")
            $hDownload = InetGet($Download_URL_Without_FileName & $Download_FileName_Without_URL, $sDest_path & $Download_FileName_Without_URL, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND)
        Else
            MsgBox($MB_SYSTEMMODAL, "", "Download ForceReload")
            $hDownload = InetGet($Download_URL_Without_FileName & $Download_FileName_Without_URL, $sDest_path & $Download_FileName_Without_URL, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
        EndIF

        While 1
            IF (InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)) then
                IF (InetGetInfo($hDownload, $INET_DOWNLOADSUCCESS)) then
                    InetClose($hDownload)
                    MsgBox(0, "", "Download Completed.")
                    Exit
                ENDIF
            ElseIF (InetGetInfo($hDownload, $INET_DOWNLOADERROR)) OR (_IsInternetConnected() == "False") then
                InetClose($hDownload)
                MsgBox(0, "", "Download Error.")
                Exit
            ENDIF
            
            $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
            IF ($iBytesSize <> "0") AND ($iBytesSize <> "") Then
                IF ($iBytesSize <> $iBytesSize_Review) Then
                    $iBytesSize_Review = $iBytesSize
                    $iMBSize = Round($iBytesSize/1024/1024,2)
                    GUICtrlSetData($Status_Lable, "Downloaded " & $iMBSize & " MB")
                    Sleep(10)
                EndIF
            Else
                GUICtrlSetData($Status_Lable, "Waiting for download")
                Sleep(10)
            EndIF
            
            $iMsg_Main = GUIGetMsg()
            Select
                Case $iMsg_Main = $BTN_Pause_And_Close
                InetClose($hDownload)
                Sleep(1000)
                Exit
            EndSelect
        WEnd
EndFunc

Func MoveGUI_Set($hWnd, $iMsg, $iwParam, $ilParam)
        if ($hWnd = $GUI_HWNDPARENT and $iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc


Func _IsInternetConnected()
    $Internet_aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
    IF @error Then
        Return SetError(1, 0, False)
    EndIF
    Return $Internet_aReturn[0] = 0
EndFunc

 

Edited by r2du-soft

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
×
×
  • Create New...