完成下载中和下载完成列表的UI

croire 3 years ago
parent a95070ffae
commit ba1235669c

@ -65,7 +65,7 @@ namespace DownKyi.Core.Aria2cNet.Server
try
{
var stream = File.Open(logFile, FileMode.Open);
if (stream.Length >= 512 * 1024 * 1024L)
if (stream.Length >= 10 * 1024 * 1024L)
{
stream.SetLength(0);
}

@ -204,7 +204,7 @@ namespace DownKyi.Core.Danmaku2Ass
{
public TopDisplay(Config config, Danmaku danmaku) : base(config, danmaku)
{
Console.WriteLine("TopDisplay constructor.");
//Console.WriteLine("TopDisplay constructor.");
}
/// <summary>
@ -226,7 +226,7 @@ namespace DownKyi.Core.Danmaku2Ass
{
public BottomDisplay(Config config, Danmaku danmaku) : base(config, danmaku)
{
Console.WriteLine("BottomDisplay constructor.");
//Console.WriteLine("BottomDisplay constructor.");
}
/// <summary>
@ -253,7 +253,7 @@ namespace DownKyi.Core.Danmaku2Ass
public ScrollDisplay(Config config, Danmaku danmaku) : base()
{
Console.WriteLine("ScrollDisplay constructor.");
//Console.WriteLine("ScrollDisplay constructor.");
Config = config;
Danmaku = danmaku;

@ -49,16 +49,16 @@ namespace DownKyi.Core.Danmaku2Ass
public void ApplyFilter()
{
Dictionary<string, int> filterDetail = new Dictionary<string, int>() {
{ "top_filter",0},
{ "bottom_filter",0},
{ "scroll_filter",0},
{ "top_filter", 0},
{ "bottom_filter", 0},
{ "scroll_filter", 0},
//{ "custom_filter",0}
};
List<Danmaku> danmakus = Danmakus;
//string[] orders = { "top_filter", "bottom_filter", "scroll_filter", "custom_filter" };
string[] orders = { "top_filter", "bottom_filter", "scroll_filter" };
foreach (var name in orders)
foreach (string name in orders)
{
Filter filter;
try

@ -69,6 +69,17 @@
Fill = "#FF000000"
};
Trash = new VectorImage
{
Height = 20,
Width = 20,
Data = @"M683 85 q0 -27 -20.5 -55 q-20.5 -28 -65.5 -30 l-170 0 q-39 1 -62 23.5 q-23 22.5 -24 61.5 l-341 0 l0 86 l1024 0 l0 -86
l-341 0 ZM341 256 l86 0 l0 597 l-86 0 l0 -597 ZM597 256 l86 0 l0 597 l-86 0 l0 -597 ZM853 853 q0 39 -23 62
q-23 23 -62 24 l-512 0 q-39 -1 -62 -24 q-23 -23 -23 -62 l0 -597 l-86 0 l0 597 q2 73 50.5 121 q48.5 48 120.5 50 l512 0
q72 -2 120.5 -50 q48.5 -48 50.5 -121 l0 -597 l-86 0 l0 597 Z",
Fill = "#FF000000"
};
Delete = new VectorImage
{
Height = 18,
@ -103,6 +114,30 @@
Fill = "#FF000000"
};
Retry = new VectorImage
{
Height = 20,
Width = 20,
Data = @"M536.69 128.65 q-161.14 5.2 -270.3 113.71 q-109.15 108.5 -113.05 269.64 q3.9 161.14 113.05 269.64
q109.16 108.5 270.3 113.71 q101.36 -1.3 185.82 -47.43 q84.47 -46.13 140.35 -129.3 q6.5 -14.3 22.09 -24.7
q15.6 -10.39 31.19 -10.39 q28.59 0 47.44 18.85 q18.84 18.85 20.14 48.74 q0 11.69 -5.2 20.79 q0 3.9 0 7.8 l-3.9 5.19
q-72.77 111.76 -185.82 174.78 q-113.06 63.03 -246.91 64.33 q-102.66 0 -196.22 -38.34 q-93.57 -38.33 -166.34 -111.11
q-72.77 -72.77 -111.1 -166.34 q-38.33 -93.56 -38.33 -196.22 q0 -102.66 38.33 -196.23 q38.34 -93.56 111.1 -166.33
q72.77 -72.77 166.34 -111.1 q93.56 -38.34 196.22 -38.34 q92.26 0 176.73 31.19 q84.47 31.19 152.04 89.66 l0 -25.99
q1.3 -27.29 18.2 -44.83 q16.89 -17.54 42.88 -17.54 q25.99 0 44.18 18.19 q18.19 18.19 18.19 44.18 l0 189.73
q0 24.69 -18.19 42.88 q-18.19 18.19 -42.88 18.19 l-191.03 0 q-24.69 0 -42.88 -18.19 q-18.2 -18.19 -18.2 -42.88
q0 -28.59 16.25 -47.43 q16.25 -18.84 44.84 -20.13 l37.69 0 q-51.98 -42.89 -114.36 -65.63 q-62.38 -22.74 -128.65 -22.74 Z",
Fill = "#FF000000"
};
Folder = new VectorImage
{
Height = 16,
Width = 20,
Data = @"M18,2H10L8,0H2A2,2,0,0,0,0,2V14a2,2,0,0,0,2,2H18a2,2,0,0,0,2-2V4A2,2,0,0,0,18,2Zm0,12H2V4H18Z",
Fill = "#FF000000"
};
}
public VectorImage GeneralSearch { get; private set; }
@ -110,9 +145,12 @@
public VectorImage DownloadManage { get; private set; }
public VectorImage Toolbox { get; private set; }
public VectorImage Trash { get; private set; }
public VectorImage Delete { get; private set; }
public VectorImage Start { get; private set; }
public VectorImage Pause { get; private set; }
public VectorImage Retry { get; private set; }
public VectorImage Folder { get; private set; }
}
}

@ -116,6 +116,13 @@
<system:String x:Key="DownloadedSortByOrder">按序号排序</system:String>
<system:String x:Key="ClearAllDownloaded">清空所有记录</system:String>
<system:String x:Key="StartDownload">开始</system:String>
<system:String x:Key="PauseDownload">暂停</system:String>
<system:String x:Key="RetryDownload">重试</system:String>
<system:String x:Key="DeleteDownload">移除</system:String>
<system:String x:Key="OpenFolder">打开文件夹</system:String>
<system:String x:Key="OpenVideo">播放</system:String>
<!-- Settings -->
<system:String x:Key="PressEnterToApplySettingTip">按回车键应用设置</system:String>

@ -11,6 +11,7 @@ using DownKyi.Core.Logging;
using DownKyi.Core.Settings;
using DownKyi.Core.Storage;
using DownKyi.Core.Utils;
using DownKyi.Images;
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
@ -145,7 +146,6 @@ namespace DownKyi.Services.Download
case DownloadResult.SUCCESS:
return Path.Combine(path, fileName);
case DownloadResult.FAILED:
return null;
case DownloadResult.ABORT:
return null;
default:
@ -395,6 +395,8 @@ namespace DownKyi.Services.Download
foreach (DownloadingItem item in downloadingList)
{
item.Downloading.DownloadStatus = DownloadStatus.WAIT_FOR_DOWNLOAD;
item.Progress = 0;
downloadStorageService.UpdateDownloading(item);
}
foreach (DownloadedItem item in downloadedList)
@ -494,6 +496,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
var isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
// 设置下载状态
downloading.Downloading.DownloadStatus = DownloadStatus.DOWNLOADING;
@ -507,6 +515,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
string videoUid = null;
// 如果需要下载视频
@ -517,6 +531,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
string outputDanmaku = null;
// 如果需要下载弹幕
@ -527,6 +547,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
List<string> outputSubtitles = null;
// 如果需要下载字幕
@ -537,6 +563,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
string outputCover = null;
// 如果需要下载封面
@ -552,6 +584,12 @@ namespace DownKyi.Services.Download
// 暂停
Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
// 混流
string outputMedia = string.Empty;
@ -561,9 +599,16 @@ namespace DownKyi.Services.Download
}
// 暂停
Pause(downloading);
//Pause(downloading);
// 是否存在
isExist = IsExist(downloading);
if (!isExist.Result)
{
return;
}
// 检测音频、视频是否下载成功
bool isMediaSuccess = true;
if (downloading.DownloadBase.NeedDownloadContent["downloadAudio"] || downloading.DownloadBase.NeedDownloadContent["downloadVideo"])
{
// 只有下载音频不下载视频时才输出aac
@ -571,16 +616,31 @@ namespace DownKyi.Services.Download
if (File.Exists(outputMedia))
{
// 成功
isMediaSuccess = true;
}
else
{
isMediaSuccess = false;
}
}
// 检测弹幕是否下载成功
if (downloading.DownloadBase.NeedDownloadContent["downloadDanmaku"] && File.Exists(outputDanmaku))
bool isDanmakuSuccess = true;
if (downloading.DownloadBase.NeedDownloadContent["downloadDanmaku"])
{
// 成功
if (File.Exists(outputDanmaku))
{
// 成功
isDanmakuSuccess = true;
}
else
{
isDanmakuSuccess = false;
}
}
// 检测字幕是否下载成功
bool isSubtitleSuccess = true;
if (downloading.DownloadBase.NeedDownloadContent["downloadSubtitle"])
{
if (outputSubtitles == null)
@ -591,25 +651,39 @@ namespace DownKyi.Services.Download
{
foreach (string subtitle in outputSubtitles)
{
if (File.Exists(subtitle))
if (!File.Exists(subtitle))
{
// 成功
// 如果有一个不存在则失败
isSubtitleSuccess = false;
}
}
}
}
// 检测封面是否下载成功
if (downloading.DownloadBase.NeedDownloadContent["downloadCover"] && File.Exists(outputCover))
bool isCover = true;
if (downloading.DownloadBase.NeedDownloadContent["downloadCover"])
{
// 成功
if (File.Exists(outputCover))
{
// 成功
isCover = true;
}
else
{
isCover = false;
}
}
if (!isMediaSuccess || !isDanmakuSuccess || !isSubtitleSuccess || !isCover)
{
downloading.Downloading.DownloadStatus = DownloadStatus.DOWNLOAD_FAILED;
downloading.StartOrPause = ButtonIcon.Instance().Retry;
downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary");
return;
}
// TODO
// 将下载结果写入数据库
// 包括下载请求的DownloadingItem对象
// 下载结果是否成功等
// 对是否成功的判断只要outputMedia存在则成功否则失败
// 下载完成后处理
Downloaded downloaded = new Downloaded
{
@ -690,6 +764,34 @@ namespace DownKyi.Services.Download
downloading.DownloadStatusTitle = oldStatus;
}
/// <summary>
/// 是否存在于下载列表中
/// </summary>
/// <param name="downloading"></param>
/// <returns></returns>
private async Task<bool> IsExist(DownloadingItem downloading)
{
bool isExist = downloadingList.Contains(downloading);
if (isExist)
{
return true;
}
else
{
// 先恢复为waiting状态暂停状态下Remove会导致文件重新下载原因暂不清楚
await AriaClient.UnpauseAsync(downloading.Downloading.Gid);
// 移除下载项
var ariaRemove = await AriaClient.RemoveAsync(downloading.Downloading.Gid);
if (ariaRemove == null || ariaRemove.Result == downloading.Downloading.Gid)
{
// 从内存中删除下载项
await AriaClient.RemoveDownloadResultAsync(downloading.Downloading.Gid);
}
return false;
}
}
/// <summary>
/// 启动Aria服务器
/// </summary>
@ -724,13 +826,6 @@ namespace DownKyi.Services.Download
var task = await AriaServer.StartServerAsync(config);
if (task) { Console.WriteLine("Start ServerAsync Completed"); }
Console.WriteLine("Start ServerAsync end");
// 恢复所有下载
//var ariaPause = await AriaClient.UnpauseAllAsync();
//if (ariaPause != null)
//{
// Core.Utils.Debugging.Console.PrintLine(ariaPause.ToString());
//}
}
/// <summary>

