forked from psantosl/p2pcopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleProgress.cs
40 lines (32 loc) · 1.12 KB
/
ConsoleProgress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
namespace p2pcopy
{
static class ConsoleProgress
{
static internal void Draw(
int i,
long transferred,
long total,
int transferStarted,
int width)
{
Console.Write("\r");
char[] progress = new char[] { '-', '\\', '|', '/' };
Console.Write(progress[i % 4]);
int fillPos = (int)((float)transferred / (float)total * width);
string filled = new string('#', fillPos);
string empty = new string('-', width - fillPos);
Console.Write("[" + filled + empty + "] ");
Console.Write("{0, 22}. ",
SizeConverter.ConvertToSizeString(transferred) + " / " +
SizeConverter.ConvertToSizeString(total));
int seconds = (Environment.TickCount - transferStarted) / 1000;
if (seconds == 0)
{
return;
}
Console.Write("{0, 10}/s",
SizeConverter.ConvertToSizeString(transferred / seconds));
}
}
}