diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index e348a60..a8d4427 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -131,19 +131,16 @@ namespace DownKyi 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/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index f00384d..b481d9f 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -326,6 +326,8 @@ 您确定要删除吗? 请选择文件夹 + 路径错误! + 下载设置 位置: diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index bcfb703..3847787 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/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 @@ namespace DownKyi.Services.Download 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/DownKyi/Services/Download/BuiltinDownloadService.cs b/DownKyi/Services/Download/BuiltinDownloadService.cs index 44b7035..1870b63 100644 --- a/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -7,6 +7,7 @@ using DownKyi.Core.Utils; 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/DownKyi/Services/Download/CustomAriaDownloadService.cs b/DownKyi/Services/Download/CustomAriaDownloadService.cs index 43fea1d..9b62701 100644 --- a/DownKyi/Services/Download/CustomAriaDownloadService.cs +++ b/DownKyi/Services/Download/CustomAriaDownloadService.cs @@ -9,6 +9,7 @@ using DownKyi.Core.Utils; 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/DownKyi/Services/Download/DownloadService.cs b/DownKyi/Services/Download/DownloadService.cs index 49a7c60..69615cd 100644 --- a/DownKyi/Services/Download/DownloadService.cs +++ b/DownKyi/Services/Download/DownloadService.cs @@ -11,6 +11,7 @@ using DownKyi.Images; 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 @@ namespace DownKyi.Services.Download { protected string Tag = "DownloadService"; + protected IDialogService dialogService; + protected ObservableCollection downloadingList; protected ObservableCollection downloadedList; @@ -41,10 +44,13 @@ namespace DownKyi.Services.Download /// /// /// - 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 @@ namespace DownKyi.Services.Download // 路径不存在则创建 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