Jump to content

Recommended Posts

Posted

hello

Im creating an app that download several file.i have problem that when start first download and using a loop to monitor ans update status on a list view , somehow script is frozen and not working.

is ther any way to send loops in background and better way to update listview?

; Wait for the download to complete :
    Do
        $currentDown[0][3]=InetGetInfo($hDownload, $INET_DOWNLOADREAD)
        Sleep(250)
        _GUICtrlListView_DeleteAllItems($idListview)
        _GUICtrlListView_AddArray($idListview,$currentDown )

    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

 

  • Developers
Posted

No multi-threading is required in this case as the download is performed already in the background, so all that is required is to store the handles of each submitted download in an array, and then loop through this array getting the status for each active download and handle the ended sessions.

 

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.
  :)

Posted
1 hour ago, Jos said:

No multi-threading is required in this case as the download is performed already in the background, so all that is required is to store the handles of each submitted download in an array, and then loop through this array getting the status for each active download and handle the ended sessions.

 

i already sent the download to background,but the way you mentioned is fine if we just have download progress , but because the download may take time i want to other aspect of gui can work for example user can add more download to list.

Global $hDownload = InetGet($url , @ScriptDir&"\"&$sFileName&$sExtension, BitOR( $INET_IGNORESSL, $INET_BINARYTRANSFER), $INET_DOWNLOADBACKGROUND)

 

  • Developers
Posted
9 minutes ago, rot3r said:

but because the download may take time i want to other aspect of gui can work for example user can add more download to list.

Understand, hence my question for a more complete script so we can assist. ;)

 

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.
  :)

Posted
On 1/9/2025 at 6:22 PM, Jos said:

Understand, hence my question for a more complete script so we can assist. ;)

 

it's function that call from main gui :

Func downAdd()

    Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
    for $vElement In $idDown[0][2]
    local $currentDown[10][5]
    Local $aPathSplit = _PathSplit(json_get($vElement,".download_link"), $sDrive, $sDir, $sFileName, $sExtension)

    $url =json_get($vElement,".download_link")

    ;"File Name|Size|Status|Transfer rate|Date Added"
    $currentDown[0][0]=$idDown[0][0]
    $currentDown[0][1]=$idDown[0][1]
    $currentDown[0][2]=floor((InetGetSize($url)/1024)/1024)
    Global $hDownload = InetGet($url , @ScriptDir&"\"&$sFileName&$sExtension, BitOR( $INET_IGNORESSL, $INET_BINARYTRANSFER), $INET_DOWNLOADBACKGROUND)

    ; Wait for the download to complete :
    Do
        $currentDown[0][3]=InetGetInfo($hDownload, $INET_DOWNLOADREAD)
        Sleep(250)
        _GUICtrlListView_DeleteAllItems($idListview)
        _GUICtrlListView_AddArray($idListview,$currentDown )
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

    ; total bytes received and filesize :
    ConsoleWrite("BytesSize InetGetInfo = " & InetGetInfo($hDownload, $INET_DOWNLOADREAD) & @CRLF)
    ConsoleWrite("BytesSize Local File  = " & FileGetSize($url) & @CRLF)
    InetClose($hDownload)

    next
EndFunc

and this is part of code that create listview :
 

$hGUIDown = GUICreate("Download",980,620, 115, 90,$WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xffffff,$hGUIDown)
 Local $idListview = GUICtrlCreateListView("File Name|Size|Status|Transfer rate|Date Added", 25, 40, 900, 550,-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES) ) ;,$LVS_SORTDESCENDING)

_GUICtrlListView_SetColumnWidth($idListview,0,0 )
_GUICtrlListView_SetColumnWidth($idListview,1,200 )
_GUICtrlListView_SetColumnWidth($idListview,2,70 )

 Local $btnDown = GUICtrlCreateButton("", 30, 0, 80, 35,$BS_BITMAP)
_GUICtrlButton_SetImageList($btnDown,$imageListBtn[4],4,0)


 Local $btnPause = GUICtrlCreateButton("", 120, 0, 40, 35,$BS_BITMAP)
_GUICtrlButton_SetImageList($btnPause,$imageListBtn[5],4,0)

Local $btnOpen = GUICtrlCreateButton("", 170, 0, 40, 35,$BS_BITMAP)
_GUICtrlButton_SetImageList($btnOpen,$imageListBtn[6],4,0)


Local $btnTrash = GUICtrlCreateButton("", 220, 0, 40, 35,$BS_BITMAP)
_GUICtrlButton_SetImageList($btnTrash,$imageListBtn[7],4,0)

GUISetState(@SW_hide)

and there is a main gui like tab that user can change between the download page and select files to download

Posted
4 hours ago, rot3r said:

and this is part of code that create listview

...I've been watching this thread for days waiting to steal your code but you only post bits and pieces. Quite frustrating.