@ -14,6 +14,8 @@
<SolidColorBrush x:Key="BrushCloseBtnHover" Color="{DynamicResource ColorCloseBtnHover}" />
<SolidColorBrush x:Key="BrushCloseBtnPressed" Color="{DynamicResource ColorCloseBtnPressed}" />
<SolidColorBrush x:Key="BrushWarning" Color="{DynamicResource ColorWarning}" />
<SolidColorBrush x:Key="BrushPrimary" Color="{DynamicResource ColorPrimary}" />
<SolidColorBrush x:Key="BrushPrimaryTranslucent" Color="{DynamicResource ColorPrimaryTranslucent}" />
<SolidColorBrush x:Key="BrushPrimaryTranslucent2" Color="{DynamicResource ColorPrimaryTranslucent2}" />

@ -14,6 +14,8 @@
<Color x:Key="ColorCloseBtnHover">#FFE81123</Color>
<Color x:Key="ColorCloseBtnPressed">#FFF1707A</Color>
<Color x:Key="ColorWarning">#FFFF4D3C</Color>
<Color x:Key="ColorPrimary">#FF00A1D6</Color>
<Color x:Key="ColorPrimaryTranslucent">#C800A1D6</Color>
<Color x:Key="ColorPrimaryTranslucent2">#7F00A1D6</Color>

