Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 53 additions & 11 deletions wd_helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -2009,15 +2009,16 @@ EndFunc ;==>_WD_SelectFiles
; ===============================================================================================================================
Func _WD_IsLatestRelease()
Local Const $sFuncName = "_WD_IsLatestRelease"
Local Const $sGitURL = "https://github.com/Danp2/au3WebDriver/releases/latest"
Local Const $sURL = "https://github.com/Danp2/au3WebDriver/releases/latest"
Local $bResult = Null
Local $iErr = $_WD_ERROR_Success
Local $sRegex = '<a.*href="\/Danp2\/au3WebDriver\/releases\/tag\/(.*?)"'

Local $sResult = InetRead($sGitURL)
If @error Then $iErr = $_WD_ERROR_GeneralError

If $iErr = $_WD_ERROR_Success Then
Local $sResult = InetRead($sURL)
If @error Then $sResult = _WD_DownloadAsBinary($sURL)
If @error Then
$iErr = $_WD_ERROR_GeneralError
Else
Local $aLatestWDVersion = StringRegExp(BinaryToString($sResult), $sRegex, $STR_REGEXPARRAYMATCH)

If Not @error Then
Expand Down Expand Up @@ -2151,7 +2152,7 @@ Func _WD_UpdateDriver($sBrowser, $sInstallDir = Default, $bFlag64 = Default, $bF
$_WD_DEBUG = $WDDebugSave
EndIf

Local $sMessage = 'DriverCurrent = ' & $sDriverCurrent & ' : DriverLatest = ' & $sDriverLatest
Local $sMessage = 'DriverCurrent = ' & $sDriverCurrent & ' : DriverLatest = ' & $sDriverLatest & ' : $sInstallDir = ' & $sInstallDir
Return SetError(__WD_Error($sFuncName, $iErr, $sMessage, $iExt), $iExt, $bResult)
EndFunc ;==>_WD_UpdateDriver

Expand Down Expand Up @@ -2431,9 +2432,10 @@ Func _WD_DownloadFile($sURL, $sDest, $iOptions = Default)
If $iOptions = Default Then $iOptions = $INET_FORCERELOAD + $INET_IGNORESSL + $INET_BINARYTRANSFER

Local $sData = InetRead($sURL, $iOptions)
If @error Then $iErr = $_WD_ERROR_NotFound

If $iErr = $_WD_ERROR_Success Then
If @error Then $sData = _WD_DownloadAsBinary($sURL)
If @error Then
$iErr = $_WD_ERROR_NotFound
Else
Local $hFile = FileOpen($sDest, $FO_OVERWRITE + $FO_BINARY)

If $hFile <> -1 Then
Expand Down Expand Up @@ -2469,6 +2471,45 @@ Func _WD_DownloadFile($sURL, $sDest, $iOptions = Default)
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iExt), $iExt, $bResult)
EndFunc ;==>_WD_DownloadFile

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_DownloadAsBinary
Comment on lines +2474 to +2475
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function header should be ; #INTERNAL_USE_ONLY# ====== and the function should be __WD_DownloadAsBinary instead of _WD_DownloadAsBinary. Actually it does not matter, but it would fulfill the consistency 😇 .

Copy link
Contributor Author

@mlipok mlipok Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have any reason to change _WD_DownloadAsBinary into internal usage only then you should try to apply the same reason to _WD_DownloadFile and see if this reason also makes sense here.

If you say that _WD_DownloadFile save data to file I would say that the destination does not matter here as I always try to avoid writing data to files on disk. Instead, I process the data in memory and write to database.

This is because of security reason (i.e. GDPR law) - I simply try to minimize the number of places where data leaves a trace (files on disc).

Summary: if any user of this UDF needs to use the function for download and writing data to a file, then the function of writing data to memory without writing it to disk is equally necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood and fair enough @mlipok 👍 .

Then at least the README.md file also has to be adjusted, right?
I mean the additional function should be described in the README like the other functions too.
Is this usually made by @Danp2 ? I believe he do a "Prep release" commit which will contain such things, right? Or do we as PR authors also adjust these files 🤔 ?

Best regards
Sven

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this usually made by @Danp2 ? I believe he do a "Prep release" commit which will contain such things, right? Or do we as PR authors also adjust these files 🤔 ?

@Danp2
What you think about ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Danp2 can you look here ?

; Description ...: Download document (file or HTML content) as binary data from a given URL
; Syntax ........: _WD_DownloadAsBinary($sURL)
; Parameters ....: $sURL - URL representing file to be downloaded
; Return values .: Success - BinaryData (Download succeeded).
; Failure - '' (Download failed) and sets @error to one of the following values:
; - $_WD_ERROR_GeneralError
; Author ........: mLipok
; Modified ......:
; Remarks .......: in case of error @extended will follow WinHttp.WinHttpRequest.5.1 @error number
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_DownloadAsBinary($sURL)
Local Const $sFuncName = "_WD_DownloadAsBinary"
Local Const $sParameters = "Parameters: URL=" & $sURL
Local $iErr = $_WD_ERROR_Success, $iExt = 0
Local $dResult

; Handle COM Errors
Local $oErr = ObjEvent("AutoIt.Error", __WD_ErrHnd)
#forceref $oErr


Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("GET", $sURL, False)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0")
$oHTTP.Send("")
If Not @error Then $dResult = $oHTTP.ResponseBody
If @error Then
$iErr = $_WD_ERROR_GeneralError
$iExt = @error
$dResult = ""
EndIf
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iExt), $iExt, $dResult)
EndFunc ;==>_WD_DownloadAsBinary

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_SetTimeouts
; Description ...: User friendly function to set webdriver session timeouts.
Expand Down Expand Up @@ -3520,7 +3561,7 @@ EndFunc ;==>__WD_JsonElement
; Return values .: Success - Array containing [0] URL for downloading requested webdriver & [1] matching webdriver version
; Failure - Empty array and sets @error to $_WD_ERROR_GeneralError
; Author ........: Danp2
; Modified ......:
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........:
Expand All @@ -3533,13 +3574,14 @@ Func __WD_GetLatestWebdriverInfo($aBrowser, $sBrowserVersion, $bFlag64)
Local $sURL = $aBrowser[0][$_WD_BROWSER_LatestReleaseURL]
Local $sRegex = $aBrowser[0][$_WD_BROWSER_LatestReleaseRegex]
Local $sNewURL = $aBrowser[0][$_WD_BROWSER_NewDriverURL]
#forceref $sBrowserVersion, $bFlag64
#forceref $bFlag64

If StringRegExp($sURL, '["'']') Then
$sURL = Execute($sURL)
EndIf

Local $sDriverLatest = InetRead($sURL)
If @error Then $sDriverLatest = _WD_DownloadAsBinary($sURL)

If @error = $_WD_ERROR_Success Then
Select
Expand Down