aria2 输出错误信息到UI

croire 2 years ago
parent dc4033cd8b
commit 4da4af680e

@ -5,8 +5,6 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace DownKyi.Core.Aria2cNet.Server namespace DownKyi.Core.Aria2cNet.Server
{ {
@ -22,7 +20,7 @@ namespace DownKyi.Core.Aria2cNet.Server
/// <param name="output"></param> /// <param name="output"></param>
/// <param name="window"></param> /// <param name="window"></param>
/// <returns></returns> /// <returns></returns>
public static async Task<bool> StartServerAsync(AriaConfig config, TextBox output = null, Window window = null) public static async Task<bool> StartServerAsync(AriaConfig config, Action<string> action)
{ {
// aria端口 // aria端口
ListenPort = config.ListenPort; ListenPort = config.ListenPort;
@ -114,17 +112,11 @@ namespace DownKyi.Core.Aria2cNet.Server
null, (s, e) => null, (s, e) =>
{ {
if (e.Data == null || e.Data == "" || e.Data.Replace(" ", "") == "") { return; } if (e.Data == null || e.Data == "" || e.Data.Replace(" ", "") == "") { return; }
Utils.Debugging.Console.PrintLine(e.Data); Utils.Debugging.Console.PrintLine(e.Data);
LogManager.Debug("AriaServer", e.Data); LogManager.Debug("AriaServer", e.Data);
if (output != null && window != null) action.Invoke(e.Data);
{
window.Dispatcher.Invoke(new Action(() =>
{
output.Text += e.Data + "\n";
output.ScrollToEnd();
}));
}
}); });
}); });

@ -15,7 +15,9 @@ using DownKyi.Views.Friends;
using DownKyi.Views.Settings; using DownKyi.Views.Settings;
using DownKyi.Views.Toolbox; using DownKyi.Views.Toolbox;
using DownKyi.Views.UserSpace; using DownKyi.Views.UserSpace;
using Prism.DryIoc;
using Prism.Ioc; using Prism.Ioc;
using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -132,7 +134,7 @@ namespace DownKyi
downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList);
break; break;
case Downloader.ARIA: case Downloader.ARIA:
downloadService = new AriaDownloadService(DownloadingList, DownloadedList); downloadService = new AriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService)));
break; break;
case Downloader.CUSTOM_ARIA: case Downloader.CUSTOM_ARIA:
downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList); downloadService = new CustomAriaDownloadService(DownloadingList, DownloadedList);

@ -50,7 +50,7 @@ namespace DownKyi.Services
return ShowMessage(image, title, message); 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; ButtonResult result = ButtonResult.None;
if (dialogService == null) if (dialogService == null)

@ -7,9 +7,11 @@ using DownKyi.Core.BiliApi.VideoStream.Models;
using DownKyi.Core.Logging; using DownKyi.Core.Logging;
using DownKyi.Core.Settings; using DownKyi.Core.Settings;
using DownKyi.Core.Utils; using DownKyi.Core.Utils;
using DownKyi.Images;
using DownKyi.Models; using DownKyi.Models;
using DownKyi.Utils; using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager; using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -24,9 +26,16 @@ namespace DownKyi.Services.Download
/// </summary> /// </summary>
public class AriaDownloadService : DownloadService, IDownloadService public class AriaDownloadService : DownloadService, IDownloadService
{ {
public AriaDownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList) : base(downloadingList, downloadedList) private readonly IDialogService dialogService;
public AriaDownloadService(
ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService = null) :
base(downloadingList, downloadedList)
{ {
Tag = "AriaDownloadService"; Tag = "AriaDownloadService";
this.dialogService = dialogService;
} }
#region 音视频 #region 音视频
@ -327,8 +336,24 @@ namespace DownKyi.Services.Download
FileAllocation = SettingsManager.GetInstance().GetAriaFileAllocation(), FileAllocation = SettingsManager.GetInstance().GetAriaFileAllocation(),
Headers = header Headers = header
}; };
var task = await AriaServer.StartServerAsync(config);
string errorMessage = null;
var task = await AriaServer.StartServerAsync(config, new Action<string>((output) =>
{
errorMessage += output + "\n";
}));
if (task) { Console.WriteLine("Start ServerAsync Completed"); } 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++) for (int i = 0; i < 10; i++)
{ {
var globOpt = await AriaClient.GetGlobalOptionAsync(); var globOpt = await AriaClient.GetGlobalOptionAsync();

@ -1,6 +1,7 @@
using DownKyi.Images; using DownKyi.Images;
using Prism.Commands; using Prism.Commands;
using Prism.Services.Dialogs; using Prism.Services.Dialogs;
using System.Windows;
namespace DownKyi.ViewModels.Dialogs namespace DownKyi.ViewModels.Dialogs
{ {
@ -20,8 +21,23 @@ namespace DownKyi.ViewModels.Dialogs
private string message; private string message;
public string Message public string Message
{ {
get { return message; } get => message;
set { SetProperty(ref message, value); } 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 #endregion
@ -57,6 +73,17 @@ namespace DownKyi.ViewModels.Dialogs
Image = parameters.GetValue<VectorImage>("image"); Image = parameters.GetValue<VectorImage>("image");
Title = parameters.GetValue<string>("title"); Title = parameters.GetValue<string>("title");
Message = parameters.GetValue<string>("message"); Message = parameters.GetValue<string>("message");
if (Image == SystemIcon.Instance().Error)
{
AloneButton = Visibility.Visible;
TwoButton = Visibility.Collapsed;
}
else
{
AloneButton = Visibility.Collapsed;
TwoButton = Visibility.Visible;
}
} }
#endregion #endregion

@ -109,7 +109,19 @@
TextTrimming="CharacterEllipsis" TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow" /> TextWrapping="WrapWithOverflow" />
<Grid Grid.Row="1"> <Button
Grid.Row="1"
Width="75"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Command="{Binding AllowCommand}"
Content="{DynamicResource Allow}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}"
Visibility="{Binding AloneButton}" />
<Grid Grid.Row="1" Visibility="{Binding TwoButton}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" /> <ColumnDefinition MinWidth="100" />
<ColumnDefinition MinWidth="100" /> <ColumnDefinition MinWidth="100" />

Loading…
Cancel
Save