DigDeep Posted January 1, 2017 Posted January 1, 2017 (edited) I have got the below code to download certain files and would need some help here in getting the file size reduced as the download % increases. The below code works all good to show the filesize and the percentage. But I wanted to reduce the filesize as the download goes on and Percentage increases. 29MB - 13% 8MB - 20% 1MB - 10% 500KB - 1% ProgressOn("", "Downloading VLC...", "0%", 100, 100, 16) $url = 'http://mirror.de.leaseweb.net/videolan/vlc/2.2.4/win32/vlc-2.2.4-win32.exe' $fldr = 'C:\Temp\VLC.exe' $hInet = InetGet($url, $fldr, 1, 1) $URLSize = InetGetSize($url) While Not InetGetInfo($hInet, 2) Sleep(100) $Size = InetGetInfo($hInet, 0) $Percentage = Int($Size / $URLSize * 100) ProgressSet($Percentage, Round($URLSize / 1024 / 1024, 2) & " MB" & " - " & $Percentage & "%") WEnd ProgressOff() Edited January 1, 2017 by DigDeep
DigDeep Posted January 1, 2017 Author Posted January 1, 2017 (edited) What I have found is that if I use the $Size in place of $Percentage, it shows the MBs' getting downloaded. But I wanted in the reverse side. Starting from Total size and ending with 0KB. ProgressSet($Percentage, Round($Size / 1024 / 1024, 1) & " MB" & " - " & $Percentage & "%") Edited January 1, 2017 by DigDeep
InunoTaishou Posted January 1, 2017 Posted January 1, 2017 Not to sound rude but this is literally basic math.... What you're wanting is how much is left to download, correct? You need to take your biggest number (the $URLSize) and subtract the smaller number ($Size). That will tell you how much left to download. In other words, if you have a large BBQ chicken pizza with 8 slices and eat 3, now you have 5 slices left and a full stomach.
DigDeep Posted January 1, 2017 Author Posted January 1, 2017 Thanks @InunoTaishou I figured that out while checking the options. But when the size is reaching to 1MB, it stays there for the Percentage and download to complete. How to get that auto changed from MB to KB? My largest file size is in GB so if the download started from 1.8GB I wanted the filesize showing as from 1.8GB to 100MB and finally as 1KB when the percentage reaches to 100%. Is there a way we can get that GB, MB and KB auto?
Danyfirex Posted January 1, 2017 Posted January 1, 2017 Hello. You can use this function. Saludos Sal Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
DigDeep Posted January 1, 2017 Author Posted January 1, 2017 Thanks @Danyfirex I used it like below. But what I get is starting with 29GB. when it reaches to less than 1GB it shows as 900MB... 800MB... The 29GB should be 29MB instead. Am I doing anything wrong here? ProgressOn("", "Downloading VLC...", "0%", 100, 100, 16) $url = 'http://mirror.de.leaseweb.net/videolan/vlc/2.2.4/win32/vlc-2.2.4-win32.exe' $fldr = 'C:\Temp\VLC.exe' $hInet = InetGet($url, $fldr, 1, 1) $URLSize = InetGetSize($url) While Not InetGetInfo($hInet, 2) Sleep(100) $Size = InetGetInfo($hInet, 0) $Percentage = Int($Size / $URLSize * 100) $iSize = $URLSize - $Size ProgressSet($Percentage, _GetDisplaySize($iSize, $iPlaces = 2) & " " & $Percentage & " %") WEnd ProgressOff() Func _GetDisplaySize($iSize, $iPlaces = 2) Local $aBytes[3] = [' KB', ' MB', ' GB'] For $i = 2 To 1 Step -1 If $URLSize < 104857600 Then Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i] Else Return Round($iSize / 1024 / 1024 ^ $i, $iPlaces) & $aBytes[$i] EndIf Next Return $iSize & ' Bytes' EndFunc
InunoTaishou Posted January 1, 2017 Posted January 1, 2017 You need to account for bytes in the for loop Func _GetDisplaySize($iTotalDownloaded, Const $iPlaces) Local Static $aSize[4] = ["Bytes", "KB", "MB", "GB"] For $i = 0 to 3 $iTotalDownloaded /= 1024 If (Int($iTotalDownloaded) = 0) Then Return Round($iTotalDownloaded * 1024, $iPlaces) & " " & $aSize[$i] Next EndFunc This is a little simpler
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