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

pull/671/head
leiurayer 1 year ago
parent d36a2b06e2
commit 683159b87b

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

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

@ -26,16 +26,13 @@ namespace DownKyi.Services.Download
/// </summary>
public class AriaDownloadService : DownloadService, IDownloadService
{
private readonly IDialogService dialogService;
public AriaDownloadService(
ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService = null) :
base(downloadingList, downloadedList)
IDialogService dialogService) :
base(downloadingList, downloadedList, dialogService)
{
Tag = "AriaDownloadService";
this.dialogService = dialogService;
}
#region 音视频
@ -345,7 +342,7 @@ namespace DownKyi.Services.Download
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);
ButtonResult result = alertService.ShowMessage(SystemIcon.Instance().Error,

@ -7,6 +7,7 @@ using DownKyi.Core.Utils;
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -19,7 +20,10 @@ namespace DownKyi.Services.Download
{
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";
}

@ -9,6 +9,7 @@ using DownKyi.Core.Utils;
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -23,7 +24,10 @@ namespace DownKyi.Services.Download
/// </summary>
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";
}

@ -11,6 +11,7 @@ using DownKyi.Images;
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -25,6 +26,8 @@ namespace DownKyi.Services.Download
{
protected string Tag = "DownloadService";
protected IDialogService dialogService;
protected ObservableCollection<DownloadingItem> downloadingList;
protected ObservableCollection<DownloadedItem> downloadedList;
@ -41,10 +44,13 @@ namespace DownKyi.Services.Download
/// </summary>
/// <param name="downloading"></param>
/// <returns></returns>
public DownloadService(ObservableCollection<DownloadingItem> downloadingList, ObservableCollection<DownloadedItem> downloadedList)
public DownloadService(ObservableCollection<DownloadingItem> downloadingList,
ObservableCollection<DownloadedItem> downloadedList,
IDialogService dialogService)
{
this.downloadingList = downloadingList;
this.downloadedList = downloadedList;
this.dialogService = dialogService;
}
protected PlayUrlDashVideo BaseDownloadAudio(DownloadingItem downloading)
@ -438,7 +444,20 @@ namespace DownKyi.Services.Download
// 路径不存在则创建
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
try
{
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

Loading…
Cancel
Save