改为每秒计算一次大小

This commit is contained in:
nilaoda 2022-12-09 22:17:20 +08:00
parent fc014cd4d9
commit ef94ab0adf
1 changed files with 14 additions and 4 deletions

View File

@ -14,6 +14,8 @@ namespace N_m3u8DL_RE.Column
internal class DownloadStatusColumn : ProgressColumn
{
private ConcurrentDictionary<int, SpeedContainer> SpeedContainerDic { get; set; }
private ConcurrentDictionary<int, string> DateTimeStringDic = new();
private ConcurrentDictionary<int, string> SizeDic = new();
public Style MyStyle { get; set; } = new Style(foreground: Color.DarkCyan);
public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green);
@ -25,15 +27,23 @@ namespace N_m3u8DL_RE.Column
public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime)
{
if (task.Value == 0) return new Text("-", MyStyle).RightAligned();
var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var speedContainer = SpeedContainerDic[task.Id];
var size = speedContainer.RDownloaded;
var totalSize = speedContainer.SingleSegment ? (speedContainer.ResponseLength ?? 0) : (long)(size / (task.Value / task.MaxValue));
var sizeStr = $"{GlobalUtil.FormatFileSize(size)}/{GlobalUtil.FormatFileSize(totalSize)}";
//一秒汇报一次即可
if (DateTimeStringDic.TryGetValue(task.Id, out var oldTime) && oldTime != now)
{
var totalSize = speedContainer.SingleSegment ? (speedContainer.ResponseLength ?? 0) : (long)(size / (task.Value / task.MaxValue));
SizeDic[task.Id] = $"{GlobalUtil.FormatFileSize(size)}/{GlobalUtil.FormatFileSize(totalSize)}";
}
DateTimeStringDic[task.Id] = now;
SizeDic.TryGetValue(task.Id, out var sizeStr);
if (task.IsFinished) sizeStr = GlobalUtil.FormatFileSize(size);
return new Text(sizeStr, MyStyle).RightAligned();
return new Text(sizeStr ?? "-", MyStyle).RightAligned();
}
}
}