From 875072fc15c0aae1eee78c57d3eb6b75abc8b097 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 12 Aug 2023 16:30:28 -0400 Subject: [PATCH] add transfer rate and size to upload tasks --- .../EftPatchHelper/Tasks/UploadTasks.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs b/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs index 4ea4a24..07bc2ed 100644 --- a/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs +++ b/EftPatchHelper/EftPatchHelper/Tasks/UploadTasks.cs @@ -87,6 +87,17 @@ namespace EftPatchHelper.Tasks } } + static string BytesToString(long byteCount) + { + string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; + if (byteCount == 0) + return "0" + suf[0]; + long bytes = Math.Abs(byteCount); + int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); + double num = Math.Round(bytes / Math.Pow(1024, place), 1); + return (Math.Sign(byteCount) * num).ToString() + suf[place]; + } + private async Task UploadAllFiles() { if(!await BuildUploadList()) @@ -98,13 +109,14 @@ namespace EftPatchHelper.Tasks new TaskDescriptionColumn() { Alignment = Justify.Left}, new ProgressBarColumn(), new PercentageColumn(), + new TransferSpeedColumn(), new RemainingTimeColumn(), new SpinnerColumn(Spinner.Known.Dots2) ).StartAsync(async context => { foreach(var file in _fileUploads) { - var task = context.AddTask($"[purple][[Pending]][/] {file.DisplayName}"); + var task = context.AddTask($"[purple][[Pending]][/] {file.DisplayName} - [blue]{BytesToString(file.UploadFileInfo.Length)}[/]"); task.IsIndeterminate = true; uploadTasks.Add(file, task); } @@ -115,7 +127,7 @@ namespace EftPatchHelper.Tasks var progress = new System.Progress((d) => pair.Value.Value = d); pair.Value.IsIndeterminate = false; - pair.Value.Description = pair.Key.DisplayName; + pair.Value.Description = $"{pair.Key.DisplayName} - [blue]{BytesToString(pair.Key.UploadFileInfo.Length)}[/]"; if(!await pair.Key.UploadAsync(progress)) {