Skip to content

Commit

Permalink
further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fearganni committed Dec 17, 2023
1 parent f91c164 commit 87c3abc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ function Request-Stream($url) {
$tempFile = [System.IO.Path]::GetTempFileName()

# Register download progress event
Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -Action {
$eventSubscription = Register-ObjectEvent -InputObject $webClient -EventName DownloadProgressChanged -Action {
param($sender, $e)
Write-Progress -Activity "Downloading" -Status ("{0} MB of {1} MB. {2}%" -f [math]::Round($e.BytesReceived / 1MB, 2), [math]::Round($e.TotalBytesToReceive / 1MB, 2), $e.ProgressPercentage) -PercentComplete $e.ProgressPercentage
}

# Download the file
try {
$webClient.DownloadFile($url, $tempFile)
} catch {
$webClient.Dispose()
} finally {
# Clean up the event registration
Unregister-Event -SourceIdentifier ([System.Management.Automation.PSEventArgs]$EventSubscriber.SourceIdentifier).EventName
Unregister-Event -SourceIdentifier $eventSubscription.Name
Remove-Job -Name $eventSubscription.Name
}

# Read the file into a memory stream
Expand Down

0 comments on commit 87c3abc

Please sign in to comment.