From 9a932b87592ff68dad99fd2e1398981815bf198f Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sat, 14 May 2022 22:15:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Download/BuiltinDownloadService.cs | 50 ++++++++++++------- DownKyi/Services/Download/DownloadService.cs | 20 ++++---- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/DownKyi/Services/Download/BuiltinDownloadService.cs b/DownKyi/Services/Download/BuiltinDownloadService.cs index d0a71e1..7c20f1b 100644 --- a/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -1,6 +1,7 @@ using DownKyi.Core.BiliApi.Login; using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Downloader; +using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Core.Utils; using DownKyi.Models; @@ -279,32 +280,45 @@ namespace DownKyi.Services.Download // 下载进度回调 mtd.TotalProgressChanged += (sender, e) => { - // 状态更新 - var downloader = sender as MultiThreadDownloader; + try + { + // 状态更新 + var downloader = sender as MultiThreadDownloader; - // 下载进度百分比 - float percent = downloader.TotalProgress; + // 下载进度百分比 + float percent = downloader.TotalProgress; - // 根据进度判断本次是否需要更新UI - if (Math.Abs(percent - downloading.Progress) < 0.01) { return; } - if (Math.Abs(percent - downloading.Progress) > 5) { return; } + // 根据进度判断本次是否需要更新UI + if (Math.Abs(percent - downloading.Progress) < 0.01) { return; } + if (Math.Abs(percent - downloading.Progress) > 5) { return; } - // 下载进度 - downloading.Progress = percent; + // 下载进度 + downloading.Progress = percent; - // 下载大小 - downloading.DownloadingFileSize = Format.FormatFileSize(downloader.TotalBytesReceived) + "/" + Format.FormatFileSize(downloader.Size); + // 下载大小 + downloading.DownloadingFileSize = Format.FormatFileSize(downloader.TotalBytesReceived) + "/" + Format.FormatFileSize(downloader.Size); - // 下载速度 - long speed = (long)downloader.TotalSpeedInBytes; + // 下载速度 + long speed = (long)downloader.TotalSpeedInBytes; - // 下载速度显示 - downloading.SpeedDisplay = Format.FormatSpeed(speed); + // 下载速度显示 + downloading.SpeedDisplay = Format.FormatSpeed(speed); - // 最大下载速度 - if (downloading.Downloading.MaxSpeed < speed) + // 最大下载速度 + if (downloading.Downloading.MaxSpeed < speed) + { + downloading.Downloading.MaxSpeed = speed; + } + } + catch (InvalidOperationException ex) + { + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadByBuiltin()发生InvalidOperationException异常: {0}", ex); + LogManager.Error($"{Tag}.DownloadByBuiltin()", ex); + } + catch (Exception ex) { - downloading.Downloading.MaxSpeed = speed; + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadByBuiltin()发生异常: {0}", ex); + LogManager.Error($"{Tag}.DownloadByBuiltin()", ex); } }; diff --git a/DownKyi/Services/Download/DownloadService.cs b/DownKyi/Services/Download/DownloadService.cs index 5a070f5..9123866 100644 --- a/DownKyi/Services/Download/DownloadService.cs +++ b/DownKyi/Services/Download/DownloadService.cs @@ -153,8 +153,8 @@ namespace DownKyi.Services.Download } catch (Exception e) { - Core.Utils.Debugging.Console.PrintLine(e); - LogManager.Error(Tag, e); + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DownloadCover()发生异常: {0}", e); + LogManager.Error($"{Tag}.DownloadCover()", e); } return null; @@ -378,20 +378,20 @@ namespace DownKyi.Services.Download } catch (InvalidOperationException e) { - Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生InvalidOperationException异常: {0}", e); - LogManager.Error("Start DoWork() InvalidOperationException", e); + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生InvalidOperationException异常: {0}", e); + LogManager.Error($"{Tag}.DoWork() InvalidOperationException", e); } catch (Exception e) { - Core.Utils.Debugging.Console.PrintLine("Start DoWork()发生异常: {0}", e); - LogManager.Error("Start DoWork()", e); + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork()发生异常: {0}", e); + LogManager.Error($"{Tag}.DoWork()", e); } // 判断是否该结束线程,若为true,跳出while循环 if (cancellationToken.IsCancellationRequested) { - Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 下载服务结束,跳出while循环"); - LogManager.Debug(Tag, "下载服务结束"); + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 下载服务结束,跳出while循环"); + LogManager.Debug($"{Tag}.DoWork()", "下载服务结束"); break; } @@ -409,8 +409,8 @@ namespace DownKyi.Services.Download await Task.WhenAny(Task.WhenAll(downloadingTasks), Task.Delay(30000)); foreach (Task tsk in downloadingTasks.FindAll((m) => !m.IsCompleted)) { - Core.Utils.Debugging.Console.PrintLine("AriaDownloadService: 任务结束超时"); - LogManager.Debug(Tag, "任务结束超时"); + Core.Utils.Debugging.Console.PrintLine($"{Tag}.DoWork() 任务结束超时"); + LogManager.Debug($"{Tag}.DoWork()", "任务结束超时"); } }