@ -1,5 +1,6 @@
using DownKyi.Images;
using DownKyi.Models;
using DownKyi.Utils;
using Prism.Commands;
using System.IO;
@ -9,6 +10,17 @@ namespace DownKyi.ViewModels.DownloadManager
{
public DownloadedItem() : base()
{
// 打开文件夹按钮
OpenFolder = ButtonIcon.Instance().Folder;
OpenFolder.Fill = DictionaryResource.GetColor("ColorPrimary");
// 打开视频按钮
OpenVideo = ButtonIcon.Instance().Start;
OpenVideo.Fill = DictionaryResource.GetColor("ColorPrimary");
// 删除按钮
RemoveVideo = ButtonIcon.Instance().Trash;
RemoveVideo.Fill = DictionaryResource.GetColor("ColorWarning");
}
// model数据
@ -73,9 +85,10 @@ namespace DownKyi.ViewModels.DownloadManager
private void ExecuteOpenFolderCommand()
{
string videoPath = $"{DownloadBase.FilePath}.mp4";
if (File.Exists(videoPath))
FileInfo fileInfo = new FileInfo(videoPath);
if (File.Exists(fileInfo.FullName))
{
System.Diagnostics.Process.Start("Explorer", "/select," + videoPath);
System.Diagnostics.Process.Start("Explorer", "/select," + fileInfo.FullName);
}
else
{
@ -93,9 +106,10 @@ namespace DownKyi.ViewModels.DownloadManager
private void ExecuteOpenVideoCommand()
{
string videoPath = $"{DownloadBase.FilePath}.mp4";
if (File.Exists(videoPath))
var fileInfo = new FileInfo(videoPath);
if (File.Exists(fileInfo.FullName))
{
System.Diagnostics.Process.Start(videoPath);
System.Diagnostics.Process.Start(fileInfo.FullName);
}
else
{

@ -80,6 +80,13 @@ namespace DownKyi.ViewModels.DownloadManager
}
}
// 操作提示
private string operationTip;
public string OperationTip
{
get => operationTip;
set => SetProperty(ref operationTip, value);
}
#region 控制按钮
@ -87,7 +94,14 @@ namespace DownKyi.ViewModels.DownloadManager
public VectorImage StartOrPause
{
get => startOrPause;
set => SetProperty(ref startOrPause, value);
set
{
SetProperty(ref startOrPause, value);
OperationTip = value.Equals(ButtonIcon.Instance().Start) ? DictionaryResource.GetString("StartDownload")
: value.Equals(ButtonIcon.Instance().Pause) ? DictionaryResource.GetString("PauseDownload")
: value.Equals(ButtonIcon.Instance().Retry) ? DictionaryResource.GetString("RetryDownload") : null;
}
}
private VectorImage delete;

@ -48,6 +48,9 @@ namespace DownKyi.ViewModels.DownloadManager
case 2:
App.SortDownloadedList(DownloadFinishedSort.NUMBER);
break;
default:
App.SortDownloadedList(DownloadFinishedSort.DOWNLOAD);
break;
}
}
@ -60,6 +63,7 @@ namespace DownKyi.ViewModels.DownloadManager
/// </summary>
private void ExecuteClearAllDownloadedCommand()
{
DownloadedList.Clear();
}
#endregion

@ -46,6 +46,8 @@ namespace DownKyi.ViewModels.DownloadManager
case DownloadStatus.NOT_STARTED:
case DownloadStatus.WAIT_FOR_DOWNLOAD:
downloading.Downloading.DownloadStatus = DownloadStatus.PAUSE_STARTED;
downloading.StartOrPause = ButtonIcon.Instance().Start;
downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary");
break;
case DownloadStatus.PAUSE_STARTED:
break;
@ -53,6 +55,8 @@ namespace DownKyi.ViewModels.DownloadManager
break;
case DownloadStatus.DOWNLOADING:
downloading.Downloading.DownloadStatus = DownloadStatus.PAUSE;
downloading.StartOrPause = ButtonIcon.Instance().Start;
downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary");
break;
case DownloadStatus.DOWNLOAD_SUCCEED:
// 下载成功后会从下载列表中删除
@ -63,9 +67,6 @@ namespace DownKyi.ViewModels.DownloadManager
default:
break;
}
downloading.StartOrPause = ButtonIcon.Instance().Start;
downloading.StartOrPause.Fill = DictionaryResource.GetColor("ColorPrimary");
}
}

@ -100,68 +100,56 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
<Button
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="{DynamicResource BrushBackground}"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding OpenFolderCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentControl>
Command="{Binding OpenFolderCommand}"
Style="{StaticResource ImageBtnStyle}"
ToolTip="{DynamicResource OpenFolder}">
<ContentControl Width="20" Height="20">
<Path
Width="{Binding OpenFolder.Width}"
Height="{Binding OpenFolder.Height}"
Data="{Binding OpenFolder.Data}"
Fill="{Binding OpenFolder.Fill}"
Stretch="UniformToFill" />
Stretch="Uniform" />
</ContentControl>
</Border>
</Button>
<Border
<Button
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="{DynamicResource BrushBackground}"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding OpenVideoCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentControl>
Command="{Binding OpenVideoCommand}"
Style="{StaticResource ImageBtnStyle}"
ToolTip="{DynamicResource OpenVideo}">
<ContentControl Width="20" Height="20">
<Path
Width="{Binding OpenVideo.Width}"
Height="{Binding OpenVideo.Height}"
Data="{Binding OpenVideo.Data}"
Fill="{Binding OpenVideo.Fill}"
Stretch="UniformToFill" />
Stretch="Uniform" />
</ContentControl>
</Border>
</Button>
<Border
<Button
Grid.Column="2"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="{DynamicResource BrushBackground}"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding RemoveVideoCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentControl>
Command="{Binding RemoveVideoCommand}"
Style="{StaticResource ImageBtnStyle}"
ToolTip="{DynamicResource DeleteDownload}">
<ContentControl Width="20" Height="20">
<Path
Width="{Binding RemoveVideo.Width}"
Height="{Binding RemoveVideo.Height}"
Data="{Binding RemoveVideo.Data}"
Fill="{Binding RemoveVideo.Fill}"
Stretch="UniformToFill" />
Stretch="Uniform" />
</ContentControl>
</Border>
</Button>
</Grid>
</Grid>

