tools/w32DownloadUnzip.vbs
author koda
Thu, 27 Dec 2012 17:08:58 +0100
changeset 8339 2154732c65f1
parent 7813 7ac83d79b897
child 9069 24a2da6e5a22
permissions -rw-r--r--
disable splash on linux
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
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    10
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    11
Set ArgObj = WScript.Arguments
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    12
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    13
If (Wscript.Arguments.Count = 1) Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    14
    strFileURL = ArgObj(0)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    15
    strOutputPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    16
Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    17
    If (Wscript.Arguments.Count = 2) Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    18
        strFileURL = ArgObj(0)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    19
        strOutputPath = ArgObj(1)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    20
    Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    21
        WScript.Echo ("Usage: csript.exe w32DownloadUnzip.vbs url output")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    22
        WScript.Quit
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    23
    End if
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
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    26
strHDLocation = "C:\Windows\Temp\temp.zip"
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    27
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    28
' Fetch the file
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents: 7810
diff changeset
    29
WScript.Echo ( "Trying to download from " & strFileURL)
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    30
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    31
objXMLHTTP.open "GET", strFileURL, false
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    32
objXMLHTTP.send()
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    33
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    34
If objXMLHTTP.Status = 200 Then
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    35
    Set objADOStream = CreateObject("ADODB.Stream")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    36
    objADOStream.Open
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    37
    objADOStream.Type = 1 'adTypeBinary
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    38
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    39
    objADOStream.Write objXMLHTTP.ResponseBody
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    40
    objADOStream.Position = 0    'Set the stream position to the start
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    41
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    42
    Set objFSO = Createobject("Scripting.FileSystemObject")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    43
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    44
    Set objFSO = Nothing
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    45
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    46
    objADOStream.SaveToFile strHDLocation
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    47
    objADOStream.Close
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    48
    Set objADOStream = Nothing
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    49
Else
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    50
    WScript.Echo ("Error downloading file (error code: " & objXMLHTTP.Status & ")")
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    51
    Set objXMLHTTP = Nothing
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    52
    WScript.Quit
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    53
End if
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
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    56
WScript.Echo ( "Extracting file to " & strOutputPath)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    57
Set objShell = CreateObject( "Shell.Application" )
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    58
Set objSource = objShell.NameSpace(strHDLocation).Items()
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    59
Set objTarget = objShell.NameSpace(strOutputPath)
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    60
intOptions = 16 'no user prompt
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    61
objTarget.CopyHere objSource, intOptions
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    62
7813
7ac83d79b897 support video recording on windows with automation and headers
koda
parents: 7810
diff changeset
    63
WScript.Echo ( "Success!" )
7810
da60e6b6baa3 download SDL dlls if not present
koda
parents:
diff changeset
    64
Set objShell = Nothing