mirror of
https://github.com/Stone-Red-Code/HyperbolicDownloader.git
synced 2026-09-04 09:06:10 +02:00
Add estimated time remaining to download progress
This commit is contained in:
@@ -152,9 +152,11 @@ public class DownloadCommands(HostsManager hostsManager, FilesManager filesManag
|
|||||||
|
|
||||||
int bytesPerSecond = 0;
|
int bytesPerSecond = 0;
|
||||||
int transferRate = 0;
|
int transferRate = 0;
|
||||||
|
TimeSpan timeRemaining = TimeSpan.Zero;
|
||||||
|
|
||||||
Stopwatch stopWatch = new Stopwatch();
|
Stopwatch stopWatch = new Stopwatch();
|
||||||
stopWatch.Start();
|
stopWatch.Start();
|
||||||
|
|
||||||
while (totalBytesRead < fileSize)
|
while (totalBytesRead < fileSize)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -180,11 +182,12 @@ public class DownloadCommands(HostsManager hostsManager, FilesManager filesManag
|
|||||||
{
|
{
|
||||||
transferRate = bytesPerSecond;
|
transferRate = bytesPerSecond;
|
||||||
host.DownloadSpeed = (host.DownloadSpeed + bytesPerSecond) / 2;
|
host.DownloadSpeed = (host.DownloadSpeed + bytesPerSecond) / 2;
|
||||||
|
timeRemaining = TimeSpan.FromSeconds((fileSize - totalBytesRead) / (double)host.DownloadSpeed);
|
||||||
bytesPerSecond = 0;
|
bytesPerSecond = 0;
|
||||||
stopWatch.Restart();
|
stopWatch.Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiManager.SendNotificationMessage($"\rDownloading: {Math.Clamp(Math.Ceiling(100d / fileSize * totalBytesRead), 0, 100)}% {UnitFormatter.FileSize(totalBytesRead)}/{UnitFormatter.FileSize(fileSize)} [{UnitFormatter.TransferRate(transferRate)}] ");
|
ApiManager.SendNotificationMessage($"\rDownloading: [{Math.Clamp(Math.Ceiling(100d / fileSize * totalBytesRead), 0, 100)}%] [{UnitFormatter.FileSize(totalBytesRead)}/{UnitFormatter.FileSize(fileSize)}] [{UnitFormatter.TransferRate(transferRate)}] [ETA: {timeRemaining:hh\\:mm\\:ss}] ");
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream.Close();
|
fileStream.Close();
|
||||||
|
|||||||
Reference in New Issue
Block a user