优化单文件大小进度显示
This commit is contained in:
parent
72ea3c996f
commit
17f5acde5a
|
@ -1,4 +1,5 @@
|
||||||
using N_m3u8DL_RE.Common.Util;
|
using N_m3u8DL_RE.Common.Util;
|
||||||
|
using N_m3u8DL_RE.Entity;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Rendering;
|
using Spectre.Console.Rendering;
|
||||||
using System;
|
using System;
|
||||||
|
@ -12,25 +13,40 @@ namespace N_m3u8DL_RE.Column
|
||||||
{
|
{
|
||||||
internal class DownloadStatusColumn : ProgressColumn
|
internal class DownloadStatusColumn : ProgressColumn
|
||||||
{
|
{
|
||||||
protected override bool NoWrap => true;
|
|
||||||
private ConcurrentDictionary<int, long> DownloadedSizeDic = new();
|
private ConcurrentDictionary<int, long> DownloadedSizeDic = new();
|
||||||
|
private ConcurrentDictionary<int, SpeedContainer> SpeedContainerDic { get; set; }
|
||||||
public Style MyStyle { get; set; } = new Style(foreground: Color.DarkCyan);
|
public Style MyStyle { get; set; } = new Style(foreground: Color.DarkCyan);
|
||||||
public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green);
|
public Style FinishedStyle { get; set; } = new Style(foreground: Color.Green);
|
||||||
|
|
||||||
public DownloadStatusColumn(ConcurrentDictionary<int, long> downloadedSizeDic)
|
public DownloadStatusColumn(ConcurrentDictionary<int, long> downloadedSizeDic, ConcurrentDictionary<int, SpeedContainer> speedContainerDic)
|
||||||
{
|
{
|
||||||
this.DownloadedSizeDic = downloadedSizeDic;
|
this.DownloadedSizeDic = downloadedSizeDic;
|
||||||
|
this.SpeedContainerDic = speedContainerDic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime)
|
public override IRenderable Render(RenderContext context, ProgressTask task, TimeSpan deltaTime)
|
||||||
{
|
{
|
||||||
|
if (task.Value == 0) return new Text("", MyStyle).RightAligned();
|
||||||
|
|
||||||
var done = task.IsFinished;
|
var done = task.IsFinished;
|
||||||
|
|
||||||
|
|
||||||
var flag = DownloadedSizeDic.TryGetValue(task.Id, out var size);
|
var flag = DownloadedSizeDic.TryGetValue(task.Id, out var size);
|
||||||
var totalSize = flag ? (size / (task.Value / task.MaxValue)) : 0;
|
var totalSize = flag ? (size / (task.Value / task.MaxValue)) : 0;
|
||||||
var sizeStr = size == 0 ? "" : $"{GlobalUtil.FormatFileSize(flag ? size : 0)}/{GlobalUtil.FormatFileSize(totalSize)}";
|
|
||||||
if (done) sizeStr = GlobalUtil.FormatFileSize(totalSize);
|
|
||||||
|
|
||||||
return new Markup(sizeStr, MyStyle).RightAligned();
|
//单文件下载汇报进度
|
||||||
|
var speedContainer = SpeedContainerDic[task.Id];
|
||||||
|
if (!done && speedContainer.SingleSegment && speedContainer.ResponseLength != null)
|
||||||
|
{
|
||||||
|
task.MaxValue = (double)speedContainer.ResponseLength;
|
||||||
|
task.Value = speedContainer.RDownloaded;
|
||||||
|
size = speedContainer.RDownloaded;
|
||||||
|
totalSize = (double)speedContainer.ResponseLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sizeStr = $"{GlobalUtil.FormatFileSize(flag ? size : 0)}/{GlobalUtil.FormatFileSize(totalSize)}";
|
||||||
|
if (done) sizeStr = GlobalUtil.FormatFileSize(totalSize);
|
||||||
|
return new Text(sizeStr, MyStyle).RightAligned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -643,9 +643,9 @@ namespace N_m3u8DL_RE.DownloadManager
|
||||||
progress.Columns(new ProgressColumn[]
|
progress.Columns(new ProgressColumn[]
|
||||||
{
|
{
|
||||||
new TaskDescriptionColumn() { Alignment = Justify.Left },
|
new TaskDescriptionColumn() { Alignment = Justify.Left },
|
||||||
new ProgressBarColumn() { Width = 30 },
|
new ProgressBarColumn(),
|
||||||
new PercentageColumn(),
|
new PercentageColumn(),
|
||||||
new DownloadStatusColumn(DownloadedSizeDic),
|
new DownloadStatusColumn(DownloadedSizeDic, SpeedContainerDic),
|
||||||
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
|
new DownloadSpeedColumn(SpeedContainerDic), //速度计算
|
||||||
new RemainingTimeColumn(),
|
new RemainingTimeColumn(),
|
||||||
new SpinnerColumn(),
|
new SpinnerColumn(),
|
||||||
|
|
Loading…
Reference in New Issue