tools/w32DownloadUnzip.vbs
author Periklis Ntanasis <pntanasis@gmail.com>
Fri, 30 Aug 2013 05:47:00 +0300
branchspacecampaign
changeset 9598 5c378d7d2e4d
parent 9069 24a2da6e5a22
child 10017 de822cd3df3a
permissions -rw-r--r--
image, description and hats
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     1
' w32DownloadUnzip.vbs
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     2
'   Download a zipfile and uncompress it with no external tools in Windows
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     3
'
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     4
' Copyright (c) 2012, Vittorio Giovara, <vittorio.giovara@gmail.com>
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     5
' Redistribution and use is allowed according to the terms of the BSD license.
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     6
'
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     7
' References
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     8
'   http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
     9
'   http://stackoverflow.com/questions/1021557/how-to-unzip-a-file-using-the-command-line
9069
24a2da6e5a22 windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents: 7813
diff changeset
    10
'   http://stackoverflow.com/questions/424331/get-the-current-temporary-directory-path-in-vbscript
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    11
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    12
Set ArgObj = WScript.Arguments
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    13
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    14
If (Wscript.Arguments.Count = 1) Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    15
    strFileURL = ArgObj(0)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    16
    strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    17
Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    18
    If (Wscript.Arguments.Count = 2) Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    19
        strFileURL = ArgObj(0)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    20
        strOutputPath = ArgObj(1)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    21
    Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    22
        WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    23
        WScript.Quit
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    24
    End if
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    25
End if
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    26
9069
24a2da6e5a22 windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents: 7813
diff changeset
    27
' Temporary directory
24a2da6e5a22 windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents: 7813
diff changeset
    28
strHDLocation = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2) + "\hwlibtemp.zip"
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    29
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    30
' Fetch the file
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents: 7810
diff changeset
    31
WScript.Echo ( "Trying to download from " & strFileURL)
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    32
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    33
objXMLHTTP.open "GET", strFileURL, false
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    34
objXMLHTTP.send()
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    35
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    36
If objXMLHTTP.Status = 200 Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    37
    Set objADOStream = CreateObject("ADODB.Stream")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    38
    objADOStream.Open
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    39
    objADOStream.Type = 1 'adTypeBinary
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    40
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    41
    objADOStream.Write objXMLHTTP.ResponseBody
9069
24a2da6e5a22 windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents: 7813
diff changeset
    42
    objADOStream.Position = 0 'Set the stream position to the start
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    43
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    44
    Set objFSO = Createobject("Scripting.FileSystemObject")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    45
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    46
    Set objFSO = Nothing
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    47
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    48
    objADOStream.SaveToFile strHDLocation
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    49
    objADOStream.Close
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    50
    Set objADOStream = Nothing
9069
24a2da6e5a22 windows build script, get the temp variable from environment, avoiding potential permission problems
koda
parents: 7813
diff changeset
    51
    Set objXMLHTTP = Nothing
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    52
Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    53
    WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    54
    Set objXMLHTTP = Nothing
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    55
    WScript.Quit
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    56
End if
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    57
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    58
WScript.Echo ( "Extracting file to " & strOutputPath)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    59
Set objShell = CreateObject( "Shell.Application" )
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    60
Set objSource = objShell.NameSpace(strHDLocation).Items()
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    61
Set objTarget = objShell.NameSpace(strOutputPath)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    62
intOptions = 16 'no user prompt
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    63
objTarget.CopyHere objSource, intOptions
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    64
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents: 7810
diff changeset
    65
WScript.Echo ( "Success!" )
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    66
Set objShell = Nothing