From 70c2c89d3283b28e85d4185af347173b905a4c47 Mon Sep 17 00:00:00 2001 From: aiqinxuancai Date: Mon, 1 Apr 2024 10:51:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=94=99=E8=AF=AF=E5=8E=9F=E5=9B=A0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria2Fast/App.xaml | 22 ++++++ Aria2Fast/Service/Model/TaskModel.cs | 60 +++++++++++++- Aria2Fast/View/Contver/DownloadSizeContver.cs | 78 +++++++++---------- Aria2Fast/View/Contver/VisibilityConverter.cs | 73 +++++++++++++++++ Aria2Fast/View/View/TaskListCellControl.xaml | 55 +++++++++---- 5 files changed, 226 insertions(+), 62 deletions(-) create mode 100644 Aria2Fast/View/Contver/VisibilityConverter.cs diff --git a/Aria2Fast/App.xaml b/Aria2Fast/App.xaml index 4e13b80..56e5ac0 100644 --- a/Aria2Fast/App.xaml +++ b/Aria2Fast/App.xaml @@ -2,6 +2,7 @@ x:Class="Aria2Fast.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:converter="clr-namespace:Aria2Fast.View.Contver" xmlns:local="clr-namespace:Aria2Fast" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" StartupUri="MainWindow.xaml"> @@ -29,6 +30,27 @@ Microsoft Yahei UI,Segoe UI, Lucida Sans Unicode, Verdana + + + + + + + + + + + + + + + + + + + + + diff --git a/Aria2Fast/Service/Model/TaskModel.cs b/Aria2Fast/Service/Model/TaskModel.cs index 934c473..e621eae 100644 --- a/Aria2Fast/Service/Model/TaskModel.cs +++ b/Aria2Fast/Service/Model/TaskModel.cs @@ -95,6 +95,8 @@ public string SubscriptionName } } + + /// /// 根据错误的类型来获取错误信息 /// @@ -107,7 +109,7 @@ public string ErrorMessage string message = Data.ErrorCode switch { null => "未知错误", - "0" => "所有下载成功", + "0" => "所有下载成功", //没有问题 "1" => "未知错误", "2" => "超时", "3" => "资源未找到", @@ -116,12 +118,12 @@ public string ErrorMessage "6" => "网络错误", "7" => "有未完成的下载。只有在所有已完成的下载都成功,并且在用户按 Ctrl-C 或发送 TERM 或 INT 信号退出 aria2 时队列中仍有未完成的下载,才会报告此错误", "8" => "远程服务器在需要完成下载的情况下不支持恢复", - "9" => "没有足够的磁盘空间", + "9" => "磁盘空间不足", "10" => "块长度与 .aria2 控制文件中的不一致。参见 --allow-piece-length-change 选项", "11" => "aria2正在下载相同的文件", "12" => "aria2正在下载相同信息散列的BT种子", - "13" => "文件已存在。参见 --allow-overwrite 选项", - "14" => "重命名文件失败。参见 --auto-file-renaming 选项", + "13" => "文件已存在", + "14" => "重命名文件失败", "15" => "aria2无法打开现有文件", "16" => "aria2无法创建新文件或截断现有文件", "17" => "文件I/O错误", @@ -149,6 +151,56 @@ public string ErrorMessage } } + public string ErrorMessageMin + { + get + { + if (Data != null) + { + string message = Data.ErrorCode switch + { + "0" => "", //没有问题 所有下载成功 + "1" => "未知错误", + "2" => "超时", + "3" => "资源未找到", + "4" => "发现指定数量的'资源未找到'错误", + "5" => "下载速度慢中止下载", + "6" => "网络错误", + "7" => "有未完成的下载", + "8" => "远程服务器在需要完成下载的情况下不支持恢复", + "9" => "磁盘空间不足", + "10" => "块长度与控制文件不一致", + "11" => "正在下载相同的文件", + "12" => "正在下载相同Hash的种子", + "13" => "文件已存在", + "14" => "重命名文件失败", + "15" => "无法打开现有文件", + "16" => "无法创建新文件或截断现有文件", + "17" => "文件I/O错误", + "18" => "无法创建目录", + "19" => "名称解析失败", + "20" => "无法解析Metalink", + "21" => "FTP命令失败", + "22" => "HTTP响应不正确", + "23" => "重定向过多", + "24" => "HTTP授权失败", + "25" => "无法解析BT文件", + "26" => "BT文件被损坏", + "27" => "MagnetURI不正确", + "28" => "未知错误#2", //"给定了错误的或无法识别的选项,或给定了意外的选项", + "29" => "远程服务器无法处理请求", //"由于暂时过载或维护,远程服务器无法处理请求", + "30" => "无法解析JSON-RPC请求", + "31" => "预留未使用", + "32" => "效验和验证失败", + _ => "未知错误" + }; + return message; + } + + return ""; + } + } + public string Link { get diff --git a/Aria2Fast/View/Contver/DownloadSizeContver.cs b/Aria2Fast/View/Contver/DownloadSizeContver.cs index 2e5f376..104dccb 100644 --- a/Aria2Fast/View/Contver/DownloadSizeContver.cs +++ b/Aria2Fast/View/Contver/DownloadSizeContver.cs @@ -175,13 +175,43 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur //14 => "准备添加中", //38 => "磁盘写入异常", }; + return errorTitle; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } - if (errorCode == "13") + public class ErrorStatusEasyContver : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + var value = values[0] as string; + var errorCode = values[1] as string; + + return value; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public class ErrorStatusEasyNeedShowContver : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + var value = values[0] as string; + var errorCode = values[1] as string; + + if (!string.IsNullOrWhiteSpace(value)) { - errorTitle += " [文件已存在]"; + return Visibility.Visible; } - - return errorTitle; + return Visibility.Collapsed; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) @@ -297,45 +327,7 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, } - [ValueConversion(typeof(bool), typeof(Visibility))] - public class BoolVisibilityConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value == null || (bool)value == false) - { - return Visibility.Collapsed; - } - return Visibility.Visible; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } - - - [ValueConversion(typeof(uint), typeof(Visibility))] - public class IntVisibilityConverter : IValueConverter - { - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - int? number = (int?)value; - - if (number > 0) - { - return Visibility.Visible; - } - return Visibility.Hidden; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } + public class NegationConverter : IValueConverter diff --git a/Aria2Fast/View/Contver/VisibilityConverter.cs b/Aria2Fast/View/Contver/VisibilityConverter.cs new file mode 100644 index 0000000..240499d --- /dev/null +++ b/Aria2Fast/View/Contver/VisibilityConverter.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows; + +namespace Aria2Fast.View.Contver +{ + [ValueConversion(typeof(bool), typeof(Visibility))] + public class BoolVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || (bool)value == false) + { + return Visibility.Collapsed; + } + return Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + + [ValueConversion(typeof(uint), typeof(Visibility))] + public class IntVisibilityConverter : IValueConverter + { + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + int? number = (int?)value; + + if (number > 0) + { + return Visibility.Visible; + } + return Visibility.Hidden; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + + [ValueConversion(typeof(string), typeof(Visibility))] + public class StringVisibilityConverter : IValueConverter + { + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string str = (string)value; + + if (!string.IsNullOrWhiteSpace(str)) + { + return Visibility.Visible; + } + return Visibility.Hidden; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Aria2Fast/View/View/TaskListCellControl.xaml b/Aria2Fast/View/View/TaskListCellControl.xaml index a7bb7d8..3bce3b6 100644 --- a/Aria2Fast/View/View/TaskListCellControl.xaml +++ b/Aria2Fast/View/View/TaskListCellControl.xaml @@ -2,7 +2,6 @@ x:Class="Aria2Fast.View.View.TaskListCellControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converter="clr-namespace:Aria2Fast.View.Contver" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" xmlns:local="clr-namespace:Aria2Fast.View.View" @@ -11,20 +10,6 @@ d:DesignWidth="300" mc:Ignorable="d"> - - - - - - - - - - - - - - @@ -86,6 +71,9 @@ MinWidth="40" Background="{Binding Data.Status, Converter={StaticResource DownloadStatusBrushContver}}" CornerRadius="4"> + + + + + + + + + + + + + + + + + + + + + + + +