Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (chocolateyGH-285) Fix download loop if connection lost
  (maint) formatting
  (doc) add changelog for chocolateyGH-353
  • Loading branch information
ferventcoder committed Jul 25, 2015
2 parents d74086d + eb11ead commit 1df662a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Alternative sources (webpi, windowsfeature, cygwin, etc) are back (finally, righ

* API - List --localonly not working by default - see [#223](https://github.com/chocolatey/choco/issues/223)
* API - Expose package results - see [#132](https://github.com/chocolatey/choco/issues/132)
* API - Externalize IPackage and its interfaces - see [#353](https://github.com/chocolatey/choco/issues/353)

## [0.9.9.8](https://github.com/chocolatey/choco/issues?q=milestone%3A0.9.9.8+is%3Aclosed) (June 26, 2015)

Expand Down
47 changes: 30 additions & 17 deletions src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,51 @@ param(
if($res.StatusCode -eq 200) {
[long]$goal = $res.ContentLength
$reader = $res.GetResponseStream()

if ($fileName) {
$fileDirectory = $([System.IO.Path]::GetDirectoryName($fileName))
if (!(Test-Path($fileDirectory))) {
[System.IO.Directory]::CreateDirectory($fileDirectory) | Out-Null
[System.IO.Directory]::CreateDirectory($fileDirectory) | Out-Null
}

try {
$writer = new-object System.IO.FileStream $fileName, "Create"
} catch {
throw $_.Exception
}

try {
$writer = new-object System.IO.FileStream $fileName, "Create"
} catch {
throw $_.Exception
}
}

[byte[]]$buffer = new-object byte[] 1048576
[long]$total = [long]$count = [long]$iterLoop =0
do
{
$count = $reader.Read($buffer, 0, $buffer.Length);
if($fileName) {

$originalEAP = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
try {
do
{
$count = $reader.Read($buffer, 0, $buffer.Length);
if($fileName) {
$writer.Write($buffer, 0, $count);
}
if($Passthru){
}

if($Passthru){
$output += $encoding.GetString($buffer,0,$count)
} elseif(!$quiet) {
} elseif(!$quiet) {
$total += $count
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 $total of $goal" -id 0 -percentComplete (($total/$goal)*100)
}

if ($total -eq $goal) {
Write-Progress "Completed download of $url." "Completed a total of $total bytes of $fileName" -id 0 -Completed
}
}
} while ($count -gt 0)
}
} while ($count -gt 0)
} catch {
throw $_.Exception
} finally {
$ErrorActionPreference = $originalEAP
}

$reader.Close()
if($fileName) {
Expand Down

0 comments on commit 1df662a

Please sign in to comment.