Add estimated time remaining to download progress

This commit is contained in:
Stone_Red
2023-12-14 23:54:49 +01:00
parent 686fe9c116
commit a44d8ebe73
@@ -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();