Skip to content

Commit 53b92ad

Browse files
committed
Check for non-zero values before computing with them
1 parent 2f3d639 commit 53b92ad

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function Get-UnityEditor {
266266
([OperatingSystem]::Windows) {
267267
$editor = Join-Path "$p" 'Editor\Unity.exe'
268268

269-
if (Test-Path $editor) {
269+
if (Test-Path $editor) {
270270
Write-Output (Resolve-Path $editor).Path
271271
}
272272
}
@@ -783,16 +783,12 @@ function Request-UnitySetupInstaller {
783783
}
784784

785785
$elapsedTime = (Get-Date) - $data.startTime
786-
787786
$progress = [int](($data.receivedBytes / [double]$data.totalBytes) * 100)
787+
$secondsRemaining = -1 # -1 for Write-Progress prevents seconds remaining from showing.
788788

789-
$averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds
790-
$secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed
791-
792-
if ([double]::IsInfinity($secondsRemaining)) {
793-
$averageSpeed = 0
794-
# -1 for Write-Progress prevents seconds remaining from showing.
795-
$secondsRemaining = -1
789+
if ($data.receivedBytes -gt 0 -and $elapsedTime.TotalSeconds -gt 0) {
790+
$averageSpeed = $data.receivedBytes / $elapsedTime.TotalSeconds
791+
$secondsRemaining = ($data.totalBytes - $data.receivedBytes) / $averageSpeed
796792
}
797793

798794
$downloadSpeed = Format-BitsPerSecond -Bytes $data.receivedBytes -Seconds $elapsedTime.TotalSeconds

0 commit comments

Comments
 (0)