From 53b92ad7a0d9c0b4a6e61c49fe85ca850b1c8016 Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Thu, 1 Aug 2019 16:25:19 -0700 Subject: [PATCH] Check for non-zero values before computing with them --- UnitySetup/UnitySetup.psm1 | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index eaf64bc..95867bd 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -266,7 +266,7 @@ function Get-UnityEditor { ([OperatingSystem]::Windows) { $editor = Join-Path "$p" 'Editor\Unity.exe' - if (Test-Path $editor) { + if (Test-Path $editor) { Write-Output (Resolve-Path $editor).Path } } @@ -783,16 +783,12 @@ function Request-UnitySetupInstaller { } $elapsedTime = (Get-Date) - $data.startTime - $progress = [int](($data.receivedBytes / [double]$data.totalBytes) * 100) + $secondsRemaining = -1 # -1 for Write-Progress prevents seconds remaining from showing. - $averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds - $secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed - - if ([double]::IsInfinity($secondsRemaining)) { - $averageSpeed = 0 - # -1 for Write-Progress prevents seconds remaining from showing. - $secondsRemaining = -1 + if ($data.receivedBytes -gt 0 -and $elapsedTime.TotalSeconds -gt 0) { + $averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds + $secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed } $downloadSpeed = Format-BitsPerSecond -Bytes $data.receivedBytes -Seconds $elapsedTime.TotalSeconds