Advertisement
metalx1000

Get and Run Quake - Windows - Progess Bar

Jun 13th, 2014
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. Gets and Runs Quake for Windows
  3. #>
  4.  
  5.  
  6.  
  7. function DownloadFile($url, $targetFile)
  8.  
  9. {
  10.  
  11.    $uri = New-Object "System.Uri" "$url"
  12.  
  13.    $request = [System.Net.HttpWebRequest]::Create($uri)
  14.  
  15.    $request.set_Timeout(15000) #15 second timeout
  16.  
  17.    $response = $request.GetResponse()
  18.  
  19.    $totalLength = [System.Math]::Floor($response.get_ContentLength()/1024)
  20.  
  21.    $responseStream = $response.GetResponseStream()
  22.  
  23.    $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
  24.  
  25.    $buffer = new-object byte[] 10KB
  26.  
  27.    $count = $responseStream.Read($buffer,0,$buffer.length)
  28.  
  29.    $downloadedBytes = $count
  30.  
  31.    while ($count -gt 0)
  32.  
  33.    {
  34.  
  35.        $targetStream.Write($buffer, 0, $count)
  36.  
  37.        $count = $responseStream.Read($buffer,0,$buffer.length)
  38.  
  39.        $downloadedBytes = $downloadedBytes + $count
  40.  
  41.        Write-Progress -activity "Downloading file '$($url.split('/') | Select -Last 1)'" -status "Downloaded ($([System.Math]::Floor($downloadedBytes/1024))K of $($totalLength)K): " -PercentComplete ((([System.Math]::Floor($downloadedBytes/1024)) / $totalLength)  * 100)
  42.  
  43.    }
  44.  
  45.    #Write-Progress -activity "Finished downloading file '$($url.split('/') | Select -Last 1)'"
  46.  
  47.    $targetStream.Flush()
  48.  
  49.    $targetStream.Close()
  50.  
  51.    $targetStream.Dispose()
  52.  
  53.    $responseStream.Dispose()
  54.  
  55. }
  56.  
  57. cls
  58. Write-Output "Creating Directory for Quake..."
  59. New-Item -ItemType directory -Path Quake
  60. ###########################get webQuakequake######################
  61. Write-Output "Downloading Quake for Windows..."
  62.  
  63. $storageDir = "$pwd"
  64.  
  65. $url = "https://dl.dropbox.com/s/wtbq73nmtuon56i/wq100.zip"
  66. $file = "$storageDir\Quake\wq100.zip"
  67. DownloadFile $url $file
  68.  
  69. Write-Output "Unzipping Quake for Windows"
  70. $shell = new-object -com shell.application
  71. $zip = $shell.NameSpace("$storageDir\Quake\wq100.zip")
  72.  
  73. foreach($item in $zip.items())
  74. {
  75.     $shell.Namespace("$storageDir\Quake\").copyhere($item)
  76. }
  77.  
  78.  
  79. ###########################get quake######################
  80. Write-Output "Downloading Quake Files..."
  81.  
  82. $webclient = New-Object System.Net.WebClient
  83. $url = "https://dl.dropbox.com/s/yu3ceyo42ny5h49/quake.zip"
  84. $file = "$storageDir\Quake\quake.zip"
  85.  
  86. DownloadFile $url $file
  87.  
  88. Write-Output "Unzipping Quake"
  89. $shell = new-object -com shell.application
  90. $zip = $shell.NameSpace("$storageDir\Quake\quake.zip")
  91. foreach($item in $zip.items())
  92. {
  93.     $shell.Namespace("$storageDir\Quake\").copyhere($item)
  94. }
  95.  
  96. Write-Output "Starting Quake"
  97. cd Quake
  98. cmd /c winquake.exe
  99. Write-Output "Exiting Quake"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement