From c42147cf2882952602c327e5a1979a5b3903af20 Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Sat, 12 Mar 2022 13:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=AD=E7=9A=84=E9=87=8D=E5=A4=8D=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AA=E9=80=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storage/Database/Download/DownloadDb.cs | 21 +++++++++---------- .../Services/Download/AriaDownloadService.cs | 12 +++++------ .../DownloadManager/DownloadedItem.cs | 4 ++++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/DownKyi.Core/Storage/Database/Download/DownloadDb.cs b/src/DownKyi.Core/Storage/Database/Download/DownloadDb.cs index f32c9c9..b4cf645 100644 --- a/src/DownKyi.Core/Storage/Database/Download/DownloadDb.cs +++ b/src/DownKyi.Core/Storage/Database/Download/DownloadDb.cs @@ -160,11 +160,11 @@ namespace DownKyi.Core.Storage.Database.Download { Dictionary objects = new Dictionary(); - try + dbHelper.ExecuteQuery(sql, reader => { - dbHelper.ExecuteQuery(sql, reader => + while (reader.Read()) { - while (reader.Read()) + try { // 读取字节数组 byte[] array = (byte[])reader["data"]; @@ -177,18 +177,17 @@ namespace DownKyi.Core.Storage.Database.Download objects.Add((string)reader["id"], obj); } - }); - } - catch (Exception e) - { - Utils.Debugging.Console.PrintLine("Query()发生异常: {0}", e); - LogManager.Error($"{tableName}", e); - } + catch (Exception e) + { + Utils.Debugging.Console.PrintLine("Query()发生异常: {0}", e); + LogManager.Error($"{tableName}", e); + } + } + }); return objects; } - /// /// 如果表不存在则创建表 /// diff --git a/src/DownKyi/Services/Download/AriaDownloadService.cs b/src/DownKyi/Services/Download/AriaDownloadService.cs index cc32704..506dd4a 100644 --- a/src/DownKyi/Services/Download/AriaDownloadService.cs +++ b/src/DownKyi/Services/Download/AriaDownloadService.cs @@ -32,8 +32,8 @@ namespace DownKyi.Services.Download { private CancellationTokenSource tokenSource; - private int retry = 5; - private string nullMark = ""; + private readonly int retry = 5; + private readonly string nullMark = ""; public AriaDownloadService(ObservableCollection downloadingList, ObservableCollection downloadedList) : base(downloadingList, downloadedList) { @@ -582,13 +582,13 @@ namespace DownKyi.Services.Download for (int i = 0; i < retry; i++) { audioUid = DownloadAudio(downloading); - if (audioUid != null && audioUid != "") + if (audioUid != null && audioUid != nullMark) { break; } } } - if (audioUid == "") + if (audioUid == nullMark) { DownloadFailed(downloading); return; @@ -611,13 +611,13 @@ namespace DownKyi.Services.Download for (int i = 0; i < retry; i++) { videoUid = DownloadVideo(downloading); - if (videoUid != null && videoUid != "") + if (videoUid != null && videoUid != nullMark) { break; } } } - if (videoUid == "") + if (videoUid == nullMark) { DownloadFailed(downloading); return; diff --git a/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs b/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs index 0da70a4..15fd55f 100644 --- a/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs +++ b/src/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs @@ -84,6 +84,8 @@ namespace DownKyi.ViewModels.DownloadManager /// private void ExecuteOpenFolderCommand() { + if (DownloadBase == null) { return; } + string videoPath = $"{DownloadBase.FilePath}.mp4"; FileInfo fileInfo = new FileInfo(videoPath); if (File.Exists(fileInfo.FullName)) @@ -105,6 +107,8 @@ namespace DownKyi.ViewModels.DownloadManager /// private void ExecuteOpenVideoCommand() { + if (DownloadBase == null) { return; } + string videoPath = $"{DownloadBase.FilePath}.mp4"; var fileInfo = new FileInfo(videoPath); if (File.Exists(fileInfo.FullName))