Since you don't want to post running code ( one that I could copy'n'paste to run on my side ) the advice is: don't "Until InetGetInfo()", instead watch the InetGetInfo() in the main loop and once they are all done, they are done. It all runs in the background anyway. Why wait in a "Until InetGetInfo()" ?, might as well run it in the foreground if you're gonna "Until InetGetInfo()".

Cheers

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

its complete code with all dependencies,in main page first select the first item after that in download page click on download.

with your help i move the InetGetInfo in the main loop.

the problem is that i want to update the download status in the listview and i think its not a good method to "_GUICtrlListView_DeleteAllItems" and  "_GUICtrlListView_AddArray" in every cycle.also if put sleep in main loop the program become unresponsive.

JBdl.zip

Posted
2 hours ago, rot3r said:

complete code with all dependencies

NotifyBox.au3 and GUIScrollbars_Ex.au3 are not there and I don't know where to get it from.

also, stuff like ""بارگذاری نرم افزارها","درحال اتصال به سرور, لطفا چند لحظه منتظر بمانید"" ( "Loading software", "Connecting to the server, please wait a few moments" ) would be good to have it internationalized or, since this forum is English only, share it in English. Am Hispanic but share everything in English because it makes sense to use a common language since becoming a polyglot is harder than becoming a coder, for me anyway.

2 hours ago, rot3r said:

also if put sleep in main loop the program become unresponsive.

Then don't. Does not need the "Sleep(250)". That is there for the example only given that there is nothing from regulating a wait time like GUIGetMsg() to handle that.

Nice looking code. Easy to read :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

Well giving your full script with missing parts is not helping us very much.  But since I am waiting for my car to get maintenance, here my take on what I think you want :

#include <File.au3>
#include <GUIConstants.au3>
#include <InetConstants.au3>
#include <GuiListView.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  Local $aDownList[20][6]
  Local $hGUI = GUICreate('Example', 600, 600, 200, 200, $WS_SIZEBOX)
  Local $idListView = GUICtrlCreateListView("ID|Status|File", 50, 20, 500, 400)
  _GUICtrlListView_SetColumnWidth($idListView, 1, 80)
  _GUICtrlListView_SetColumnWidth($idListView, 2, 300)
  Local $idDownload = GUICtrlCreateButton("Add DownLoad", 50, 500, 150, 25)
  GUISetState()

  Local $iIndex
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idDownload
        ;$iIndex = AddDown($aDownList, "http://www.autoitscript.com/autoit3/files/beta/update.dat", _TempFile(@ScriptDir, Default, ".txt", 10))
        $iIndex = AddDown($aDownList, "https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3.zip", _TempFile(@ScriptDir, Default, ".zip", 10))
        $aDownList[$iIndex][5] = GUICtrlCreateListViewItem($aDownList[$iIndex][0] & "|0.0%|" & $aDownList[$iIndex][3], $idListView)
    EndSwitch
    VerifyDownLoad($idListView, $aDownList)
  WEnd
EndFunc   ;==>Example

Func AddDown(ByRef $aList, $sURL, $sFile)
  For $i = 0 To UBound($aList) - 1
    If Not $aList[$i][0] Then ExitLoop
  Next
  If $i = UBound($aList) Then Return SetError(1)
  $aList[$i][0] = InetGet($sURL, $sFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
  $aList[$i][1] = 0
  $aList[$i][2] = 0
  $aList[$i][3] = $sFile
  $aList[$i][4] = $sURL
  Return $i
EndFunc   ;==>AddDown

Func VerifyDownLoad($idLV, ByRef $aList)
  Local $sStatus, $iValue
  Local $tInfo = DllStructCreate($tagLVFINDINFO)
  $tInfo.Flags = $LVFI_PARAM

  For $i = 0 To UBound($aList) - 1
    If Not $aList[$i][0] Then ContinueLoop
    If InetGetInfo($aList[$i][0], $INET_DOWNLOADCOMPLETE) Then
      $sStatus = "Complete"
      InetClose($aList[$i][0])
      $aList[$i][0] = 0
    Else
      $iValue = InetGetInfo($aList[$i][0], $INET_DOWNLOADREAD)
      If $iValue = $aList[$i][2] Then ContinueLoop
      If Not $aList[$i][1] Then $aList[$i][1] = InetGetInfo($aList[$i][0], $INET_DOWNLOADSIZE)
      $sStatus = StringFormat("%.1f%%", $iValue / $aList[$i][1] * 100)
      $aList[$i][2] = $iValue
    EndIf
    $tInfo.Param = $aList[$i][5]
    $iValue = _GUICtrlListView_FindItem($idLV, -1, $tInfo)
    _GUICtrlListView_SetItem($idLV, $sStatus, $iValue, 1)
  Next
EndFunc   ;==>VerifyDownLoad

ps.  see how you can make a runable script without having the full blown code...

Edited by Nine
missing inetclose

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...