Jimtags Posted February 15, 2011 Posted February 15, 2011 (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... ================================================================================== expandcollapse popup#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 February 15, 2011 by Jimtags
Moderators Melba23 Posted February 15, 2011 Moderators Posted February 15, 2011 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Jimtags Posted March 2, 2011 Author Posted March 2, 2011 ##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"
guinness Posted March 2, 2011 Posted March 2, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now