Skip to content

Commit

Permalink
下载前检测无效的下载目录 leiurayer#574
Browse files Browse the repository at this point in the history
  • Loading branch information
leiurayer committed Feb 13, 2023
1 parent d36a2b0 commit 683159b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/DownKyi/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,16 @@ await Task.Run(() =>
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>();
}
Expand Down
2 changes: 2 additions & 0 deletions src/DownKyi/Languages/Default.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
9 changes: 3 additions & 6 deletions src/DownKyi/Services/Download/AriaDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 音视频
Expand Down Expand Up @@ -345,7 +342,7 @@ private async void StartAriaServer()
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,
Expand Down
6 changes: 5 additions & 1 deletion src/DownKyi/Services/Download/BuiltinDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -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";
}
Expand Down
6 changes: 5 additions & 1 deletion src/DownKyi/Services/Download/CustomAriaDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -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";
}
Expand Down
23 changes: 21 additions & 2 deletions src/DownKyi/Services/Download/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using DownKyi.Models;
using DownKyi.Utils;
using DownKyi.ViewModels.DownloadManager;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -25,6 +26,8 @@ public abstract class DownloadService
{
protected string Tag = "DownloadService";

protected IDialogService dialogService;

protected ObservableCollection<DownloadingItem> downloadingList;
protected ObservableCollection<DownloadedItem> downloadedList;

Expand All @@ -41,10 +44,13 @@ public abstract class DownloadService
/// </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)
Expand Down Expand Up @@ -438,7 +444,20 @@ private async Task SingleDownload(DownloadingItem downloading)
// 路径不存在则创建
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
Expand Down

0 comments on commit 683159b

Please sign in to comment.