Skip to content

Commit

Permalink
任务列表增加错误原因显示
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Apr 1, 2024
1 parent 03d5ed2 commit 70c2c89
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 62 deletions.
22 changes: 22 additions & 0 deletions Aria2Fast/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -29,6 +30,27 @@
<FontFamily x:Key="DFontFamily">Microsoft Yahei UI,Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>


<converter:DownloadSizeContver x:Key="DownloadSizeContver" />
<converter:DownloadStatusContver x:Key="DownloadStatusContver" />
<converter:DownloadProgressContver x:Key="DownloadProgressContver" />
<converter:DownloadProgressVisibilityConverter x:Key="DownloadProgressVisibilityConverter" />
<converter:DownloadSpeedVisibilityConverter x:Key="DownloadSpeedVisibilityConverter" />
<converter:DownloadStatusBrushContver x:Key="DownloadStatusBrushContver" />
<converter:ExistVisibilityConverter x:Key="ExistVisibilityConverter" />

<converter:DownloadSizeToProgressConverter x:Key="DownloadSizeToProgressConverter" />
<converter:DownloadStatusFullContver x:Key="DownloadStatusFullContver" />

<converter:ErrorStatusEasyContver x:Key="ErrorStatusEasyContver" />
<converter:ErrorStatusEasyNeedShowContver x:Key="ErrorStatusEasyNeedShowContver" />



<converter:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
<converter:IntVisibilityConverter x:Key="IntVisibilityConverter" />
<converter:StringVisibilityConverter x:Key="StringVisibilityConverter" />
</ResourceDictionary>


</Application.Resources>
</Application>
60 changes: 56 additions & 4 deletions Aria2Fast/Service/Model/TaskModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public string SubscriptionName
}
}



/// <summary>
/// 根据错误的类型来获取错误信息
/// </summary>
Expand All @@ -107,7 +109,7 @@ public string ErrorMessage
string message = Data.ErrorCode switch
{
null => "未知错误",
"0" => "所有下载成功",
"0" => "所有下载成功", //没有问题
"1" => "未知错误",
"2" => "超时",
"3" => "资源未找到",
Expand All @@ -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错误",
Expand Down Expand Up @@ -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
Expand Down
78 changes: 35 additions & 43 deletions Aria2Fast/View/Contver/DownloadSizeContver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions Aria2Fast/View/Contver/VisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
55 changes: 40 additions & 15 deletions Aria2Fast/View/View/TaskListCellControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -11,20 +10,6 @@
d:DesignWidth="300"
mc:Ignorable="d">

<UserControl.Resources>
<converter:DownloadSizeContver x:Key="DownloadSizeContver" />
<converter:DownloadStatusContver x:Key="DownloadStatusContver" />
<converter:DownloadProgressContver x:Key="DownloadProgressContver" />
<converter:DownloadProgressVisibilityConverter x:Key="DownloadProgressVisibilityConverter" />
<converter:DownloadSpeedVisibilityConverter x:Key="DownloadSpeedVisibilityConverter" />
<converter:DownloadStatusBrushContver x:Key="DownloadStatusBrushContver" />
<converter:ExistVisibilityConverter x:Key="ExistVisibilityConverter" />
<converter:BoolVisibilityConverter x:Key="BoolVisibilityConverter" />
<converter:DownloadSizeToProgressConverter x:Key="DownloadSizeToProgressConverter" />
<converter:DownloadStatusFullContver x:Key="DownloadStatusFullContver" />


</UserControl.Resources>
<Grid>
<Border CornerRadius="4">
<Border.Style>
Expand Down Expand Up @@ -86,6 +71,9 @@
MinWidth="40"
Background="{Binding Data.Status, Converter={StaticResource DownloadStatusBrushContver}}"
CornerRadius="4">
<Border.ToolTip>
<TextBlock Text="{Binding ErrorMessage}" Visibility="{Binding ErrorMessage, Converter={StaticResource StringVisibilityConverter}}" />
</Border.ToolTip>
<TextBlock
Margin="4,0,4,0"
HorizontalAlignment="Center"
Expand All @@ -109,6 +97,43 @@
</TextBlock>
</Border>

<!-- 错误原因提示,目前仅支持重复下载 -->
<Border
Height="18"
MinWidth="40"
Margin="5,0,0,0"
Background="#DCDEE2"
CornerRadius="4">
<Border.Visibility>
<MultiBinding Converter="{StaticResource ErrorStatusEasyNeedShowContver}">
<Binding Path="ErrorMessageMin" />
<Binding Path="Data.ErrorCode" />
</MultiBinding>
</Border.Visibility>
<TextBlock
Margin="4,0,4,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#515A6E">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ErrorStatusEasyContver}">
<Binding Path="ErrorMessageMin" />
<Binding Path="Data.ErrorCode" />
</MultiBinding>
</TextBlock.Text>
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="#FFFFFF" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True">
<Setter Property="Foreground" Value="#FFFFFF" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>

<Border
Height="18"
MinWidth="40"
Expand Down

0 comments on commit 70c2c89

Please sign in to comment.