forked from NuGet/NuGet.Client
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds download progress to the console when ChocolateyProgressInfo.ShouldDisplayDownloadProgress is set to true. It works for both v2 and v3 feeds, but does not display for local feeds.
- Loading branch information
1 parent
6ab0442
commit f311ec5
Showing
9 changed files
with
369 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2022-Present Chocolatey Software, Inc. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NuGet.Packaging.Core; | ||
|
||
namespace NuGet.Protocol | ||
{ | ||
public class ChocolateyProgressInfo | ||
{ | ||
public ChocolateyProgressInfo(PackageIdentity identity, long? length = null, string operation = "") | ||
{ | ||
Operation = operation; | ||
Length = length; | ||
Identity = identity; | ||
} | ||
|
||
public string Operation { get; set; } | ||
public PackageIdentity Identity { get; set; } | ||
public long? Length { get; set; } | ||
public static bool ShouldDisplayDownloadProgress { get; set; } | ||
public bool Completed { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2022-Present Chocolatey Software, Inc. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace NuGet.Protocol | ||
{ | ||
public delegate void StreamUpdate(Stream sender, long progress, long totalProgress); | ||
|
||
// Based on https://www.thomasbogholm.net/2021/07/15/extend-streams-with-progress-reporting-progressreportingstream/ | ||
public class ChocolateyProgressStream : Stream | ||
{ | ||
public event StreamUpdate WriteProgress; | ||
public event StreamUpdate ReadProgress; | ||
long _totalBytesRead; | ||
long _totalBytesWritten; | ||
private void UpdateRead(long read) | ||
{ | ||
_totalBytesRead += read; | ||
ReadProgress?.Invoke(this, read, _totalBytesRead); | ||
} | ||
private void UpdateWritten(long written) | ||
{ | ||
_totalBytesWritten += written; | ||
WriteProgress?.Invoke(this, written, _totalBytesWritten); | ||
} | ||
|
||
Stream InnerStream { get; } | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
var result = InnerStream.Read(buffer, offset, count); | ||
UpdateRead(result); | ||
return result; | ||
} | ||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
InnerStream.Write(buffer, offset, count); | ||
UpdateWritten(count); | ||
} | ||
public override bool CanRead => InnerStream.CanRead; | ||
public override bool CanSeek => InnerStream.CanSeek; | ||
public override bool CanWrite => InnerStream.CanWrite; | ||
public override long Length => InnerStream.Length; | ||
public override long Position { get => InnerStream.Position; set => InnerStream.Position = value; } | ||
public ChocolateyProgressStream(Stream s) | ||
{ | ||
InnerStream = s; | ||
} | ||
public override void Flush() => InnerStream.Flush(); | ||
public override long Seek(long offset, SeekOrigin origin) => InnerStream.Seek(offset, origin); | ||
public override void SetLength(long value) => InnerStream.SetLength(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.