Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/07/2020 in all areas

  1. Hi guys, I needed a simple function to download files and show the progress of the download. I commented a bit (don't know if i should have added more) You can provide the url to the file, the wanted file name, the visible name for in the download progress UI, where the file should be downloaded to, if the progressbar should be hidden at the end of the function or if it should remain visible, how long the last message (completed/failed) should show and last but not least, a title for the progress window. At the end of the function you either get the full path of the download file or false when it fails with @error set and @extended set with the error code of the download. #include <InetConstants.au3> Func _webDownloader($sSourceURL, $sTargetName, $sVisibleName, $sTargetDir = @TempDir, $bProgressOff = True, $iEndMsgTime = 2000, $sDownloaderTitle = "MyDownloader") ; Declare some general vars Local $iMBbytes = 1048576 ; If the target directory doesn't exist -> create the dir If Not FileExists($sTargetDir) Then DirCreate($sTargetDir) ; Get download and target info Local $sTargetPath = $sTargetDir & "\" & $sTargetName Local $iFileSize = InetGetSize($sSourceURL) Local $hFileDownload = InetGet($sSourceURL, $sTargetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND) ; Show progress UI ProgressOn($sDownloaderTitle, "Downloading " & $sVisibleName) ; Keep checking until download completed Do Sleep(250) ; Set vars Local $iDLPercentage = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) * 100 / $iFileSize, 0) Local $iDLBytes = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) / $iMBbytes, 2) Local $iDLTotalBytes = Round($iFileSize / $iMBbytes, 2) ; Update progress UI If IsNumber($iDLBytes) And $iDLBytes >= 0 Then ProgressSet($iDLPercentage, $iDLPercentage & "% - Downloaded " & $iDLBytes & " MB of " & $iDLTotalBytes & " MB") Else ProgressSet(0, "Downloading '" & $sVisibleName & "'") EndIf Until InetGetInfo($hFileDownload, $INET_DOWNLOADCOMPLETE) ; If the download was successfull, return the target location If InetGetInfo($hFileDownload, $INET_DOWNLOADSUCCESS) Then ProgressSet(100, "Downloading '" & $sVisibleName & "' completed") If $bProgressOff Then Sleep($iEndMsgTime) ProgressOff() EndIf Return $sTargetPath ; If the download failed, set @error and return False Else Local $errorCode = InetGetInfo($hFileDownload, $INET_DOWNLOADERROR) ProgressSet(0, "Downloading '" & $sVisibleName & "' failed." & @CRLF & "Error code: " & $errorCode) If $bProgressOff Then Sleep($iEndMsgTime) ProgressOff() EndIf SetError(1, $errorCode, False) EndIf EndFunc ;==>_webDownloaderLet me know what you think The test in my example is done with the installer for java 8 update 65 Example usage : $url = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=111687" $file = "Java_8_Update_65.exe" $name = "Java 8 Update 65" $dir = @TempDir & "\MyDownloader" $installcommand = " /s STATIC=Disable AUTO_UPDATE=Disable WEB_JAVA=Enable WEB_JAVA_SECURITY_LEVEL=H WEB_ANALYTICS=Disable EULA=Enable REBOOT=Disable SPONSORS=Disable" $test = _webDownloader($url, $file, $name, $dir, False) If $test Then ProgressSet(100, "Running silent installation...", "Installing " & $name) $exitCode = RunWait($test & $installcommand) If $exitCode = 0 Then ProgressSet(100, "Installation completed") If $exitCode <> 0 Then ProgressSet(0, "Installation failed" & @CRLF & "Exit code: " & $exitCode) Sleep(3000) ProgressOff() FileDelete($test) Else ProgressOff() EndIfGreetz _webDownloader.au3
    1 point
  2. @seadoggie01 I missed my bi-weekly updated... isn't that surprising? Seriously though, I did remember it but I didn't have any working or complete code, so I couldn't share it. In other words, it is still a work in progress. There has been progress since the last post: I have started work on the statement parser, I am currently working on parsing declarations, as well as making other required tweaks in the tokenizer. Oh, and I also implemented a rudimentary error handling method using longjmp, because it gets complex in C. There is a lot of new code that I wish I could share, but it is all a mess so I can't do it in a meaningful way. -- And I am doing all that while dealing with some issues on my professional end, no doubt many would be in the same situation thanks to the deadly cough going around. I am resuming work on ECI now, after taking a break for 2 day, so hopefully I will have a more proper update out soon next week
    1 point
  3. Ping! Just in case you forgot you bi-weekly update
    1 point
  4. abberration

    Software Installer

    I just posted a new version that addresses some issues and adds several new features. I updated the first post and archived version 1.0 at the very bottom. I will go back to older comments and consider more features people requested.
    1 point
  5. Thanks @argumentum Took me a bit of time to understand the whole workflow. I was going to use my own method to extract the json values because I wasn't sure exactly where your code belonged. In other words looking inside the oAuth.au3 file there was a function called _JsonValue and I just had to add your code:     $sString = StringStripWS($sString,8)     $sStart = StringStripWS($sStart,8)     $sEnd = StringStripWS($sEnd,8) to the top of the function and leave the rest of the code below it in the function intact. I also realized I reauthorized so many times playing with this method, I wound up just automating the whole process and then received some great tokens to use in the gmail function. Next and last step is somehow figuring out how to create a single function to use the tokens and log into a Google sheet and extract the value of a single cell. That's going to be the hardest part of the code :-/ Thanks again.
    1 point
  6. You can try if you can identify the menus with UI Automation code in Menus.7z in this post. The 7z file contains all necessary code. Run Example.au3 in SciTE with F5.
    1 point
×
×
  • Create New...