From a44d8ebe73c455cdd47a89786a8b055d47e26ba7 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 14 Dec 2023 23:54:49 +0100 Subject: [PATCH] Add estimated time remaining to download progress --- HyperbolicDownloaderApi/Commands/DownloadCommands.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/HyperbolicDownloaderApi/Commands/DownloadCommands.cs b/HyperbolicDownloaderApi/Commands/DownloadCommands.cs index 76b8fd5..7597a74 100644 --- a/HyperbolicDownloaderApi/Commands/DownloadCommands.cs +++ b/HyperbolicDownloaderApi/Commands/DownloadCommands.cs @@ -152,9 +152,11 @@ public class DownloadCommands(HostsManager hostsManager, FilesManager filesManag int bytesPerSecond = 0; int transferRate = 0; + TimeSpan timeRemaining = TimeSpan.Zero; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); + while (totalBytesRead < fileSize) { try @@ -180,11 +182,12 @@ public class DownloadCommands(HostsManager hostsManager, FilesManager filesManag { transferRate = bytesPerSecond; host.DownloadSpeed = (host.DownloadSpeed + bytesPerSecond) / 2; + timeRemaining = TimeSpan.FromSeconds((fileSize - totalBytesRead) / (double)host.DownloadSpeed); bytesPerSecond = 0; 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();