Skip to content

Instantly share code, notes, and snippets.

@Bak-Jin-Hyeong
Last active June 27, 2017 08:17
Show Gist options
  • Save Bak-Jin-Hyeong/ab0647f067cf4698203ca3269531d539 to your computer and use it in GitHub Desktop.
Save Bak-Jin-Hyeong/ab0647f067cf4698203ca3269531d539 to your computer and use it in GitHub Desktop.
DownloadAndUnzip.ps1 -Url "https://sourceforge.net/projects/glew/files/glew/2.0.0/glew-2.0.0.zip/download" -DownloadDir . -ExtractDir .
param (
[Parameter(Mandatory=$true)][string]$Uri,
[string]$DownloadDir,
[string]$ExtractDir,
[string]$DownloadFilePath
)
$invocation_dir = Split-Path $MyInvocation.MyCommand.Path
$response = Invoke-WebRequest -Uri $Uri -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox
$response_path = $response.BaseResponse.ResponseUri.AbsolutePath.Split('/')
$filename_from_response = $response_path[$response_path.Length - 1]
if ($DownloadDir)
{
if (![System.IO.Path]::IsPathRooted($DownloadDir))
{
$DownloadDir = Join-Path -Path $invocation_dir -ChildPath $DownloadDir
}
}
else
{
$DownloadDir = $invocation_dir
}
if ($DownloadFilePath)
{
if (![System.IO.Path]::IsPathRooted($DownloadFilePath))
{
$DownloadFilePath = Join-Path -Path $DownloadDir -ChildPath $DownloadFilePath
}
}
else
{
$DownloadFilePath = Join-Path -Path $DownloadDir -ChildPath $filename_from_response
}
[IO.File]::WriteAllBytes($DownloadFilePath, $response.Content)
if ($ExtractDir)
{
if (![System.IO.Path]::IsPathRooted($ExtractDir))
{
$ExtractDir = Join-Path -Path $invocation_dir -ChildPath $ExtractDir
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($DownloadFilePath, $ExtractDir)
}
@Bak-Jin-Hyeong
Copy link
Author

Bak-Jin-Hyeong commented Jun 27, 2017

".\DownloadAndUnzip.ps1" -Url "https://sourceforge.net/projects/glew/files/glew/2.0.0/glew-2.0.0.zip/download" -DownloadDir . -ExtractDir . 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment