新增下载流的https控制

html
leiurayer 2 years ago
parent bfad734d59
commit 259271ec8c

@ -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;

@ -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();
}
/// <summary>
/// 获取是否启用https
/// </summary>
/// <returns></returns>
public AllowStatus UseSSL()
{
appSettings = GetSettings();
if (appSettings.Network.UseSSL == AllowStatus.NONE)
{
// 第一次获取,先设置默认值
UseSSL(useSSL);
return useSSL;
}
return appSettings.Network.UseSSL;
}
/// <summary>
/// 设置是否启用https
/// </summary>
/// <param name="useSSL"></param>
/// <returns></returns>
public bool UseSSL(AllowStatus useSSL)
{
appSettings.Network.UseSSL = useSSL;
return SetSettings();
}
/// <summary>
/// 获取下载器
/// </summary>

@ -183,8 +183,9 @@
<system:String x:Key="AutoDownloadAll">解析后自动下载已解析视频</system:String>
<system:String x:Key="Network">网络</system:String>
<system:String x:Key="UseSSL">启用https若下载器提示SSL错误则关闭此项</system:String>
<system:String x:Key="SelectDownloader">选择下载器(重启生效):</system:String>
<system:String x:Key="BuiltinDownloader">内建下载器</system:String>
<system:String x:Key="BuiltinDownloader">内建下载器(测试)</system:String>
<system:String x:Key="Aria2cDownloader">Aria2下载器</system:String>
<system:String x:Key="AriaServerPort">Aria服务器端口</system:String>
<system:String x:Key="AriaLogLevel">Aria日志等级</system:String>

@ -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)

@ -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)

@ -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));
/// <summary>
/// 是否启用https事件
/// </summary>
private void ExecuteUseSSLCommand()
{
AllowStatus useSSL = UseSSL ? AllowStatus.YES : AllowStatus.NO;
bool isSucceed = SettingsManager.GetInstance().UseSSL(useSSL);
PublishTip(isSucceed);
}
// 下载器选择事件
private DelegateCommand<string> selectDownloaderCommand;
public DelegateCommand<string> SelectDownloaderCommand => selectDownloaderCommand ?? (selectDownloaderCommand = new DelegateCommand<string>(ExecuteSelectDownloaderCommand));

@ -16,6 +16,18 @@
Text="{DynamicResource Network}" />
</StackPanel>
<CheckBox
Name="nameUseSSL"
Margin="0,20,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Command="{Binding UseSSLCommand}"
Content="{DynamicResource UseSSL}"
FontSize="12"
Foreground="{DynamicResource BrushTextDark}"
IsChecked="{Binding UseSSL, Mode=TwoWay}"
Style="{StaticResource CheckBoxStyle}" />
<StackPanel Margin="0,20,0,0" Orientation="Vertical">
<TextBlock
FontSize="12"

Loading…
Cancel
Save