Skip to content

Commit

Permalink
Extract new clearlines method and increase download progress update i…
Browse files Browse the repository at this point in the history
…nterval
  • Loading branch information
loc0 committed Jun 14, 2019
1 parent a629a9a commit 4419159
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions codeWithMoshDownloader/codeWithMoshDownloader/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private async Task<bool> DownloadClient(string url, string filepath)

webClient.DownloadFileCompleted += (sender, args) =>
{
Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");
ClearLine();

if (args.Error != null)
{
Expand All @@ -263,12 +263,12 @@ private void DownloadProgressChangedHandler(object sender, DownloadProgressChang
{
_downloadCounter++;

if (_downloadCounter % 500 == 0)
if (_downloadCounter % 250 == 0)
{
string downloaded = ((args.BytesReceived / 1024f) / 1024f).ToString("#0.##");
string total = ((args.TotalBytesToReceive / 1024f) / 1024f).ToString("#0.##");

Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");
ClearLine();

Console.Write($"[download] {downloaded}MB of {total}MB ({args.ProgressPercentage}%)");
}
Expand Down
5 changes: 1 addition & 4 deletions codeWithMoshDownloader/codeWithMoshDownloader/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ public static string AddIndex(string filename, int index)

public static void ClearLine()
{
int currentCursorPosition = Console.CursorTop;
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(new string(' ', Console.WindowWidth));
Console.SetCursorPosition(0, currentCursorPosition);
Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");
}
}
}

1 comment on commit 4419159

@Pseudorizer
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*decrease

Please sign in to comment.