Jump to content

Recommended Posts

Posted (edited)

I found this code a while ago in this forum.. I want to ask about the code but seems I can't remember the thread and the author of this code.. This code gives an download example of a PROGRESSBAR WITH TOTAL PROGRESSBAR.. My Problem is How can I make the $DownloadArray[X][Y] readed from a file? Example a

DLlink.ini

line 1: http://www.cutepdf.com/download/CuteWriter.exe

line 2: http://www.cutepdf.com/download/CuteWriter.exe

line 3: http://www.cutepdf.com/download/CuteWriter.exe

line 4: http://www.cutepdf.com/download/CuteWriter.exe

line ....

line etc...

Thanks in advance...

==================================================================================

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>

Opt("TrayMenuMode", 1)

$Form1              = GUICreate("Downloader", 400, 170, -1, -1)

$pb_File            = GUICtrlCreateProgress(30, 30, 300, 20, $PBS_SMOOTH)
$lbl_FilePercent    = GUICtrlCreateLabel("0 %", 335, 32, 35, 16, $SS_RIGHT)

$pb_Overall         = GUICtrlCreateProgress(30, 80, 300, 20, $PBS_SMOOTH)
$lbl_OverallPercent = GUICtrlCreateLabel("0 %", 335, 82, 35, 16, $SS_RIGHT)

$but_Download       = GUICtrlCreateButton("Download", 160, 120, 80, 30)

GUISetState(@SW_Show)

While 1

    $nMsg = GUIGetMsg()

    If $nMsg = $GUI_EVENT_CLOSE Then EXIT

    If $nMsg = $but_Download Then _Download()

WEnd


Func _Download()

    ; Disable the download button
    GUICtrlSetState($but_Download, $GUI_DISABLE)

    ; Reset total filesize to download
    $TotalToDownload = 0

    Dim $DownloadArray[8][3]

    ; Setup the URL's to download - i'm using CutePDF 7 times to demonstrate
    $DownloadArray[1][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[2][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[3][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[4][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[5][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[6][0] = "http://www.cutepdf.com/download/CuteWriter.exe"
    $DownloadArray[7][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

    For $i = 1 To UBound($DownloadArray)-1

        ; Get the File size
        $FileSize = INetGetSize($DownloadArray[$i][0])

        ; Current File Size
        $DownloadArray[$i][1] = $FileSize

        ; Cumulative Total
        $DownloadArray[$i][2] = $TotalToDownload

        ; Add the current file size to the total
        $TotalToDownload += $FileSize
    Next

    ; Do the Downloads
    For $i = 1 To UBound($DownloadArray)-1

        ; Dow the download in the background
        $Download = INetGet($DownloadArray[$i][0], "C:\test" & $i & ".exe", 1, 1)

        ; Loop to update progress
        Do
            ; Get number of bytes read for current file
            $BytesDownloaded    = INetGetInfo($Download, 0)

            ; Add this to the cumulative total
            $DownloadedSoFar    = $DownloadArray[$i][2] + $BytesDownloaded

            ; Calculate the current file percentage
            $FileProgress       = Floor(($BytesDownloaded / $DownloadArray[$i][1]) * 100)

            ; Calculate the overall percentage
            $OverallProgress    = Floor(($DownloadedSoFar / $TotalToDownload) * 100)

            ; Update the Current FIle progress bar
            GUICtrlSetData($pb_File, $FileProgress)

            ; Only update the current file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_FilePercent) <> $FileProgress & " %" Then GUICtrlSetData($lbl_FilePercent, $FileProgress & " %")

            ; Update the overall progress bar
            GUICtrlSetData($pb_Overall, $OverallProgress)

            ; Only update the overall file percent label if it has changed to avoid flickering
            If GUICtrlRead($lbl_OverallPercent) <> $OverallProgress & " %" Then GUICtrlSetData($lbl_OverallPercent, $OverallProgress & " %")

            ; Only update the title bar (overall) percent label if it has changed to avoid flickering
            If WinGetTitle($Form1, "") <> $OverallProgress & " % - Downloader" Then WinSetTitle($Form1, "", $OverallProgress & " % - Downloader")

        ; Continue loop until download is complete
        Until InetGetInfo($Download, 2)

        ; Set current file progress bar to 100% when complete
        GUICtrlSetData($pb_File, 100)

        ; Set current file percent label to 100% when complete
        GUICtrlSetData($lbl_FilePercent, "100 %")

    Next

    ; Set overall progress bar to 100% when complete
    GUICtrlSetData($pb_Overall, 100)

    ; Set overall percent label to 100% when complete
    GUICtrlSetData($lbl_OverallPercent, "100 %")

    ; Display message box to say all downloads complete
    MsgBox(64, "Downloader", "All downloads complete")

    ; Reset GUI
    WinSetTitle($Form1, "", "Downloader")

    GUICtrlSetData($pb_File, 0)
    GUICtrlSetData($lbl_FilePercent, "0 %")

    GUICtrlSetData($pb_Overall, 0)
    GUICtrlSetData($lbl_OverallPercent, "0 %")

    ; Enable the download button
    GUICtrlSetState($but_Download, $GUI_ENABLE)

EndFunc
Edited by Jimtags
  • Moderators
Posted

Jimtags,

If you adjust your file to a proper ini format, you can do it very easily using IniReadSection - details are in the Help file as usual. :)

Note that you may have to adjust the array indices used in the script to get the correct data. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • 2 weeks later...
Posted

##for example i put the download links in a text file 7 lines of dload links .. (dlink.txt)

$CL = _FileCountLines(dlink.txt)

Dim $DownloadArray[$CL+1][3]

##below i dont have idea whats the syntax...or how to do it

; Setup the URL's to download - i'm using CutePDF 7 times to demonstrate

$DownloadArray[1][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[2][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[3][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[4][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[5][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[6][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

$DownloadArray[7][0] = "http://www.cutepdf.com/download/CuteWriter.exe"

Posted

Why not use _FileReadToArray() instead of _FileCountLines(), presuming you are not using an INI structure e.g. Otherwise I would recommend looking at the INI Functions.

[Downloads]
1=http://www.cutepdf.com/download/CuteWriter.exe
2=http://www.cutepdf.com/download/CuteWriter.exe

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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