diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index cd38faf..bfad80b 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -63,7 +63,7 @@ namespace DownKyi containerRegistry.RegisterForNavigation(ViewExtractMediaViewModel.Tag); // dialogs - containerRegistry.RegisterDialog(ViewDirectorySelectorViewModel.Tag); + containerRegistry.RegisterDialog(ViewDownloadSetterViewModel.Tag); containerRegistry.RegisterDialog(ViewParsingSelectorViewModel.Tag); } diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index cf0d869..3972b01 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -105,7 +105,7 @@ - + @@ -127,8 +127,8 @@ - - ViewDirectorySelector.xaml + + ViewDownloadSetter.xaml ViewParsingSelector.xaml @@ -254,7 +254,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index 5ff0b24..c635e25 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -177,15 +177,21 @@ 取消 请选择文件夹 - - 设置下载文件夹 + + 下载设置 位置: 浏览 盘剩余空间: + 下载内容: + 所有 + 音频 + 视频 + 弹幕 + 字幕 + 封面 设此文件夹为默认下载文件夹 选中后下次将不会弹出此窗口 下载 - 文件夹路径不能为空 diff --git a/DownKyi/ViewModels/Dialogs/ViewDirectorySelectorViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewDirectorySelectorViewModel.cs deleted file mode 100644 index 8c9643d..0000000 --- a/DownKyi/ViewModels/Dialogs/ViewDirectorySelectorViewModel.cs +++ /dev/null @@ -1,203 +0,0 @@ -using DownKyi.Core.Settings; -using DownKyi.Core.Utils; -using DownKyi.Events; -using DownKyi.Images; -using DownKyi.Utils; -using Prism.Commands; -using Prism.Events; -using Prism.Services.Dialogs; -using System.Collections.Generic; - -namespace DownKyi.ViewModels.Dialogs -{ - public class ViewDirectorySelectorViewModel : BaseDialogViewModel - { - public const string Tag = "DialogDirectorySelector"; - private readonly IEventAggregator eventAggregator; - - // 历史文件夹的数量 - private readonly int maxDirectoryListCount = 20; - - #region 页面属性申明 - - private VectorImage cloudDownloadIcon; - public VectorImage CloudDownloadIcon - { - get { return cloudDownloadIcon; } - set { SetProperty(ref cloudDownloadIcon, value); } - } - - private VectorImage folderIcon; - public VectorImage FolderIcon - { - get { return folderIcon; } - set { SetProperty(ref folderIcon, value); } - } - - private bool isDefaultDownloadDirectory; - public bool IsDefaultDownloadDirectory - { - get { return isDefaultDownloadDirectory; } - set { SetProperty(ref isDefaultDownloadDirectory, value); } - } - - private List directoryList; - public List DirectoryList - { - get { return directoryList; } - set { SetProperty(ref directoryList, value); } - } - - private string directory; - public string Directory - { - get { return directory; } - set - { - SetProperty(ref directory, value); - - DriveName = directory.Substring(0, 1).ToUpper(); - DriveNameFreeSpace = Format.FormatFileSize(HardDisk.GetHardDiskFreeSpace(DriveName)); - } - } - - private string driveName; - public string DriveName - { - get { return driveName; } - set { SetProperty(ref driveName, value); } - } - - private string driveNameFreeSpace; - public string DriveNameFreeSpace - { - get { return driveNameFreeSpace; } - set { SetProperty(ref driveNameFreeSpace, value); } - } - - #endregion - - public ViewDirectorySelectorViewModel(IEventAggregator eventAggregator) - { - this.eventAggregator = eventAggregator; - - #region 属性初始化 - - Title = DictionaryResource.GetString("DownloadDirectorySelector"); - - CloudDownloadIcon = NormalIcon.Instance().CloudDownload; - CloudDownloadIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); - - FolderIcon = NormalIcon.Instance().Folder; - FolderIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); - - #endregion - - // 历史下载目录 - DirectoryList = SettingsManager.GetInstance().GetHistoryVideoRootPaths(); - string directory = SettingsManager.GetInstance().GetSaveVideoRootPath(); - if (!DirectoryList.Contains(directory)) - { - ListHelper.InsertUnique(DirectoryList, directory, 0); - } - Directory = directory; - - // 是否使用默认下载目录 - IsDefaultDownloadDirectory = SettingsManager.GetInstance().IsUseSaveVideoRootPath() == AllowStatus.YES; - } - - #region 命令申明 - - // 浏览文件夹事件 - private DelegateCommand browseCommand; - public DelegateCommand BrowseCommand => browseCommand ?? (browseCommand = new DelegateCommand(ExecuteBrowseCommand)); - - /// - /// 浏览文件夹事件 - /// - private void ExecuteBrowseCommand() - { - string directory = SetDirectory(); - - if (directory == null) - { - eventAggregator.GetEvent().Publish(DictionaryResource.GetString("WarningNullDirectory")); - Directory = string.Empty; - } - else - { - ListHelper.InsertUnique(DirectoryList, directory, 0); - Directory = directory; - - if (DirectoryList.Count > maxDirectoryListCount) - { - DirectoryList.RemoveAt(maxDirectoryListCount); - } - } - } - - // 确认下载事件 - private DelegateCommand downloadCommand; - public DelegateCommand DownloadCommand => downloadCommand ?? (downloadCommand = new DelegateCommand(ExecuteDownloadCommand)); - - /// - /// 确认下载事件 - /// - private void ExecuteDownloadCommand() - { - if (Directory == null || Directory == string.Empty) - { - return; - } - - // 设此文件夹为默认下载文件夹 - if (IsDefaultDownloadDirectory) - { - SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.YES); - } - else - { - SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.NO); - } - - // 将Directory移动到第一项 - // 如果直接在ComboBox中选择的就需要 - // 否则选中项不会在下次出现在第一项 - ListHelper.InsertUnique(DirectoryList, Directory, 0); - - // 将更新后的DirectoryList写入历史中 - SettingsManager.GetInstance().SetSaveVideoRootPath(Directory); - SettingsManager.GetInstance().SetHistoryVideoRootPaths(DirectoryList); - - ButtonResult result = ButtonResult.OK; - IDialogParameters parameters = new DialogParameters - { - { "directory", Directory } - }; - - RaiseRequestClose(new DialogResult(result, parameters)); - } - - #endregion - - /// - /// 设置下载路径 - /// - /// - private string SetDirectory() - { - // 下载目录 - string path; - - // 弹出选择下载目录的窗口 - path = DialogUtils.SetDownloadDirectory(); - if (path == null || path == "") - { - return null; - } - - return path; - } - - } -} diff --git a/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs b/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs new file mode 100644 index 0000000..6603ec7 --- /dev/null +++ b/DownKyi/ViewModels/Dialogs/ViewDownloadSetterViewModel.cs @@ -0,0 +1,393 @@ +using DownKyi.Core.Settings; +using DownKyi.Core.Utils; +using DownKyi.Events; +using DownKyi.Images; +using DownKyi.Utils; +using Prism.Commands; +using Prism.Events; +using Prism.Services.Dialogs; +using System.Collections.Generic; + +namespace DownKyi.ViewModels.Dialogs +{ + public class ViewDownloadSetterViewModel : BaseDialogViewModel + { + public const string Tag = "DialogDownloadSetter"; + private readonly IEventAggregator eventAggregator; + + // 历史文件夹的数量 + private readonly int maxDirectoryListCount = 20; + + #region 页面属性申明 + + private VectorImage cloudDownloadIcon; + public VectorImage CloudDownloadIcon + { + get { return cloudDownloadIcon; } + set { SetProperty(ref cloudDownloadIcon, value); } + } + + private VectorImage folderIcon; + public VectorImage FolderIcon + { + get { return folderIcon; } + set { SetProperty(ref folderIcon, value); } + } + + private bool isDefaultDownloadDirectory; + public bool IsDefaultDownloadDirectory + { + get { return isDefaultDownloadDirectory; } + set { SetProperty(ref isDefaultDownloadDirectory, value); } + } + + private List directoryList; + public List DirectoryList + { + get { return directoryList; } + set { SetProperty(ref directoryList, value); } + } + + private string directory; + public string Directory + { + get { return directory; } + set + { + SetProperty(ref directory, value); + + if (directory != string.Empty) + { + DriveName = directory.Substring(0, 1).ToUpper(); + DriveNameFreeSpace = Format.FormatFileSize(HardDisk.GetHardDiskFreeSpace(DriveName)); + } + } + } + + private string driveName; + public string DriveName + { + get { return driveName; } + set { SetProperty(ref driveName, value); } + } + + private string driveNameFreeSpace; + public string DriveNameFreeSpace + { + get { return driveNameFreeSpace; } + set { SetProperty(ref driveNameFreeSpace, value); } + } + + private bool downloadAll; + public bool DownloadAll + { + get { return downloadAll; } + set { SetProperty(ref downloadAll, value); } + } + + private bool downloadAudio; + public bool DownloadAudio + { + get { return downloadAudio; } + set { SetProperty(ref downloadAudio, value); } + } + + private bool downloadVideo; + public bool DownloadVideo + { + get { return downloadVideo; } + set { SetProperty(ref downloadVideo, value); } + } + + private bool downloadDanmaku; + public bool DownloadDanmaku + { + get { return downloadDanmaku; } + set { SetProperty(ref downloadDanmaku, value); } + } + + private bool downloadSubtitle; + public bool DownloadSubtitle + { + get { return downloadSubtitle; } + set { SetProperty(ref downloadSubtitle, value); } + } + + private bool downloadCover; + public bool DownloadCover + { + get { return downloadCover; } + set { SetProperty(ref downloadCover, value); } + } + + #endregion + + public ViewDownloadSetterViewModel(IEventAggregator eventAggregator) + { + this.eventAggregator = eventAggregator; + + #region 属性初始化 + + Title = DictionaryResource.GetString("DownloadSetter"); + + CloudDownloadIcon = NormalIcon.Instance().CloudDownload; + CloudDownloadIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); + + FolderIcon = NormalIcon.Instance().Folder; + FolderIcon.Fill = DictionaryResource.GetColor("ColorPrimary"); + + DownloadAll = true; + DownloadAudio = true; + DownloadVideo = true; + DownloadDanmaku = true; + DownloadSubtitle = true; + DownloadCover = true; + + #endregion + + // 历史下载目录 + DirectoryList = SettingsManager.GetInstance().GetHistoryVideoRootPaths(); + string directory = SettingsManager.GetInstance().GetSaveVideoRootPath(); + if (!DirectoryList.Contains(directory)) + { + ListHelper.InsertUnique(DirectoryList, directory, 0); + } + Directory = directory; + + // 是否使用默认下载目录 + IsDefaultDownloadDirectory = SettingsManager.GetInstance().IsUseSaveVideoRootPath() == AllowStatus.YES; + } + + #region 命令申明 + + // 浏览文件夹事件 + private DelegateCommand browseCommand; + public DelegateCommand BrowseCommand => browseCommand ?? (browseCommand = new DelegateCommand(ExecuteBrowseCommand)); + + /// + /// 浏览文件夹事件 + /// + private void ExecuteBrowseCommand() + { + string directory = SetDirectory(); + + if (directory == null) + { + eventAggregator.GetEvent().Publish(DictionaryResource.GetString("WarningNullDirectory")); + Directory = string.Empty; + } + else + { + ListHelper.InsertUnique(DirectoryList, directory, 0); + Directory = directory; + + if (DirectoryList.Count > maxDirectoryListCount) + { + DirectoryList.RemoveAt(maxDirectoryListCount); + } + } + } + + // 所有内容选择事件 + private DelegateCommand downloadAllCommand; + public DelegateCommand DownloadAllCommand => downloadAllCommand ?? (downloadAllCommand = new DelegateCommand(ExecuteDownloadAllCommand)); + + /// + /// 所有内容选择事件 + /// + private void ExecuteDownloadAllCommand() + { + if (DownloadAll) + { + DownloadAudio = true; + DownloadVideo = true; + DownloadDanmaku = true; + DownloadSubtitle = true; + DownloadCover = true; + } + else + { + DownloadAudio = false; + DownloadVideo = false; + DownloadDanmaku = false; + DownloadSubtitle = false; + DownloadCover = false; + } + } + + // 音频选择事件 + private DelegateCommand downloadAudioCommand; + public DelegateCommand DownloadAudioCommand => downloadAudioCommand ?? (downloadAudioCommand = new DelegateCommand(ExecuteDownloadAudioCommand)); + + /// + /// 音频选择事件 + /// + private void ExecuteDownloadAudioCommand() + { + if (!DownloadAudio) + { + DownloadAll = false; + return; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + } + + // 视频选择事件 + private DelegateCommand downloadVideoCommand; + public DelegateCommand DownloadVideoCommand => downloadVideoCommand ?? (downloadVideoCommand = new DelegateCommand(ExecuteDownloadVideoCommand)); + + /// + /// 视频选择事件 + /// + private void ExecuteDownloadVideoCommand() + { + if (!DownloadVideo) + { + DownloadAll = false; + return; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + } + + // 弹幕选择事件 + private DelegateCommand downloadDanmakuCommand; + public DelegateCommand DownloadDanmakuCommand => downloadDanmakuCommand ?? (downloadDanmakuCommand = new DelegateCommand(ExecuteDownloadDanmakuCommand)); + + /// + /// 弹幕选择事件 + /// + private void ExecuteDownloadDanmakuCommand() + { + if (!DownloadDanmaku) + { + DownloadAll = false; + return; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + } + + // 字幕选择事件 + private DelegateCommand downloadSubtitleCommand; + public DelegateCommand DownloadSubtitleCommand => downloadSubtitleCommand ?? (downloadSubtitleCommand = new DelegateCommand(ExecuteDownloadSubtitleCommand)); + + /// + /// 字幕选择事件 + /// + private void ExecuteDownloadSubtitleCommand() + { + if (!DownloadSubtitle) + { + DownloadAll = false; + return; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + } + + // 封面选择事件 + private DelegateCommand downloadCoverCommand; + public DelegateCommand DownloadCoverCommand => downloadCoverCommand ?? (downloadCoverCommand = new DelegateCommand(ExecuteDownloadCoverCommand)); + + /// + /// 封面选择事件 + /// + private void ExecuteDownloadCoverCommand() + { + if (!DownloadCover) + { + DownloadAll = false; + return; + } + + if (DownloadAudio && DownloadVideo && DownloadDanmaku && DownloadSubtitle && DownloadCover) + { + DownloadAll = true; + } + } + + // 确认下载事件 + private DelegateCommand downloadCommand; + public DelegateCommand DownloadCommand => downloadCommand ?? (downloadCommand = new DelegateCommand(ExecuteDownloadCommand)); + + /// + /// 确认下载事件 + /// + private void ExecuteDownloadCommand() + { + if (Directory == null || Directory == string.Empty) + { + return; + } + + // 设此文件夹为默认下载文件夹 + if (IsDefaultDownloadDirectory) + { + SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.YES); + } + else + { + SettingsManager.GetInstance().IsUseSaveVideoRootPath(AllowStatus.NO); + } + + // 将Directory移动到第一项 + // 如果直接在ComboBox中选择的就需要 + // 否则选中项不会在下次出现在第一项 + ListHelper.InsertUnique(DirectoryList, Directory, 0); + + // 将更新后的DirectoryList写入历史中 + SettingsManager.GetInstance().SetSaveVideoRootPath(Directory); + SettingsManager.GetInstance().SetHistoryVideoRootPaths(DirectoryList); + + // 返回数据 + ButtonResult result = ButtonResult.OK; + IDialogParameters parameters = new DialogParameters + { + { "directory", Directory }, + { "downloadAudio", DownloadAudio }, + { "downloadVideo", DownloadVideo }, + { "downloadDanmaku", DownloadDanmaku }, + { "downloadSubtitle", DownloadSubtitle }, + { "downloadCover", DownloadCover } + }; + + RaiseRequestClose(new DialogResult(result, parameters)); + } + + #endregion + + /// + /// 设置下载路径 + /// + /// + private string SetDirectory() + { + // 下载目录 + string path; + + // 弹出选择下载目录的窗口 + path = DialogUtils.SetDownloadDirectory(); + if (path == null || path == "") + { + return null; + } + + return path; + } + + } +} diff --git a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index 2eb6d7b..daf3174 100644 --- a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -492,6 +492,13 @@ namespace DownKyi.ViewModels // 选择的下载文件夹 string directory = string.Empty; + // 下载内容 + bool downloadAudio = true; + bool downloadVideo = true; + bool downloadDanmaku = true; + bool downloadSubtitle = true; + bool downloadCover = true; + // 是否使用默认下载目录 if (SettingsManager.GetInstance().IsUseSaveVideoRootPath() == AllowStatus.YES) { @@ -500,24 +507,36 @@ namespace DownKyi.ViewModels else { // 打开文件夹选择器 - dialogService.ShowDialog(ViewDirectorySelectorViewModel.Tag, null, result => + dialogService.ShowDialog(ViewDownloadSetterViewModel.Tag, null, result => { if (result.Result == ButtonResult.OK) { // 选择的下载文件夹 directory = result.Parameters.GetValue("directory"); + // 下载内容 + downloadAudio = result.Parameters.GetValue("downloadAudio"); + downloadVideo = result.Parameters.GetValue("downloadVideo"); + downloadDanmaku = result.Parameters.GetValue("downloadDanmaku"); + downloadSubtitle = result.Parameters.GetValue("downloadSubtitle"); + downloadCover = result.Parameters.GetValue("downloadCover"); + // 文件夹不存在则创建 if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } - - // 添加到下载 - eventAggregator.GetEvent().Publish(directory); } }); } + + // 下载设置dialog中如果点击取消或者关闭窗口, + // 会返回空字符串, + // 这时直接退出 + if (directory == string.Empty) { return; } + + // 添加到下载 + eventAggregator.GetEvent().Publish(directory); } /// diff --git a/DownKyi/Views/Dialogs/ViewDirectorySelector.xaml b/DownKyi/Views/Dialogs/ViewDownloadSetter.xaml similarity index 72% rename from DownKyi/Views/Dialogs/ViewDirectorySelector.xaml rename to DownKyi/Views/Dialogs/ViewDownloadSetter.xaml index d02e900..0320c5a 100644 --- a/DownKyi/Views/Dialogs/ViewDirectorySelector.xaml +++ b/DownKyi/Views/Dialogs/ViewDownloadSetter.xaml @@ -1,5 +1,5 @@  + @@ -195,6 +196,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DownKyi/Views/Dialogs/ViewDirectorySelector.xaml.cs b/DownKyi/Views/Dialogs/ViewDownloadSetter.xaml.cs similarity index 53% rename from DownKyi/Views/Dialogs/ViewDirectorySelector.xaml.cs rename to DownKyi/Views/Dialogs/ViewDownloadSetter.xaml.cs index 8c2588b..8a39337 100644 --- a/DownKyi/Views/Dialogs/ViewDirectorySelector.xaml.cs +++ b/DownKyi/Views/Dialogs/ViewDownloadSetter.xaml.cs @@ -3,11 +3,11 @@ namespace DownKyi.Views.Dialogs { /// - /// Interaction logic for ViewDirectorySelector + /// Interaction logic for ViewDownloadSetter /// - public partial class ViewDirectorySelector : UserControl + public partial class ViewDownloadSetter : UserControl { - public ViewDirectorySelector() + public ViewDownloadSetter() { InitializeComponent(); }