下载前检测无效的下载目录

croire 2 years ago
parent 0991019aba
commit 48624ff505

@ -131,19 +131,16 @@ namespace DownKyi
case Downloader.NOT_SET: case Downloader.NOT_SET:
break; break;
case Downloader.BUILT_IN: case Downloader.BUILT_IN:
downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService)));
break; break;
case Downloader.ARIA: case Downloader.ARIA:
downloadService = new AriaDownloadService(DownloadingList, DownloadedList, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService))); 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, (IDialogService)Container.GetContainer().GetService(typeof(IDialogService)));
break; break;
} }
if (downloadService != null) downloadService?.Start();
{
downloadService.Start();
}
return Container.Resolve<MainWindow>(); return Container.Resolve<MainWindow>();
} }

@ -326,6 +326,8 @@
<system:String x:Key="ConfirmDelete">您确定要删除吗?</system:String> <system:String x:Key="ConfirmDelete">您确定要删除吗?</system:String>
<system:String x:Key="SelectDirectory">请选择文件夹</system:String> <system:String x:Key="SelectDirectory">请选择文件夹</system:String>
<system:String x:Key="DirectoryError">路径错误!</system:String>
<!-- ViewDownloadSetter --> <!-- ViewDownloadSetter -->
<system:String x:Key="DownloadSetter">下载设置</system:String> <system:String x:Key="DownloadSetter">下载设置</system:String>
<system:String x:Key="Location">位置:</system:String> <system:String x:Key="Location">位置:</system:String>

@ -26,16 +26,13 @@ namespace DownKyi.Services.Download
/// </summary> /// </summary>
public class AriaDownloadService : DownloadService, IDownloadService public class AriaDownloadService : DownloadService, IDownloadService
{ {
private readonly IDialogService dialogService;
public AriaDownloadService( public AriaDownloadService(
ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList, ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService = null) : IDialogService dialogService) :
base(downloadingList, downloadedList) base(downloadingList, downloadedList, dialogService)
{ {
Tag = "AriaDownloadService"; Tag = "AriaDownloadService";
this.dialogService = dialogService;
} }
#region 音视频 #region 音视频
@ -345,7 +342,7 @@ namespace DownKyi.Services.Download
if (task) { Console.WriteLine("Start ServerAsync Completed"); } if (task) { Console.WriteLine("Start ServerAsync Completed"); }
// 显示错误信息 // 显示错误信息
if (dialogService != null && errorMessage != null && errorMessage.Contains("ERROR")) if (errorMessage != null && errorMessage.Contains("ERROR"))
{ {
AlertService alertService = new AlertService(dialogService); AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error, ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error,

@ -7,6 +7,7 @@ using DownKyi.Core.Utils;
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;
@ -19,7 +20,10 @@ namespace DownKyi.Services.Download
{ {
public class BuiltinDownloadService : DownloadService, IDownloadService public class BuiltinDownloadService : DownloadService, IDownloadService
{ {
public BuiltinDownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList) : base(downloadingList, downloadedList) public BuiltinDownloadService(ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService
) : base(downloadingList, downloadedList, dialogService)
{ {
Tag = "BuiltinDownloadService"; Tag = "BuiltinDownloadService";
} }

@ -9,6 +9,7 @@ using DownKyi.Core.Utils;
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;
@ -23,7 +24,10 @@ namespace DownKyi.Services.Download
/// </summary> /// </summary>
public class CustomAriaDownloadService : DownloadService, IDownloadService public class CustomAriaDownloadService : DownloadService, IDownloadService
{ {
public CustomAriaDownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList) : base(downloadingList, downloadedList) public CustomAriaDownloadService(ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService
) : base(downloadingList, downloadedList, dialogService)
{ {
Tag = "AriaDownloadService"; Tag = "AriaDownloadService";
} }

@ -11,6 +11,7 @@ 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;
@ -25,6 +26,8 @@ namespace DownKyi.Services.Download
{ {
protected string Tag = "DownloadService"; protected string Tag = "DownloadService";
protected IDialogService dialogService;
protected ObservableCollection<DownloadingItem> downloadingList; protected ObservableCollection<DownloadingItem> downloadingList;
protected ObservableCollection<DownloadedItem> downloadedList; protected ObservableCollection<DownloadedItem> downloadedList;
@ -41,10 +44,13 @@ namespace DownKyi.Services.Download
/// </summary> /// </summary>
/// <param name="downloading"></param> /// <param name="downloading"></param>
/// <returns></returns> /// <returns></returns>
public DownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList) public DownloadService(ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService)
{ {
this.downloadingList = downloadingList; this.downloadingList = downloadingList;
this.downloadedList = downloadedList; this.downloadedList = downloadedList;
this.dialogService = dialogService;
} }
protected PlayUrlDashVideo BaseDownloadAudio(DownloadingItem downloading) protected PlayUrlDashVideo BaseDownloadAudio(DownloadingItem downloading)
@ -437,9 +443,22 @@ namespace DownKyi.Services.Download
// 路径不存在则创建 // 路径不存在则创建
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{
try
{ {
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
catch (Exception e)
{
Core.Utils.Debugging.Console.PrintLine(Tag, e.ToString());
LogManager.Debug(Tag, e.Message);
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowError($"{path}{DictionaryResource.GetString("DirectoryError")}");
return;
}
}
try try
{ {

Loading…
Cancel
Save