Skip to content

Commit

Permalink
Merge branch 'pr873' into stable
Browse files Browse the repository at this point in the history
* pr873:
  (GH-875) Pad progress output line to console width
  (GH-872) Fix: Download progress never reaches completion
  • Loading branch information
ferventcoder committed Aug 3, 2016
2 parents 289f0c0 + b7548cd commit 00c7b88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1
Expand Up @@ -26,7 +26,7 @@ FileName location specified.
This is a low-level function and not recommended for use in package
scripts. It is recommended you call `Get-ChocolateyWebFile` instead.
Starting in 0.9.10, will automatically call Set-PowerShellExitCode to
Starting in 0.9.10, will automatically call Set-PowerShellExitCode to
set the package exit code to 404 if the resource is not found.
.INPUTS
Expand Down Expand Up @@ -155,12 +155,13 @@ param(
$total += $count
$totalFormatted = Format-FileSize $total
if($goal -gt 0) {
Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete (($total/$goal)*100)
$percentComplete = [Math]::Truncate(($total/$goal)*100)
Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete $percentComplete
} else {
Write-Progress "Downloading $url to $fileName" "Saving $total bytes..." -id 0 -Completed
}
if ($total -eq $goal) {
Write-Progress "Completed download of $url." "Completed a total of $total bytes of $fileName" -id 0 -Completed
if ($total -eq $goal -and $count -eq 0) {
Write-Progress "Completed download of $url." "Completed a total of $total bytes of $fileName" -id 0 -Completed -PercentComplete 100
}
}
} while ($count -ne 0)
Expand Down
7 changes: 4 additions & 3 deletions src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Expand Up @@ -278,11 +278,12 @@ param(
$total += $count
$totalFormatted = Format-FileSize $total
if($goal -gt 0 -and ++$iterLoop%10 -eq 0) {
Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete (($total/$goal)*100)
$percentComplete = [Math]::Truncate(($total/$goal)*100)
Write-Progress "Downloading $url to $fileName" "Saving $totalFormatted of $goalFormatted ($total/$goal)" -id 0 -percentComplete $percentComplete
}

if ($total -eq $goal) {
Write-Progress "Completed download of $url." "Completed download of $fileName ($goalFormatted)." -id 0 -Completed
if ($total -eq $goal -and $count -eq 0) {
Write-Progress "Completed download of $url." "Completed download of $fileName ($goalFormatted)." -id 0 -Completed -PercentComplete 100
}
}
} while ($count -gt 0)
Expand Down
12 changes: 2 additions & 10 deletions src/chocolatey/infrastructure/powershell/PoshHostUserInterface.cs
Expand Up @@ -118,26 +118,18 @@ public override void WriteDebugLine(string message)
}

private bool hasLoggedStartProgress = false;
private bool hasLoggedFinalProgress = false;
public override void WriteProgress(long sourceId, ProgressRecord record)
{
if (record.PercentComplete == -1) return;
if (hasLoggedFinalProgress) return;

if (!hasLoggedStartProgress)
{
hasLoggedStartProgress = true;
this.Log().Debug(record.Activity.escape_curly_braces());
}

// http://stackoverflow.com/a/888569/18475
Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription.PadRight(50, ' ')));

if (record.PercentComplete == 100 && !hasLoggedFinalProgress)
{
hasLoggedFinalProgress = true;
//this.Log().Info("");
//this.Log().Info(record.StatusDescription.Replace("Saving","Finished downloading. Saved"));
}
Console.Write("\rProgress: {0}% - {1}".format_with(record.PercentComplete.to_string(), record.StatusDescription).PadRight(Console.WindowWidth));
}

public override void WriteVerboseLine(string message)
Expand Down

0 comments on commit 00c7b88

Please sign in to comment.