From 4da4af680e1bc464745505a69c5a29253afb72b9 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Tue, 10 Jan 2023 21:22:09 +0800 Subject: [PATCH] =?UTF-8?q?aria2=20=E8=BE=93=E5=87=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=88=B0UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi.Core/Aria2cNet/Server/AriaServer.cs | 14 ++------- DownKyi/App.xaml.cs | 4 ++- DownKyi/Services/AlertService.cs | 2 +- .../Services/Download/AriaDownloadService.cs | 29 +++++++++++++++-- .../Dialogs/ViewAlertDialogViewModel.cs | 31 +++++++++++++++++-- DownKyi/Views/Dialogs/ViewAlertDialog.xaml | 14 ++++++++- 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/DownKyi.Core/Aria2cNet/Server/AriaServer.cs b/DownKyi.Core/Aria2cNet/Server/AriaServer.cs index d61cb15..e4d5b34 100644 --- a/DownKyi.Core/Aria2cNet/Server/AriaServer.cs +++ b/DownKyi.Core/Aria2cNet/Server/AriaServer.cs @@ -5,8 +5,6 @@ using System.Diagnostics; using System.IO; using System.Text; using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; namespace DownKyi.Core.Aria2cNet.Server { @@ -22,7 +20,7 @@ namespace DownKyi.Core.Aria2cNet.Server /// /// /// - public static async Task StartServerAsync(AriaConfig config, TextBox output = null, Window window = null) + public static async Task StartServerAsync(AriaConfig config, Action action) { // aria端口 ListenPort = config.ListenPort; @@ -114,17 +112,11 @@ namespace DownKyi.Core.Aria2cNet.Server null, (s, e) => { if (e.Data == null || e.Data == "" || e.Data.Replace(" ", "") == "") { return; } + Utils.Debugging.Console.PrintLine(e.Data); LogManager.Debug("AriaServer", e.Data); - if (output != null && window != null) - { - window.Dispatcher.Invoke(new Action(() => - { - output.Text += e.Data + "\n"; - output.ScrollToEnd(); - })); - } + action.Invoke(e.Data); }); }); diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index a6ceda2..e348a60 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -15,7 +15,9 @@ using DownKyi.Views.Friends; using DownKyi.Views.Settings; using DownKyi.Views.Toolbox; using DownKyi.Views.UserSpace; +using Prism.DryIoc; using Prism.Ioc; +using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -132,7 +134,7 @@ namespace DownKyi downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); break; case Downloader.ARIA: - downloadService = new AriaDownloadService(DownloadingList, DownloadedList); + downloadService = new AriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService))); break; case Downloader.CUSTOM_ARIA: downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList); diff --git a/DownKyi/Services/AlertService.cs b/DownKyi/Services/AlertService.cs index e30a9ff..5302459 100644 --- a/DownKyi/Services/AlertService.cs +++ b/DownKyi/Services/AlertService.cs @@ -50,7 +50,7 @@ namespace DownKyi.Services return ShowMessage(image, title, message); } - private ButtonResult ShowMessage(VectorImage image, string type, string message) + public ButtonResult ShowMessage(VectorImage image, string type, string message) { ButtonResult result = ButtonResult.None; if (dialogService == null) diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index 03925b2..d2954a7 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/DownKyi/Services/Download/AriaDownloadService.cs @@ -7,9 +7,11 @@ using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Logging; using DownKyi.Core.Settings; using DownKyi.Core.Utils; +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; @@ -24,9 +26,16 @@ namespace DownKyi.Services.Download /// public class AriaDownloadService : DownloadService, IDownloadService { - public AriaDownloadService(ObservableCollection downloadingList, ObservableCollection downloadedList) : base(downloadingList, downloadedList) + private readonly IDialogService dialogService; + + public AriaDownloadService( + ObservableCollection downloadingList, + ObservableCollection downloadedList, + IDialogService dialogService = null) : + base(downloadingList, downloadedList) { Tag = "AriaDownloadService"; + this.dialogService = dialogService; } #region 音视频 @@ -327,8 +336,24 @@ namespace DownKyi.Services.Download FileAllocation = SettingsManager.GetInstance().GetAriaFileAllocation(), Headers = header }; - var task = await AriaServer.StartServerAsync(config); + + string errorMessage = null; + var task = await AriaServer.StartServerAsync(config, new Action((output) => + { + errorMessage += output + "\n"; + })); if (task) { Console.WriteLine("Start ServerAsync Completed"); } + + // 显示错误信息 + if (dialogService != null && errorMessage != null && errorMessage.Contains("ERROR")) + { + AlertService alertService = new AlertService(dialogService); + ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error, + $"Aria2 {DictionaryResource.GetString("Error")}", + errorMessage); + return; + } + for (int i = 0; i < 10; i++) { var globOpt = await AriaClient.GetGlobalOptionAsync(); diff --git a/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs index 4a61093..4bd897f 100644 --- a/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs +++ b/DownKyi/ViewModels/Dialogs/ViewAlertDialogViewModel.cs @@ -1,6 +1,7 @@ using DownKyi.Images; using Prism.Commands; using Prism.Services.Dialogs; +using System.Windows; namespace DownKyi.ViewModels.Dialogs { @@ -20,8 +21,23 @@ namespace DownKyi.ViewModels.Dialogs private string message; public string Message { - get { return message; } - set { SetProperty(ref message, value); } + get => message; + set => SetProperty(ref message, value); + } + + + private Visibility aloneButton; + public Visibility AloneButton + { + get => aloneButton; + set => SetProperty(ref aloneButton, value); + } + + private Visibility twoButton; + public Visibility TwoButton + { + get => twoButton; + set => SetProperty(ref twoButton, value); } #endregion @@ -57,6 +73,17 @@ namespace DownKyi.ViewModels.Dialogs Image = parameters.GetValue("image"); Title = parameters.GetValue("title"); Message = parameters.GetValue("message"); + + if (Image == SystemIcon.Instance().Error) + { + AloneButton = Visibility.Visible; + TwoButton = Visibility.Collapsed; + } + else + { + AloneButton = Visibility.Collapsed; + TwoButton = Visibility.Visible; + } } #endregion diff --git a/DownKyi/Views/Dialogs/ViewAlertDialog.xaml b/DownKyi/Views/Dialogs/ViewAlertDialog.xaml index 16de4ef..becee3e 100644 --- a/DownKyi/Views/Dialogs/ViewAlertDialog.xaml +++ b/DownKyi/Views/Dialogs/ViewAlertDialog.xaml @@ -109,7 +109,19 @@ TextTrimming="CharacterEllipsis" TextWrapping="WrapWithOverflow" /> - +