Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   AutoIt (http://forum.oszone.net/forumdisplay.php?f=103)
-   -   InetGet и ProgressOn (http://forum.oszone.net/showthread.php?t=315516)

sincolinum 03-06-2016 14:26 2639908

InetGet и ProgressOn
 
В справке к AutoIt есть пример для скачивания файла из интернета

читать дальше »
Код:

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

; Download a file in the background.
; Wait for the download to complete.

Example()

Func Example()
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Download the file in the background with the selected option of 'force a reload from the remote site.'
    Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

    ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

    ; Retrieve the number of total bytes received and the filesize.
    Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
    Local $iFileSize = FileGetSize($sFilePath)

    ; Close the handle returned by InetGet.
    InetClose($hDownload)

    ; Display details about the total number of bytes read and the filesize.
    MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _
            "The total filesize: " & $iFileSize)

    ; Delete the file.
    FileDelete($sFilePath)
EndFunc  ;==>Example


Подскажите пожалуйста, как сделать так, чтобы во время скачивания файла появлялся "ProgressOn" от 0% до 100% или размер файла в цифрах по мере его скачивания

читать дальше »
Код:

Example()

Func Example()
    ; Display a progress bar window.
    ProgressOn("Progress Meter", "Increments every second", "0%")

    ; Update the progress value of the progress bar window every second.
    For $i = 10 To 100 Step 10
        Sleep(1000)
        ProgressSet($i, $i & "%")
    Next

    ; Set the "subtext" and "maintext" of the progress bar window.
    ProgressSet(100, "Done", "Complete")
    Sleep(5000)

    ; Close the progress window.
    ProgressOff()
EndFunc  ;==>Example


Как бы это скомбинировать ?

Iska 03-06-2016 21:36 2640059

Ну, например:
Скрытый текст
Код:

#include <InetConstants.au3>

Example()

Func Example()
        Local $sUrl      = "https://download.sysinternals.com/files/ProcessExplorer.zip"
        Local $sFilePath  = @ScriptDir & "\ProcessExplorer.zip"

        Local $lTotalSize = InetGetSize($sUrl, $INET_FORCERELOAD)
        Local $dCurrentPercent

        Local $hDownload  = InetGet($sUrl, $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)


        ProgressOn($sUrl, "Download progress", "0%")

        Do
                Sleep(250)
                $dCurrentPercent = InetGetInfo($hDownload, $INET_DOWNLOADREAD) / $lTotalSize * 100
                ProgressSet($dCurrentPercent, StringFormat("%.2f", $dCurrentPercent) & "%")
        Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

        Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
        Local $iFileSize  = FileGetSize($sFilePath)

        InetClose($hDownload)

        ProgressSet(100, "The total download size: " & $iBytesSize & @CRLF & "The total filesize: " & $iFileSize, "Complete")
        Sleep(3000)
        ProgressOff()
EndFunc


В реальности пользоваться приведёнными Вами примерами нельзя — надо ещё проверять возможные ошибки.

sincolinum 04-06-2016 11:02 2640118

Скачал файл намного большего размера и ошибок не наблюдал.

Спасибо за помощь.

Iska 05-06-2016 00:46 2640297

Цитата:

Цитата sincolinum
и ошибок не наблюдал. »

Отключите, например, соединение во время загрузки.


Время: 12:57.

Время: 12:57.
© OSzone.net 2001-