diff --git a/DownKyi.Core/Settings/Models/BasicSettings.cs b/DownKyi.Core/Settings/Models/BasicSettings.cs index 2089888..21fde70 100644 --- a/DownKyi.Core/Settings/Models/BasicSettings.cs +++ b/DownKyi.Core/Settings/Models/BasicSettings.cs @@ -12,4 +12,5 @@ public class BasicSettings public AllowStatus IsAutoDownloadAll { get; set; } = AllowStatus.NONE; public DownloadFinishedSort DownloadFinishedSort { get; set; } = DownloadFinishedSort.NOT_SET; public RepeatDownloadStrategy RepeatDownloadStrategy { get; set; } = RepeatDownloadStrategy.Ask; + public bool RepeatFileAutoAddNumberSuffix { get; set; } = false; } \ No newline at end of file diff --git a/DownKyi.Core/Settings/SettingsManager.Basic.cs b/DownKyi.Core/Settings/SettingsManager.Basic.cs index d6de598..ca57569 100644 --- a/DownKyi.Core/Settings/SettingsManager.Basic.cs +++ b/DownKyi.Core/Settings/SettingsManager.Basic.cs @@ -19,10 +19,13 @@ public partial class SettingsManager // 下载完成列表排序 private readonly DownloadFinishedSort _finishedSort = DownloadFinishedSort.DOWNLOAD; - + // 重复下载策略 private readonly RepeatDownloadStrategy _repeatDownloadStrategy = RepeatDownloadStrategy.Ask; + // 重复文件自动添加数字后缀 + private readonly bool _repeatFileAutoAddNumberSuffix = false; + /// /// 获取下载完成后的操作 /// @@ -190,7 +193,7 @@ public partial class SettingsManager appSettings.Basic.DownloadFinishedSort = finishedSort; return SetSettings(); } - + /// /// 获取重复下载策略 /// @@ -218,4 +221,33 @@ public partial class SettingsManager appSettings.Basic.RepeatDownloadStrategy = repeatDownloadStrategy; return SetSettings(); } + + /// + /// 重复文件自动添加数字后缀 + /// + /// + public bool IsRepeatFileAutoAddNumberSuffix() + { + appSettings = GetSettings(); + if (appSettings.Basic.RepeatFileAutoAddNumberSuffix == false) + { + // 第一次获取,先设置默认值 + IsRepeatFileAutoAddNumberSuffix(_repeatFileAutoAddNumberSuffix); + return _repeatFileAutoAddNumberSuffix; + } + + return appSettings.Basic.RepeatFileAutoAddNumberSuffix; + } + + /// + /// 设置重复文件自动添加数字后缀 + /// + /// + /// + /// + public bool IsRepeatFileAutoAddNumberSuffix(bool repeatFileAutoAddNumberSuffix) + { + appSettings.Basic.RepeatFileAutoAddNumberSuffix = repeatFileAutoAddNumberSuffix; + return SetSettings(); + } } \ No newline at end of file diff --git a/DownKyi.Core/Utils/Format.cs b/DownKyi.Core/Utils/Format.cs index dacf6f3..76cfae6 100644 --- a/DownKyi.Core/Utils/Format.cs +++ b/DownKyi.Core/Utils/Format.cs @@ -211,6 +211,6 @@ public static class Format destName = destName.Trim('.'); // 如果只有空白字符、dot符 - return destName is "" or "." ? "[empty title]" : destName; + return destName is " " or "." ? "[empty title]" : destName; } } \ No newline at end of file diff --git a/DownKyi/Languanges/Default.axaml b/DownKyi/Languanges/Default.axaml index 298a6a1..16cf372 100644 --- a/DownKyi/Languanges/Default.axaml +++ b/DownKyi/Languanges/Default.axaml @@ -183,6 +183,7 @@ 每次询问 重新下载 跳过重复项 + 重复文件自动添加数字序号后缀 解析后自动下载已解析视频 网络 启用https(若下载器提示SSL错误,则关闭此项) diff --git a/DownKyi/Services/Download/AddToDownloadService.cs b/DownKyi/Services/Download/AddToDownloadService.cs index 27c41d4..6042a4f 100644 --- a/DownKyi/Services/Download/AddToDownloadService.cs +++ b/DownKyi/Services/Download/AddToDownloadService.cs @@ -445,6 +445,27 @@ public class AddToDownloadService // 合成绝对路径 var filePath = Path.Combine(directory, fileName.RelativePath()); + if (SettingsManager.GetInstance().IsRepeatFileAutoAddNumberSuffix()) + { + // 如果存在同名文件,自动重命名 + // todo 如果重新下载呢。还没想好 + var directoryName = Path.GetDirectoryName(filePath); + var files = Directory.GetFiles(directoryName).Select(Path.GetFileNameWithoutExtension).Distinct().ToList(); + + if (files.Contains(Path.GetFileNameWithoutExtension(filePath))) + { + var count = 1; + var newFilePath = filePath; + while (files.Contains(Path.GetFileNameWithoutExtension(newFilePath))) + { + newFilePath = Path.Combine(directory, $"{fileName.RelativePath()}({count})"); + count++; + } + + filePath = newFilePath; + } + } + // 视频类别 PlayStreamType playStreamType; switch (_videoInfoView.TypeId) diff --git a/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs b/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs index 39927c2..ea92018 100644 --- a/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewBasicViewModel.cs @@ -81,6 +81,14 @@ public class ViewBasicViewModel : ViewModelBase get => _autoDownloadAll; set => SetProperty(ref _autoDownloadAll, value); } + + private bool _repeatFileAutoAddNumberSuffix; + + public bool RepeatFileAutoAddNumberSuffix + { + get => _repeatFileAutoAddNumberSuffix; + set => SetProperty(ref _repeatFileAutoAddNumberSuffix, value); + } private List _repeatDownloadStrategy; @@ -260,13 +268,23 @@ public class ViewBasicViewModel : ViewModelBase PublishTip(isSucceed); } - // 解析范围事件 + private DelegateCommand? _repeatFileAutoAddNumberSuffixCommand; + + public DelegateCommand RepeatFileAutoAddNumberSuffixCommand => _repeatFileAutoAddNumberSuffixCommand ??= new DelegateCommand(ExecuteRepeatFileAutoAddNumberSuffixCommand); + + private void ExecuteRepeatFileAutoAddNumberSuffixCommand() + { + var isSucceed = SettingsManager.GetInstance().IsRepeatFileAutoAddNumberSuffix(RepeatFileAutoAddNumberSuffix); + PublishTip(isSucceed); + } + + // 重复下载策略事件 private DelegateCommand? _repeatDownloadStrategyCommand; public DelegateCommand RepeatDownloadStrategyCommand => _repeatDownloadStrategyCommand ??= new DelegateCommand(ExecuteRepeatDownloadStrategyCommand); /// - /// 解析范围事件 + /// 重复下载策略事件 /// /// private void ExecuteRepeatDownloadStrategyCommand(object parameter) diff --git a/DownKyi/Views/Settings/ViewBasic.axaml b/DownKyi/Views/Settings/ViewBasic.axaml index e9458be..cdf3773 100644 --- a/DownKyi/Views/Settings/ViewBasic.axaml +++ b/DownKyi/Views/Settings/ViewBasic.axaml @@ -129,6 +129,15 @@ +