Skip to content

Commit

Permalink
OPERA: _WD_UpdateDriver + __WD_UpdateExtractor (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlipok authored Mar 2, 2022
1 parent 690e729 commit 863ea9e
Showing 1 changed file with 85 additions and 51 deletions.
136 changes: 85 additions & 51 deletions wd_helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ Func _WD_UpdateDriver($sBrowser, $sInstallDir = Default, $bFlag64 = Default, $bF
Local Const $sFuncName = "_WD_UpdateDriver"
Local $iErr = $_WD_ERROR_Success, $iExt = 0, $sDriverEXE, $sBrowserVersion, $bResult = False
Local $sDriverCurrent, $sDriverLatest, $sURLNewDriver
Local $sTempFile, $oShell, $FilesInZip
Local $sTempFile
Local $bKeepArch = False

If $sInstallDir = Default Then $sInstallDir = @ScriptDir
Expand Down Expand Up @@ -1315,9 +1315,6 @@ Func _WD_UpdateDriver($sBrowser, $sInstallDir = Default, $bFlag64 = Default, $bF
If $bKeepArch Then $bFlag64 = $bDriverIs64Bit
If $_WD_SupportedBrowsers[$iIndex][$_WD_BROWSER_64Bit] And $bDriverIs64Bit <> $bFlag64 Then
$bForce = True
;~ If $WDDebugSave = $_WD_DEBUG_Info Then
;~ __WD_ConsoleWrite($sFuncName & ': ' & $sDriverEXE & ' = ' & (($bDriverIs64Bit) ? ("switching 64>32 Bit") : ("switching 32>64 Bit")) & @CRLF)
;~ EndIf
EndIf
EndIf

Expand Down Expand Up @@ -1345,51 +1342,11 @@ Func _WD_UpdateDriver($sBrowser, $sInstallDir = Default, $bFlag64 = Default, $bF
; Close any instances of webdriver
__WD_CloseDriver($sDriverEXE)

#Region - Extract new instance of webdriver
; Handle COM Errors
Local $oErr = ObjEvent("AutoIt.Error", __WD_ErrHnd)
#forceref $oErr
$oShell = ObjCreate("Shell.Application")
If @error Then
$iErr = $_WD_ERROR_GeneralError
ElseIf FileGetSize($sTempFile) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 11 ; $iExt from 11 to 19 are related to _WD_UpdateDriver()
ElseIf IsObj($oShell.NameSpace($sTempFile)) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 12
ElseIf IsObj($oShell.NameSpace($sInstallDir)) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 13
Else
Local $oNameSpace_Temp = $oShell.NameSpace($sTempFile)
$FilesInZip = $oNameSpace_Temp.items
If @error Then
$iErr = $_WD_ERROR_GeneralError
Else
Local $oNameSpace_Install = $oShell.NameSpace($sInstallDir)
Local $bEXEWasFound = False
For $FileItem In $FilesInZip ; Check the files in the archive separately
; https://docs.microsoft.com/en-us/windows/win32/shell/folderitem
If StringRight($FileItem.Name, 4) = ".exe" Or StringRight($FileItem.Path, 4) = ".exe" Then ; extract only EXE files
; delete webdriver from disk before unpacking to avoid potential problems
FileDelete($sInstallDir & $sDriverEXE)
$bEXEWasFound = True
$oNameSpace_Install.CopyHere($FileItem, 20) ; 20 = (4) Do not display a progress dialog box. + (16) Respond with "Yes to All" for any dialog box that is displayed.
EndIf
Next
If @error Then
$iErr = $_WD_ERROR_GeneralError
ElseIf Not $bEXEWasFound Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 19 ; $iExt from 11 to 19 are related to _WD_UpdateDriver()
Else
$iErr = $_WD_ERROR_Success
$bResult = True
EndIf
EndIf
EndIf
#EndRegion - Extract new instance of webdriver
; Extract
__WD_UpdateExtractor($sTempFile, $sInstallDir, $sDriverEXE)
If Not @error Then $bResult = True
$iErr = @error
$iExt = @extended
EndIf
FileDelete($sTempFile)
EndIf
Expand All @@ -1401,15 +1358,92 @@ Func _WD_UpdateDriver($sBrowser, $sInstallDir = Default, $bFlag64 = Default, $bF
EndIf

If $_WD_DEBUG = $_WD_DEBUG_Info Then
;~ __WD_ConsoleWrite($sFuncName & ': Local File = ' & $sInstallDir & $sDriverEXE & @CRLF)
;~ __WD_ConsoleWrite($sFuncName & ': URLNewDriver = ' & $sURLNewDriver & @CRLF)
__WD_ConsoleWrite($sFuncName & ': DriverCurrent = ' & $sDriverCurrent & ' : DriverLatest = ' & $sDriverLatest & @CRLF)
__WD_ConsoleWrite($sFuncName & ': Error = ' & $iErr & ' : Extended = ' & $iExt & ' : Result = ' & $bResult & @CRLF)
EndIf

Return SetError(__WD_Error($sFuncName, $iErr), $iExt, $bResult)
EndFunc ;==>_WD_UpdateDriver

; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WD_UpdateExtractor
; Description ...: Extract webdriver executable from zip file
; Syntax ........: __WD_UpdateExtractor($sTempFile, $sInstallDir, $sDriverEXE[, $sSubDir = ""])
; Parameters ....: $sTempFile - Full path to zip file.
; $sInstallDir - Directory where extracted files are placed
; $sDriverEXE - Name of webdriver executable
; $sSubDir - [optional] Directory containing files to extract.
; Return values .: None
; Author ........: Danp2
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WD_UpdateExtractor($sTempFile, $sInstallDir, $sDriverEXE, $sSubDir = "")
Local Const $sFuncName = "__WD_UpdateExtractor"
Local $iErr = $_WD_ERROR_Success, $iExt = 0

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

Local $oShell = ObjCreate("Shell.Application")
If @error Then
$iErr = $_WD_ERROR_GeneralError
ElseIf FileGetSize($sTempFile) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 11 ; $iExt from 11 to 19 are related to __WD_UpdateExtractor()
ElseIf IsObj($oShell.NameSpace($sTempFile)) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 12
ElseIf IsObj($oShell.NameSpace($sInstallDir)) = 0 Then
$iErr = $_WD_ERROR_FileIssue
$iExt = 13
Else
Local $oNameSpace_Temp = $oShell.NameSpace($sTempFile & $sSubDir)
Local $FilesInZip = $oNameSpace_Temp.items
If @error Then
$iErr = $_WD_ERROR_GeneralError
$iExt = 14
Else
Local $oNameSpace_Install = $oShell.NameSpace($sInstallDir)
Local $bEXEWasFound = False
For $FileItem In $FilesInZip ; Check the files in the archive separately
; https://docs.microsoft.com/en-us/windows/win32/shell/folderitem

If $FileItem.IsFolder Then
; try to Extract subdir content
__WD_UpdateExtractor($sTempFile, $sInstallDir, $sDriverEXE, '\' & $FileItem.Name)
Else
If StringRight($FileItem.Name, 4) = ".exe" Or StringRight($FileItem.Path, 4) = ".exe" Then ; extract only EXE files
$bEXEWasFound = True
; delete webdriver from disk before unpacking to avoid potential problems
FileDelete($sInstallDir & $sDriverEXE)
$oNameSpace_Install.CopyHere($FileItem, 20) ; 20 = (4) Do not display a progress dialog box. + (16) Respond with "Yes to All" for any dialog box that is displayed.
EndIf
EndIf
Next
If @error Then
$iErr = $_WD_ERROR_GeneralError
$iExt = 15
ElseIf Not $bEXEWasFound Then
$iErr = $_WD_ERROR_NotFound
$iExt = 19 ; $iExt from 11 to 19 are related to __WD_UpdateExtractor()
Else
$iErr = $_WD_ERROR_Success
EndIf
EndIf
EndIf

If $_WD_DEBUG = $_WD_DEBUG_Info Then
__WD_ConsoleWrite($sFuncName & ': Error = ' & $iErr & ' : Extended = ' & $iExt & @CRLF)
EndIf

Return SetError(__WD_Error($sFuncName, $iErr), $iExt)
EndFunc ;==>__WD_UpdateExtractor

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_GetBrowserVersion
; Description ...: Get version number of specified browser.
Expand Down

0 comments on commit 863ea9e

Please sign in to comment.