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))