diff --git a/DownKyi.Core/Aria2cNet/Server/AriaServer.cs b/DownKyi.Core/Aria2cNet/Server/AriaServer.cs index c78853d..513771d 100644 --- a/DownKyi.Core/Aria2cNet/Server/AriaServer.cs +++ b/DownKyi.Core/Aria2cNet/Server/AriaServer.cs @@ -65,7 +65,7 @@ namespace DownKyi.Core.Aria2cNet.Server try { var stream = File.Open(logFile, FileMode.Open); - if (stream.Length >= 512 * 1024 * 1024L) + if (stream.Length >= 10 * 1024 * 1024L) { stream.SetLength(0); } diff --git a/DownKyi.Core/Danmaku2Ass/Display.cs b/DownKyi.Core/Danmaku2Ass/Display.cs index e83f48f..6e26576 100644 --- a/DownKyi.Core/Danmaku2Ass/Display.cs +++ b/DownKyi.Core/Danmaku2Ass/Display.cs @@ -204,7 +204,7 @@ namespace DownKyi.Core.Danmaku2Ass { public TopDisplay(Config config, Danmaku danmaku) : base(config, danmaku) { - Console.WriteLine("TopDisplay constructor."); + //Console.WriteLine("TopDisplay constructor."); } /// @@ -226,7 +226,7 @@ namespace DownKyi.Core.Danmaku2Ass { public BottomDisplay(Config config, Danmaku danmaku) : base(config, danmaku) { - Console.WriteLine("BottomDisplay constructor."); + //Console.WriteLine("BottomDisplay constructor."); } /// @@ -253,7 +253,7 @@ namespace DownKyi.Core.Danmaku2Ass public ScrollDisplay(Config config, Danmaku danmaku) : base() { - Console.WriteLine("ScrollDisplay constructor."); + //Console.WriteLine("ScrollDisplay constructor."); Config = config; Danmaku = danmaku; diff --git a/DownKyi.Core/Danmaku2Ass/Producer.cs b/DownKyi.Core/Danmaku2Ass/Producer.cs index 42e0ae3..068c1a0 100644 --- a/DownKyi.Core/Danmaku2Ass/Producer.cs +++ b/DownKyi.Core/Danmaku2Ass/Producer.cs @@ -49,16 +49,16 @@ namespace DownKyi.Core.Danmaku2Ass public void ApplyFilter() { Dictionary filterDetail = new Dictionary() { - { "top_filter",0}, - { "bottom_filter",0}, - { "scroll_filter",0}, + { "top_filter", 0}, + { "bottom_filter", 0}, + { "scroll_filter", 0}, //{ "custom_filter",0} }; List danmakus = Danmakus; //string[] orders = { "top_filter", "bottom_filter", "scroll_filter", "custom_filter" }; string[] orders = { "top_filter", "bottom_filter", "scroll_filter" }; - foreach (var name in orders) + foreach (string name in orders) { Filter filter; try diff --git a/DownKyi/Images/ButtonIcon.cs b/DownKyi/Images/ButtonIcon.cs index d747936..e4a3c8a 100644 --- a/DownKyi/Images/ButtonIcon.cs +++ b/DownKyi/Images/ButtonIcon.cs @@ -69,6 +69,17 @@ Fill = "#FF000000" }; + Trash = new VectorImage + { + Height = 20, + Width = 20, + Data = @"M683 85 q0 -27 -20.5 -55 q-20.5 -28 -65.5 -30 l-170 0 q-39 1 -62 23.5 q-23 22.5 -24 61.5 l-341 0 l0 86 l1024 0 l0 -86 + l-341 0 ZM341 256 l86 0 l0 597 l-86 0 l0 -597 ZM597 256 l86 0 l0 597 l-86 0 l0 -597 ZM853 853 q0 39 -23 62 + q-23 23 -62 24 l-512 0 q-39 -1 -62 -24 q-23 -23 -23 -62 l0 -597 l-86 0 l0 597 q2 73 50.5 121 q48.5 48 120.5 50 l512 0 + q72 -2 120.5 -50 q48.5 -48 50.5 -121 l0 -597 l-86 0 l0 597 Z", + Fill = "#FF000000" + }; + Delete = new VectorImage { Height = 18, @@ -103,6 +114,30 @@ Fill = "#FF000000" }; + Retry = new VectorImage + { + Height = 20, + Width = 20, + Data = @"M536.69 128.65 q-161.14 5.2 -270.3 113.71 q-109.15 108.5 -113.05 269.64 q3.9 161.14 113.05 269.64 + q109.16 108.5 270.3 113.71 q101.36 -1.3 185.82 -47.43 q84.47 -46.13 140.35 -129.3 q6.5 -14.3 22.09 -24.7 + q15.6 -10.39 31.19 -10.39 q28.59 0 47.44 18.85 q18.84 18.85 20.14 48.74 q0 11.69 -5.2 20.79 q0 3.9 0 7.8 l-3.9 5.19 + q-72.77 111.76 -185.82 174.78 q-113.06 63.03 -246.91 64.33 q-102.66 0 -196.22 -38.34 q-93.57 -38.33 -166.34 -111.11 + q-72.77 -72.77 -111.1 -166.34 q-38.33 -93.56 -38.33 -196.22 q0 -102.66 38.33 -196.23 q38.34 -93.56 111.1 -166.33 + q72.77 -72.77 166.34 -111.1 q93.56 -38.34 196.22 -38.34 q92.26 0 176.73 31.19 q84.47 31.19 152.04 89.66 l0 -25.99 + q1.3 -27.29 18.2 -44.83 q16.89 -17.54 42.88 -17.54 q25.99 0 44.18 18.19 q18.19 18.19 18.19 44.18 l0 189.73 + q0 24.69 -18.19 42.88 q-18.19 18.19 -42.88 18.19 l-191.03 0 q-24.69 0 -42.88 -18.19 q-18.2 -18.19 -18.2 -42.88 + q0 -28.59 16.25 -47.43 q16.25 -18.84 44.84 -20.13 l37.69 0 q-51.98 -42.89 -114.36 -65.63 q-62.38 -22.74 -128.65 -22.74 Z", + Fill = "#FF000000" + }; + + Folder = new VectorImage + { + Height = 16, + Width = 20, + Data = @"M18,2H10L8,0H2A2,2,0,0,0,0,2V14a2,2,0,0,0,2,2H18a2,2,0,0,0,2-2V4A2,2,0,0,0,18,2Zm0,12H2V4H18Z", + Fill = "#FF000000" + }; + } public VectorImage GeneralSearch { get; private set; } @@ -110,9 +145,12 @@ public VectorImage DownloadManage { get; private set; } public VectorImage Toolbox { get; private set; } + public VectorImage Trash { get; private set; } public VectorImage Delete { get; private set; } public VectorImage Start { get; private set; } public VectorImage Pause { get; private set; } + public VectorImage Retry { get; private set; } + public VectorImage Folder { get; private set; } } } diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index d7e3447..35f2e9d 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -116,6 +116,13 @@ 按序号排序 清空所有记录 + 开始 + 暂停 + 重试 + 移除 + 打开文件夹 + 播放 + 按回车键应用设置 diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index 31885ac..7806276 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/DownKyi/Services/Download/AriaDownloadService.cs @@ -11,6 +11,7 @@ using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Core.Storage; using DownKyi.Core.Utils; +using DownKyi.Images; using DownKyi.Models; using DownKyi.Utils; using DownKyi.ViewModels.DownloadManager; @@ -145,7 +146,6 @@ namespace DownKyi.Services.Download case DownloadResult.SUCCESS: return Path.Combine(path, fileName); case DownloadResult.FAILED: - return null; case DownloadResult.ABORT: return null; default: @@ -395,6 +395,8 @@ namespace DownKyi.Services.Download foreach (DownloadingItem item in downloadingList) { item.Downloading.DownloadStatus = DownloadStatus.WAIT_FOR_DOWNLOAD; + item.Progress = 0; + downloadStorageService.UpdateDownloading(item); } foreach (DownloadedItem item in downloadedList) @@ -494,6 +496,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + var isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } // 设置下载状态 downloading.Downloading.DownloadStatus = DownloadStatus.DOWNLOADING; @@ -507,6 +515,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } string videoUid = null; // 如果需要下载视频 @@ -517,6 +531,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } string outputDanmaku = null; // 如果需要下载弹幕 @@ -527,6 +547,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } List outputSubtitles = null; // 如果需要下载字幕 @@ -537,6 +563,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } string outputCover = null; // 如果需要下载封面 @@ -552,6 +584,12 @@ namespace DownKyi.Services.Download // 暂停 Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } // 混流 string outputMedia = string.Empty; @@ -561,9 +599,16 @@ namespace DownKyi.Services.Download } // 暂停 - Pause(downloading); + //Pause(downloading); + // 是否存在 + isExist = IsExist(downloading); + if (!isExist.Result) + { + return; + } // 检测音频、视频是否下载成功 + bool isMediaSuccess = true; if (downloading.DownloadBase.NeedDownloadContent["downloadAudio"] || downloading.DownloadBase.NeedDownloadContent["downloadVideo"]) { // 只有下载音频不下载视频时才输出aac @@ -571,16 +616,31 @@ namespace DownKyi.Services.Download if (File.Exists(outputMedia)) { // 成功 + isMediaSuccess = true; + } + else + { + isMediaSuccess = false; } } // 检测弹幕是否下载成功 - if (downloading.DownloadBase.NeedDownloadContent["downloadDanmaku"] && File.Exists(outputDanmaku)) + bool isDanmakuSuccess = true; + if (downloading.DownloadBase.NeedDownloadContent["downloadDanmaku"]) { - // 成功 + if (File.Exists(outputDanmaku)) + { + // 成功 + isDanmakuSuccess = true; + } + else + { + isDanmakuSuccess = false; + } } // 检测字幕是否下载成功 + bool isSubtitleSuccess = true; if (downloading.DownloadBase.NeedDownloadContent["downloadSubtitle"]) { if (outputSubtitles == null) @@ -591,25 +651,39 @@ namespace DownKyi.Services.Download { foreach (string subtitle in outputSubtitles) { - if (File.Exists(subtitle)) + if (!File.Exists(subtitle)) { - // 成功 + // 如果有一个不存在则失败 + isSubtitleSuccess = false; } } } } // 检测封面是否下载成功 - if (downloading.DownloadBase.NeedDownloadContent["downloadCover"] && File.Exists(outputCover)) + bool isCover = true; + if (downloading.DownloadBase.NeedDownloadContent["downloadCover"]) { - // 成功 + if (File.Exists(outputCover)) + { + // 成功 + isCover = true; + } + else + { + isCover = false; + } + } + + if (!isMediaSuccess || !isDanmakuSuccess || !isSubtitleSuccess || !isCover) + { + downloading.Downloading.DownloadStatus = DownloadStatus.DOWNLOAD_FAILED; + downloading.StartOrPause = ButtonIcon.Instance().Retry; + downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary"); + return; } - // TODO - // 将下载结果写入数据库 - // 包括下载请求的DownloadingItem对象, - // 下载结果是否成功等 - // 对是否成功的判断:只要outputMedia存在则成功,否则失败 + // 下载完成后处理 Downloaded downloaded = new Downloaded { @@ -690,6 +764,34 @@ namespace DownKyi.Services.Download downloading.DownloadStatusTitle = oldStatus; } + /// + /// 是否存在于下载列表中 + /// + /// + /// + private async Task IsExist(DownloadingItem downloading) + { + bool isExist = downloadingList.Contains(downloading); + if (isExist) + { + return true; + } + else + { + // 先恢复为waiting状态,暂停状态下Remove会导致文件重新下载,原因暂不清楚 + await AriaClient.UnpauseAsync(downloading.Downloading.Gid); + // 移除下载项 + var ariaRemove = await AriaClient.RemoveAsync(downloading.Downloading.Gid); + if (ariaRemove == null || ariaRemove.Result == downloading.Downloading.Gid) + { + // 从内存中删除下载项 + await AriaClient.RemoveDownloadResultAsync(downloading.Downloading.Gid); + } + + return false; + } + } + /// /// 启动Aria服务器 /// @@ -724,13 +826,6 @@ namespace DownKyi.Services.Download var task = await AriaServer.StartServerAsync(config); if (task) { Console.WriteLine("Start ServerAsync Completed"); } Console.WriteLine("Start ServerAsync end"); - - // 恢复所有下载 - //var ariaPause = await AriaClient.UnpauseAllAsync(); - //if (ariaPause != null) - //{ - // Core.Utils.Debugging.Console.PrintLine(ariaPause.ToString()); - //} } /// diff --git a/DownKyi/Themes/ColorBrush.xaml b/DownKyi/Themes/ColorBrush.xaml index a35e8a0..3d1c458 100644 --- a/DownKyi/Themes/ColorBrush.xaml +++ b/DownKyi/Themes/ColorBrush.xaml @@ -14,6 +14,8 @@ + + diff --git a/DownKyi/Themes/Colors/ColorDefault.xaml b/DownKyi/Themes/Colors/ColorDefault.xaml index 168440b..1c38497 100644 --- a/DownKyi/Themes/Colors/ColorDefault.xaml +++ b/DownKyi/Themes/Colors/ColorDefault.xaml @@ -14,6 +14,8 @@ #FFE81123 #FFF1707A + #FFFF4D3C + #FF00A1D6 #C800A1D6 #7F00A1D6 diff --git a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs index 5149d28..0da70a4 100644 --- a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs +++ b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs @@ -1,5 +1,6 @@ using DownKyi.Images; using DownKyi.Models; +using DownKyi.Utils; using Prism.Commands; using System.IO; @@ -9,6 +10,17 @@ namespace DownKyi.ViewModels.DownloadManager { public DownloadedItem() : base() { + // 打开文件夹按钮 + OpenFolder = ButtonIcon.Instance().Folder; + OpenFolder.Fill = DictionaryResource.GetColor("ColorPrimary"); + + // 打开视频按钮 + OpenVideo = ButtonIcon.Instance().Start; + OpenVideo.Fill = DictionaryResource.GetColor("ColorPrimary"); + + // 删除按钮 + RemoveVideo = ButtonIcon.Instance().Trash; + RemoveVideo.Fill = DictionaryResource.GetColor("ColorWarning"); } // model数据 @@ -73,9 +85,10 @@ namespace DownKyi.ViewModels.DownloadManager private void ExecuteOpenFolderCommand() { string videoPath = $"{DownloadBase.FilePath}.mp4"; - if (File.Exists(videoPath)) + FileInfo fileInfo = new FileInfo(videoPath); + if (File.Exists(fileInfo.FullName)) { - System.Diagnostics.Process.Start("Explorer", "/select," + videoPath); + System.Diagnostics.Process.Start("Explorer", "/select," + fileInfo.FullName); } else { @@ -93,9 +106,10 @@ namespace DownKyi.ViewModels.DownloadManager private void ExecuteOpenVideoCommand() { string videoPath = $"{DownloadBase.FilePath}.mp4"; - if (File.Exists(videoPath)) + var fileInfo = new FileInfo(videoPath); + if (File.Exists(fileInfo.FullName)) { - System.Diagnostics.Process.Start(videoPath); + System.Diagnostics.Process.Start(fileInfo.FullName); } else { diff --git a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs index e727366..aa2f30d 100644 --- a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs +++ b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs @@ -80,6 +80,13 @@ namespace DownKyi.ViewModels.DownloadManager } } + // 操作提示 + private string operationTip; + public string OperationTip + { + get => operationTip; + set => SetProperty(ref operationTip, value); + } #region 控制按钮 @@ -87,7 +94,14 @@ namespace DownKyi.ViewModels.DownloadManager public VectorImage StartOrPause { get => startOrPause; - set => SetProperty(ref startOrPause, value); + set + { + SetProperty(ref startOrPause, value); + + OperationTip = value.Equals(ButtonIcon.Instance().Start) ? DictionaryResource.GetString("StartDownload") + : value.Equals(ButtonIcon.Instance().Pause) ? DictionaryResource.GetString("PauseDownload") + : value.Equals(ButtonIcon.Instance().Retry) ? DictionaryResource.GetString("RetryDownload") : null; + } } private VectorImage delete; diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs index 492cf1d..ec28582 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs @@ -48,6 +48,9 @@ namespace DownKyi.ViewModels.DownloadManager case 2: App.SortDownloadedList(DownloadFinishedSort.NUMBER); break; + default: + App.SortDownloadedList(DownloadFinishedSort.DOWNLOAD); + break; } } @@ -60,6 +63,7 @@ namespace DownKyi.ViewModels.DownloadManager /// private void ExecuteClearAllDownloadedCommand() { + DownloadedList.Clear(); } #endregion diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs index d4bc070..1985f53 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs @@ -46,6 +46,8 @@ namespace DownKyi.ViewModels.DownloadManager case DownloadStatus.NOT_STARTED: case DownloadStatus.WAIT_FOR_DOWNLOAD: downloading.Downloading.DownloadStatus = DownloadStatus.PAUSE_STARTED; + downloading.StartOrPause = ButtonIcon.Instance().Start; + downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary"); break; case DownloadStatus.PAUSE_STARTED: break; @@ -53,6 +55,8 @@ namespace DownKyi.ViewModels.DownloadManager break; case DownloadStatus.DOWNLOADING: downloading.Downloading.DownloadStatus = DownloadStatus.PAUSE; + downloading.StartOrPause = ButtonIcon.Instance().Start; + downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary"); break; case DownloadStatus.DOWNLOAD_SUCCEED: // 下载成功后会从下载列表中删除 @@ -63,9 +67,6 @@ namespace DownKyi.ViewModels.DownloadManager default: break; } - - downloading.StartOrPause = ButtonIcon.Instance().Start; - downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary"); } } diff --git a/DownKyi/Views/DownloadManager/ViewDownloadFinished.xaml b/DownKyi/Views/DownloadManager/ViewDownloadFinished.xaml index 49b63b6..3d317ba 100644 --- a/DownKyi/Views/DownloadManager/ViewDownloadFinished.xaml +++ b/DownKyi/Views/DownloadManager/ViewDownloadFinished.xaml @@ -100,68 +100,56 @@ - - - - - - - + Command="{Binding OpenFolderCommand}" + Style="{StaticResource ImageBtnStyle}" + ToolTip="{DynamicResource OpenFolder}"> + + Stretch="Uniform" /> - + - - - - - - - + Command="{Binding OpenVideoCommand}" + Style="{StaticResource ImageBtnStyle}" + ToolTip="{DynamicResource OpenVideo}"> + + Stretch="Uniform" /> - + - - - - - - - + Command="{Binding RemoveVideoCommand}" + Style="{StaticResource ImageBtnStyle}" + ToolTip="{DynamicResource DeleteDownload}"> + + Stretch="Uniform" /> - + diff --git a/DownKyi/Views/DownloadManager/ViewDownloading.xaml b/DownKyi/Views/DownloadManager/ViewDownloading.xaml index 6b60d1b..fd5e4bc 100644 --- a/DownKyi/Views/DownloadManager/ViewDownloading.xaml +++ b/DownKyi/Views/DownloadManager/ViewDownloading.xaml @@ -160,47 +160,39 @@ - - - - - - - + Command="{Binding StartOrPauseCommand}" + Style="{StaticResource ImageBtnStyle}" + ToolTip="{Binding OperationTip}"> + + Stretch="Uniform" /> - + - - - - - - - + Command="{Binding DeleteCommand}" + Style="{StaticResource ImageBtnStyle}" + ToolTip="{DynamicResource DeleteDownload}"> + + Stretch="Uniform" /> - +