From e597596e66b6580dfd904f200e3dbf5e9cb55d05 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sun, 5 Jun 2022 00:20:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8B=E8=BD=BD=E6=B5=81?= =?UTF-8?q?=E7=9A=84https=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Settings/Models/NetworkSettings.cs | 2 ++ .../Settings/SettingsManager.Network.cs | 30 +++++++++++++++++++ DownKyi/Languages/Default.xaml | 1 + .../Services/Download/AriaDownloadService.cs | 25 ++++++++++++++++ .../Download/BuiltinDownloadService.cs | 25 ++++++++++++++++ .../Settings/ViewNetworkViewModel.cs | 26 ++++++++++++++++ DownKyi/Views/Settings/ViewNetwork.xaml | 12 ++++++++ 7 files changed, 121 insertions(+) diff --git a/DownKyi.Core/Settings/Models/NetworkSettings.cs b/DownKyi.Core/Settings/Models/NetworkSettings.cs index 1e98ceb..bf26ede 100644 --- a/DownKyi.Core/Settings/Models/NetworkSettings.cs +++ b/DownKyi.Core/Settings/Models/NetworkSettings.cs @@ -9,6 +9,8 @@ namespace DownKyi.Core.Settings.Models { public AllowStatus IsLiftingOfRegion { get; set; } = AllowStatus.NONE; + public AllowStatus UseSSL { get; set; } = AllowStatus.NONE; + public Downloader Downloader { get; set; } = Downloader.NOT_SET; public int MaxCurrentDownloads { get; set; } = -1; diff --git a/DownKyi.Core/Settings/SettingsManager.Network.cs b/DownKyi.Core/Settings/SettingsManager.Network.cs index 302846d..8ffb9e7 100644 --- a/DownKyi.Core/Settings/SettingsManager.Network.cs +++ b/DownKyi.Core/Settings/SettingsManager.Network.cs @@ -7,6 +7,9 @@ namespace DownKyi.Core.Settings // 是否开启解除地区限制 private readonly AllowStatus isLiftingOfRegion = AllowStatus.YES; + // 启用https + private readonly AllowStatus useSSL = AllowStatus.YES; + // 下载器 private readonly Downloader downloader = Downloader.ARIA; @@ -71,6 +74,33 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取是否启用https + /// + /// + public AllowStatus UseSSL() + { + appSettings = GetSettings(); + if (appSettings.Network.UseSSL == AllowStatus.NONE) + { + // 第一次获取,先设置默认值 + UseSSL(useSSL); + return useSSL; + } + return appSettings.Network.UseSSL; + } + + /// + /// 设置是否启用https + /// + /// + /// + public bool UseSSL(AllowStatus useSSL) + { + appSettings.Network.UseSSL = useSSL; + return SetSettings(); + } + /// /// 获取下载器 /// diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index 9f7993a..4cedf8c 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -183,6 +183,7 @@ 解析后自动下载已解析视频 网络 + 启用https(若下载器提示SSL错误,则关闭此项) 选择下载器(重启生效): 内建下载器(测试) Aria2下载器 diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index 2ffe7df..34ef063 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/DownKyi/Services/Download/AriaDownloadService.cs @@ -113,6 +113,31 @@ namespace DownKyi.Services.Download downloading.Downloading.Gid = null; } + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + if (useSSL == AllowStatus.YES) + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("http://")) + { + urls[i] = url.Replace("http://", "https://"); + } + } + } + else + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("https://")) + { + urls[i] = url.Replace("https://", "http://"); + } + } + } + // 开始下载 DownloadResult downloadStatus = DownloadByAria(downloading, urls, path, fileName); switch (downloadStatus) diff --git a/DownKyi/Services/Download/BuiltinDownloadService.cs b/DownKyi/Services/Download/BuiltinDownloadService.cs index 7c20f1b..4a4ca79 100644 --- a/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -108,6 +108,31 @@ namespace DownKyi.Services.Download downloading.Downloading.Gid = null; } + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + if (useSSL == AllowStatus.YES) + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("http://")) + { + urls[i] = url.Replace("http://", "https://"); + } + } + } + else + { + for (int i = 0; i < urls.Count; i++) + { + string url = urls[i]; + if (url.StartsWith("https://")) + { + urls[i] = url.Replace("https://", "http://"); + } + } + } + // 开始下载 var downloadStatus = DownloadByBuiltin(downloading, urls, path, fileName); if (downloadStatus) diff --git a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs index 0aa3468..a46ce58 100644 --- a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs @@ -20,6 +20,13 @@ namespace DownKyi.ViewModels.Settings #region 页面属性申明 + private bool useSSL; + public bool UseSSL + { + get => useSSL; + set => SetProperty(ref useSSL, value); + } + private bool builtin; public bool Builtin { @@ -236,6 +243,10 @@ namespace DownKyi.ViewModels.Settings isOnNavigatedTo = true; + // 启用https + AllowStatus useSSL = SettingsManager.GetInstance().UseSSL(); + UseSSL = useSSL == AllowStatus.YES; + // 选择下载器 var downloader = SettingsManager.GetInstance().GetDownloader(); switch (downloader) @@ -304,6 +315,21 @@ namespace DownKyi.ViewModels.Settings #region 命令申明 + // 是否启用https事件 + private DelegateCommand useSSLCommand; + public DelegateCommand UseSSLCommand => useSSLCommand ?? (useSSLCommand = new DelegateCommand(ExecuteUseSSLCommand)); + + /// + /// 是否启用https事件 + /// + private void ExecuteUseSSLCommand() + { + AllowStatus useSSL = UseSSL ? AllowStatus.YES : AllowStatus.NO; + + bool isSucceed = SettingsManager.GetInstance().UseSSL(useSSL); + PublishTip(isSucceed); + } + // 下载器选择事件 private DelegateCommand selectDownloaderCommand; public DelegateCommand SelectDownloaderCommand => selectDownloaderCommand ?? (selectDownloaderCommand = new DelegateCommand(ExecuteSelectDownloaderCommand)); diff --git a/DownKyi/Views/Settings/ViewNetwork.xaml b/DownKyi/Views/Settings/ViewNetwork.xaml index 4430c61..23a3e49 100644 --- a/DownKyi/Views/Settings/ViewNetwork.xaml +++ b/DownKyi/Views/Settings/ViewNetwork.xaml @@ -16,6 +16,18 @@ Text="{DynamicResource Network}" /> + +