@ -160,47 +160,39 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
<Button
Grid.Column="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="{DynamicResource BrushBackground}"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding StartOrPauseCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentControl>
Command="{Binding StartOrPauseCommand}"
Style="{StaticResource ImageBtnStyle}"
ToolTip="{Binding OperationTip}">
<ContentControl Width="20" Height="20">
<Path
Width="{Binding StartOrPause.Width}"
Height="{Binding StartOrPause.Height}"
Data="{Binding StartOrPause.Data}"
Fill="{Binding StartOrPause.Fill}"
Stretch="UniformToFill" />
Stretch="Uniform" />
</ContentControl>
</Border>
</Button>
<Border
<Button
Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Background="{DynamicResource BrushBackground}"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding DeleteCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ContentControl>
Command="{Binding DeleteCommand}"
Style="{StaticResource ImageBtnStyle}"
ToolTip="{DynamicResource DeleteDownload}">
<ContentControl Width="20" Height="20">
<Path
Width="{Binding Delete.Width}"
Height="{Binding Delete.Height}"
Data="{Binding Delete.Data}"
Fill="{Binding Delete.Fill}"
Stretch="UniformToFill" />
Stretch="Uniform" />
</ContentControl>
</Border>
</Button>
</Grid>
</Grid>

Loading…
Cancel
Save