From 7afa244e6a3c61152737e4fa0848d417005b823d Mon Sep 17 00:00:00 2001 From: 502y <53784463+502y@users.noreply.github.com> Date: Tue, 14 Jan 2025 20:32:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=80=9F=E5=BA=A6=E6=98=BE=E7=A4=BA=20(#11541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 优化下载速度显示 下载速度超过1MiB/s时以MiB/s为单位显示下载速度 * feat: apply review * style: format --------- Co-authored-by: status102 <102887808+status102@users.noreply.github.com> --- .../ViewModels/UI/VersionUpdateViewModel.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs index f062195dcd..2b04e6db0e 100644 --- a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs @@ -882,8 +882,21 @@ public class VersionUpdateViewModel : Screen public static void OutputDownloadProgress(long value = 0, long maximum = 1, int len = 0, double ts = 1) { - OutputDownloadProgress( - $"[{value / 1048576.0:F}MiB/{maximum / 1048576.0:F}MiB({100 * value / maximum}%) {len / ts / 1024.0:F} KiB/s]"); + string progress = $"[{value / 1048576.0:F}MiB/{maximum / 1048576.0:F}MiB ({value * 100.0 / maximum:F}%)"; + + double speedInKiBPerSecond = len / ts / 1024.0; + string speedDisplay; + + if (speedInKiBPerSecond >= 1024) + { + speedDisplay = $"{speedInKiBPerSecond / 1024.0:F} MiB/s"; + } + else + { + speedDisplay = $"{speedInKiBPerSecond:F} KiB/s"; + } + + OutputDownloadProgress(progress + $" {speedDisplay}"); } private static void OutputDownloadProgress(string output, bool downloading = true)