Skip to content

Commit

Permalink
Update bootstrap_win_dev.vbs
Browse files Browse the repository at this point in the history
bug fix oStream.SaveToFile strFile
  • Loading branch information
wonhoseo committed Aug 12, 2017
1 parent 8b7638b commit c82d18e
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions bootstrap_win_dev.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -461,20 +461,19 @@ Sub HTTPDownload( myURL, myPath )
End Sub

' Download a binary type file over http
Sub HTTPDownloadBinaryFile( myURL, myPath )
Sub HTTPDownloadBinaryFile( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
' Based on a script written by Rob van der Woude
' http://www.robvanderwoude.com
' Ref: https://stackoverflow.com/questions/29367130/downloading-a-file-in-vba-and-storing-it
' Ref: https://stackoverflow.com/questions/29367130/downloading-a-file-in-vba-and-storing-it

' Standard housekeeping
Dim i, objFile, objHTTP, strFile, strMsg


Const adSaveCreateOverWrite = 2, adSaveCreateNotExist = 1
Const adTypeBinary = 1

Expand All @@ -489,9 +488,6 @@ Sub HTTPDownloadBinaryFile( myURL, myPath )
AbortScript
End If

' Create or open the target file
'Set objFile = objFso.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "MSXML2.ServerXMLHTTP" )

Expand All @@ -501,19 +497,17 @@ Sub HTTPDownloadBinaryFile( myURL, myPath )

' Write the downloaded byte stream to the target file
If objHTTP.Status = 200 Then
' Create the target stream
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = adTypeBinary
oStream.Write objHTTP.responseBody
oStream.SaveToFile filePath, adSaveCreateOverWrite ' 1 = no overwrite, 2 = overwrite
' Close the target file
oStream.Close
End If

' Create the target stream
Set oStream = WScript.CreateObject( "ADODB.Stream" )
oStream.Open
oStream.Type = adTypeBinary
oStream.Write objHTTP.responseBody
oStream.SaveToFile strFile, adSaveCreateOverWrite ' 1 = no overwrite, 2 = overwrite
' Close the target file
oStream.Close
End If
End Sub


' Extract a zip file strZipFile into strFolder
Function ExtractAll(strZipFile, strFolder)
Set objShell = CreateObject("Shell.Application")
Expand Down

0 comments on commit c82d18e

Please sign in to comment.