diff --git a/src/chocolatey.resources/chocolatey.resources.csproj b/src/chocolatey.resources/chocolatey.resources.csproj index bbd951ecd9..306a783fae 100644 --- a/src/chocolatey.resources/chocolatey.resources.csproj +++ b/src/chocolatey.resources/chocolatey.resources.csproj @@ -43,6 +43,7 @@ + diff --git a/src/chocolatey.resources/helpers/functions/Format-FileSize.ps1 b/src/chocolatey.resources/helpers/functions/Format-FileSize.ps1 new file mode 100644 index 0000000000..c1be440737 --- /dev/null +++ b/src/chocolatey.resources/helpers/functions/Format-FileSize.ps1 @@ -0,0 +1,25 @@ +# Copyright © 2011 - Present RealDimensions Software, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Function Format-FileSize() { + Param ([double]$size) + Foreach ($unit in @('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB')) { + If ($size -lt 1024) { + return [string]::Format("{0:0.##} {1}", $size, $unit) + } + $size /= 1024 + } + return [string]::Format("{0:0.##} YB", $size) +} \ No newline at end of file diff --git a/src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1 b/src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1 index 9f7973b353..56e962c0f2 100644 --- a/src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1 @@ -27,6 +27,7 @@ param( # send the ftp request to the server $ftpresponse = $ftprequest.GetResponse() [int]$goal = $ftpresponse.ContentLength + $goalFormatted = Format-FileSize $goal # get a download stream from the server response $reader = $ftpresponse.GetResponseStream() @@ -42,8 +43,9 @@ param( $writer.Write($buffer, 0, $count); if(!$quiet) { $total += $count + $totalFormatted = Format-FileSize $total if($goal -gt 0) { - Write-Progress "Downloading $url to $fileName" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100) + Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete (($total/$goal)*100) } else { Write-Progress "Downloading $url to $fileName" "Saving $total bytes..." -id 0 -Completed } diff --git a/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 b/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 index 76b4298907..893dcef705 100644 --- a/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 +++ b/src/chocolatey.resources/helpers/functions/Get-WebFile.ps1 @@ -108,6 +108,7 @@ param( if($res.StatusCode -eq 200) { [long]$goal = $res.ContentLength + $goalFormatted = Format-FileSize $goal $reader = $res.GetResponseStream() if ($fileName) { @@ -140,8 +141,9 @@ param( $output += $encoding.GetString($buffer,0,$count) } elseif(!$quiet) { $total += $count + $totalFormatted = Format-FileSize $total if($goal -gt 0 -and ++$iterLoop%10 -eq 0) { - Write-Progress "Downloading $url to $fileName" "Saving $total of $goal" -id 0 -percentComplete (($total/$goal)*100) + Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete (($total/$goal)*100) } if ($total -eq $goal) {