From 683159b87b3a7910fde23032db6211db24e4fcfd Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Mon, 13 Feb 2023 22:32:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=89=8D=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84=E4=B8=8B=E8=BD=BD=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=20#574?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DownKyi/App.xaml.cs | 9 +++----- src/DownKyi/Languages/Default.xaml | 2 ++ .../Services/Download/AriaDownloadService.cs | 9 +++----- .../Download/BuiltinDownloadService.cs | 6 ++++- .../Download/CustomAriaDownloadService.cs | 6 ++++- .../Services/Download/DownloadService.cs | 23 +++++++++++++++++-- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/DownKyi/App.xaml.cs b/src/DownKyi/App.xaml.cs index e348a605..a8d44274 100644 --- a/src/DownKyi/App.xaml.cs +++ b/src/DownKyi/App.xaml.cs @@ -131,19 +131,16 @@ await Task.Run(() => case Downloader.NOT_SET: break; case Downloader.BUILT_IN: - downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); + downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService))); break; case Downloader.ARIA: downloadService = new AriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService))); break; case Downloader.CUSTOM_ARIA: - downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList); + downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService))); break; } - if (downloadService != null) - { - downloadService.Start(); - } + downloadService?.Start(); return Container.Resolve(); } diff --git a/src/DownKyi/Languages/Default.xaml b/src/DownKyi/Languages/Default.xaml index f00384dd..b481d9f6 100644 --- a/src/DownKyi/Languages/Default.xaml +++ b/src/DownKyi/Languages/Default.xaml @@ -326,6 +326,8 @@ 您确定要删除吗? 请选择文件夹 + 路径错误! + 下载设置 位置: diff --git a/src/DownKyi/Services/Download/AriaDownloadService.cs b/src/DownKyi/Services/Download/AriaDownloadService.cs index bcfb7030..3847787c 100644 --- a/src/DownKyi/Services/Download/AriaDownloadService.cs +++ b/src/DownKyi/Services/Download/AriaDownloadService.cs @@ -26,16 +26,13 @@ namespace DownKyi.Services.Download /// public class AriaDownloadService : DownloadService, IDownloadService { - private readonly IDialogService dialogService; - public AriaDownloadService( ObservableCollection downloadingList, ObservableCollection downloadedList, - IDialogService dialogService = null) : - base(downloadingList, downloadedList) + IDialogService dialogService) : + base(downloadingList, downloadedList, dialogService) { Tag = "AriaDownloadService"; - this.dialogService = dialogService; } #region 音视频 @@ -345,7 +342,7 @@ private async void StartAriaServer() if (task) { Console.WriteLine("Start ServerAsync Completed"); } // 显示错误信息 - if (dialogService != null && errorMessage != null && errorMessage.Contains("ERROR")) + if (errorMessage != null && errorMessage.Contains("ERROR")) { AlertService alertService = new AlertService(dialogService); ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error, diff --git a/src/DownKyi/Services/Download/BuiltinDownloadService.cs b/src/DownKyi/Services/Download/BuiltinDownloadService.cs index 44b7035b..1870b633 100644 --- a/src/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/src/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -7,6 +7,7 @@ using DownKyi.Models; using DownKyi.Utils; using DownKyi.ViewModels.DownloadManager; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -19,7 +20,10 @@ namespace DownKyi.Services.Download { public class BuiltinDownloadService : DownloadService, IDownloadService { - public BuiltinDownloadService(ObservableCollection downloadingList, ObservableCollection downloadedList) : base(downloadingList, downloadedList) + public BuiltinDownloadService(ObservableCollection downloadingList, + ObservableCollection downloadedList, + IDialogService dialogService + ) : base(downloadingList, downloadedList, dialogService) { Tag = "BuiltinDownloadService"; } diff --git a/src/DownKyi/Services/Download/CustomAriaDownloadService.cs b/src/DownKyi/Services/Download/CustomAriaDownloadService.cs index 43fea1d4..9b62701a 100644 --- a/src/DownKyi/Services/Download/CustomAriaDownloadService.cs +++ b/src/DownKyi/Services/Download/CustomAriaDownloadService.cs @@ -9,6 +9,7 @@ using DownKyi.Models; using DownKyi.Utils; using DownKyi.ViewModels.DownloadManager; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -23,7 +24,10 @@ namespace DownKyi.Services.Download /// public class CustomAriaDownloadService : DownloadService, IDownloadService { - public CustomAriaDownloadService(ObservableCollection downloadingList, ObservableCollection downloadedList) : base(downloadingList, downloadedList) + public CustomAriaDownloadService(ObservableCollection downloadingList, + ObservableCollection downloadedList, + IDialogService dialogService + ) : base(downloadingList, downloadedList, dialogService) { Tag = "AriaDownloadService"; } diff --git a/src/DownKyi/Services/Download/DownloadService.cs b/src/DownKyi/Services/Download/DownloadService.cs index 49a7c604..69615cda 100644 --- a/src/DownKyi/Services/Download/DownloadService.cs +++ b/src/DownKyi/Services/Download/DownloadService.cs @@ -11,6 +11,7 @@ using DownKyi.Models; using DownKyi.Utils; using DownKyi.ViewModels.DownloadManager; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -25,6 +26,8 @@ public abstract class DownloadService { protected string Tag = "DownloadService"; + protected IDialogService dialogService; + protected ObservableCollection downloadingList; protected ObservableCollection downloadedList; @@ -41,10 +44,13 @@ public abstract class DownloadService /// /// /// - public DownloadService(ObservableCollection downloadingList, ObservableCollection downloadedList) + public DownloadService(ObservableCollection downloadingList, + ObservableCollection downloadedList, + IDialogService dialogService) { this.downloadingList = downloadingList; this.downloadedList = downloadedList; + this.dialogService = dialogService; } protected PlayUrlDashVideo BaseDownloadAudio(DownloadingItem downloading) @@ -438,7 +444,20 @@ private async Task SingleDownload(DownloadingItem downloading) // 路径不存在则创建 if (!Directory.Exists(path)) { - Directory.CreateDirectory(path); + try + { + Directory.CreateDirectory(path); + } + catch (Exception e) + { + Core.Utils.Debugging.Console.PrintLine(Tag, e.ToString()); + LogManager.Debug(Tag, e.Message); + + AlertService alertService = new AlertService(dialogService); + ButtonResult result = alertService.ShowError($"{path}{DictionaryResource.GetString("DirectoryError")}"); + + return; + } } try