From 6e6e5a4751dd94fafe1337a9a32ee14953439e50 Mon Sep 17 00:00:00 2001 From: croire <1432593898@qq.com> Date: Sat, 14 May 2022 21:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8B=E8=BD=BD=E5=99=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DownKyi.Core/DownKyi.Core.csproj | 1 + DownKyi.Core/Settings/Downloader.cs | 9 + .../Settings/Models/NetworkSettings.cs | 14 +- .../Settings/SettingsManager.Network.cs | 206 +++++- DownKyi/App.xaml.cs | 20 +- DownKyi/Languages/Default.xaml | 12 +- .../Services/Download/AriaDownloadService.cs | 2 +- .../Download/BuiltinDownloadService.cs | 12 +- DownKyi/Services/Download/DownloadService.cs | 2 +- .../Settings/ViewNetworkViewModel.cs | 281 +++++++- DownKyi/Views/Settings/ViewNetwork.xaml | 599 ++++++++++++------ 11 files changed, 873 insertions(+), 285 deletions(-) create mode 100644 DownKyi.Core/Settings/Downloader.cs diff --git a/DownKyi.Core/DownKyi.Core.csproj b/DownKyi.Core/DownKyi.Core.csproj index 5c3361b..1266e24 100644 --- a/DownKyi.Core/DownKyi.Core.csproj +++ b/DownKyi.Core/DownKyi.Core.csproj @@ -290,6 +290,7 @@ + diff --git a/DownKyi.Core/Settings/Downloader.cs b/DownKyi.Core/Settings/Downloader.cs new file mode 100644 index 0000000..ff5cb8c --- /dev/null +++ b/DownKyi.Core/Settings/Downloader.cs @@ -0,0 +1,9 @@ +namespace DownKyi.Core.Settings +{ + public enum Downloader + { + NOT_SET = 0, + BUILT_IN, + ARIA, + } +} diff --git a/DownKyi.Core/Settings/Models/NetworkSettings.cs b/DownKyi.Core/Settings/Models/NetworkSettings.cs index 6b283f8..1e98ceb 100644 --- a/DownKyi.Core/Settings/Models/NetworkSettings.cs +++ b/DownKyi.Core/Settings/Models/NetworkSettings.cs @@ -8,9 +8,20 @@ namespace DownKyi.Core.Settings.Models public class NetworkSettings { public AllowStatus IsLiftingOfRegion { get; set; } = AllowStatus.NONE; + + public Downloader Downloader { get; set; } = Downloader.NOT_SET; + public int MaxCurrentDownloads { get; set; } = -1; + + #region built-in + public int Split { get; set; } = -1; + public AllowStatus IsHttpProxy { get; set; } = AllowStatus.NONE; + public string HttpProxy { get; set; } = null; + public int HttpProxyListenPort { get; set; } = -1; + #endregion + + #region Aria public int AriaListenPort { get; set; } = -1; public AriaConfigLogLevel AriaLogLevel { get; set; } = AriaConfigLogLevel.NOT_SET; - public int AriaMaxConcurrentDownloads { get; set; } = -1; public int AriaSplit { get; set; } = -1; public int AriaMaxOverallDownloadLimit { get; set; } = -1; public int AriaMaxDownloadLimit { get; set; } = -1; @@ -19,5 +30,6 @@ namespace DownKyi.Core.Settings.Models public AllowStatus IsAriaHttpProxy { get; set; } = AllowStatus.NONE; public string AriaHttpProxy { get; set; } = null; public int AriaHttpProxyListenPort { get; set; } = -1; + #endregion } } diff --git a/DownKyi.Core/Settings/SettingsManager.Network.cs b/DownKyi.Core/Settings/SettingsManager.Network.cs index f7786d2..302846d 100644 --- a/DownKyi.Core/Settings/SettingsManager.Network.cs +++ b/DownKyi.Core/Settings/SettingsManager.Network.cs @@ -7,15 +7,26 @@ namespace DownKyi.Core.Settings // 是否开启解除地区限制 private readonly AllowStatus isLiftingOfRegion = AllowStatus.YES; + // 下载器 + private readonly Downloader downloader = Downloader.ARIA; + + // 最大同时下载数(任务数) + private readonly int maxCurrentDownloads = 3; + + // 单文件最大线程数 + private readonly int split = 8; + + // HttpProxy代理 + private readonly AllowStatus isHttpProxy = AllowStatus.NO; + private readonly string httpProxy = ""; + private readonly int httpProxyListenPort = 0; + // Aria服务器端口号 private readonly int ariaListenPort = 6800; // Aria日志等级 private readonly AriaConfigLogLevel ariaLogLevel = AriaConfigLogLevel.INFO; - // Aria最大同时下载数(任务数) - private readonly int ariaMaxConcurrentDownloads = 3; - // Aria单文件最大线程数 private readonly int ariaSplit = 5; @@ -60,6 +71,168 @@ namespace DownKyi.Core.Settings return SetSettings(); } + /// + /// 获取下载器 + /// + /// + public Downloader GetDownloader() + { + appSettings = GetSettings(); + if (appSettings.Network.Downloader == Downloader.NOT_SET) + { + // 第一次获取,先设置默认值 + SetDownloader(downloader); + return downloader; + } + return appSettings.Network.Downloader; + } + + /// + /// 设置下载器 + /// + /// + /// + public bool SetDownloader(Downloader downloader) + { + appSettings.Network.Downloader = downloader; + return SetSettings(); + } + + /// + /// 获取最大同时下载数(任务数) + /// + /// + public int GetMaxCurrentDownloads() + { + appSettings = GetSettings(); + if (appSettings.Network.MaxCurrentDownloads == -1) + { + // 第一次获取,先设置默认值 + SetMaxCurrentDownloads(maxCurrentDownloads); + return maxCurrentDownloads; + } + return appSettings.Network.MaxCurrentDownloads; + } + + /// + /// 设置最大同时下载数(任务数) + /// + /// + /// + public bool SetMaxCurrentDownloads(int maxCurrentDownloads) + { + appSettings.Network.MaxCurrentDownloads = maxCurrentDownloads; + return SetSettings(); + } + + /// + /// 获取单文件最大线程数 + /// + /// + public int GetSplit() + { + appSettings = GetSettings(); + if (appSettings.Network.Split == -1) + { + // 第一次获取,先设置默认值 + SetSplit(split); + return split; + } + return appSettings.Network.Split; + } + + /// + /// 设置单文件最大线程数 + /// + /// + /// + public bool SetSplit(int split) + { + appSettings.Network.Split = split; + return SetSettings(); + } + + /// + /// 获取是否开启Http代理 + /// + /// + public AllowStatus IsHttpProxy() + { + appSettings = GetSettings(); + if (appSettings.Network.IsHttpProxy == AllowStatus.NONE) + { + // 第一次获取,先设置默认值 + IsHttpProxy(isHttpProxy); + return isHttpProxy; + } + return appSettings.Network.IsHttpProxy; + } + + /// + /// 设置是否开启Http代理 + /// + /// + /// + public bool IsHttpProxy(AllowStatus isHttpProxy) + { + appSettings.Network.IsHttpProxy = isHttpProxy; + return SetSettings(); + } + + /// + /// 获取Http代理的地址 + /// + /// + public string GetHttpProxy() + { + appSettings = GetSettings(); + if (appSettings.Network.HttpProxy == null) + { + // 第一次获取,先设置默认值 + SetHttpProxy(httpProxy); + return httpProxy; + } + return appSettings.Network.HttpProxy; + } + + /// + /// 设置Aria的http代理的地址 + /// + /// + /// + public bool SetHttpProxy(string httpProxy) + { + appSettings.Network.HttpProxy = httpProxy; + return SetSettings(); + } + + /// + /// 获取Http代理的端口 + /// + /// + public int GetHttpProxyListenPort() + { + appSettings = GetSettings(); + if (appSettings.Network.HttpProxyListenPort == -1) + { + // 第一次获取,先设置默认值 + SetHttpProxyListenPort(httpProxyListenPort); + return httpProxyListenPort; + } + return appSettings.Network.HttpProxyListenPort; + } + + /// + /// 设置Http代理的端口 + /// + /// + /// + public bool SetHttpProxyListenPort(int httpProxyListenPort) + { + appSettings.Network.HttpProxyListenPort = httpProxyListenPort; + return SetSettings(); + } + /// /// 获取Aria服务器的端口号 /// @@ -114,33 +287,6 @@ namespace DownKyi.Core.Settings return SetSettings(); } - /// - /// 获取Aria最大同时下载数(任务数) - /// - /// - public int GetAriaMaxConcurrentDownloads() - { - appSettings = GetSettings(); - if (appSettings.Network.AriaMaxConcurrentDownloads == -1) - { - // 第一次获取,先设置默认值 - SetAriaMaxConcurrentDownloads(ariaMaxConcurrentDownloads); - return ariaMaxConcurrentDownloads; - } - return appSettings.Network.AriaMaxConcurrentDownloads; - } - - /// - /// 设置Aria最大同时下载数(任务数) - /// - /// - /// - public bool SetAriaMaxConcurrentDownloads(int ariaMaxConcurrentDownloads) - { - appSettings.Network.AriaMaxConcurrentDownloads = ariaMaxConcurrentDownloads; - return SetSettings(); - } - /// /// 获取Aria单文件最大线程数 /// diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index 019951d..cae6342 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -14,7 +14,6 @@ using DownKyi.Views.Settings; using DownKyi.Views.Toolbox; using DownKyi.Views.UserSpace; using Prism.Ioc; -using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -122,9 +121,22 @@ namespace DownKyi }); // 启动下载服务 - //downloadService = new AriaDownloadService(DownloadingList, DownloadedList); - downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); - downloadService.Start(); + var download = SettingsManager.GetInstance().GetDownloader(); + switch (download) + { + case Downloader.NOT_SET: + break; + case Downloader.BUILT_IN: + downloadService = new BuiltinDownloadService(DownloadingList, DownloadedList); + break; + case Downloader.ARIA: + downloadService = new AriaDownloadService(DownloadingList, DownloadedList); + break; + } + if (downloadService != null) + { + downloadService.Start(); + } return Container.Resolve(); } diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index 0204679..f5527a3 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -183,6 +183,9 @@ 解析后自动下载已解析视频 网络 + 选择下载器(重启生效): + 内建下载器 + Aria2下载器 Aria服务器端口: Aria日志等级: Aria同时下载数: @@ -190,10 +193,12 @@ Aria下载速度限制(KB/s) 全局下载速度限制[0: 无限制] 单任务下载速度限制[0: 无限制] - 使用Http代理 - 代理地址: - 端口: Aria文件预分配: + 使用Http代理 + 代理地址: + 端口: + 同时下载数: + 最大线程数: 视频 优先下载的视频编码: @@ -300,6 +305,7 @@ 确定 取消 + 此项需重启生效,您确定要重新启动吗? 您确定要删除吗? 请选择文件夹 diff --git a/DownKyi/Services/Download/AriaDownloadService.cs b/DownKyi/Services/Download/AriaDownloadService.cs index 70481fc..2ffe7df 100644 --- a/DownKyi/Services/Download/AriaDownloadService.cs +++ b/DownKyi/Services/Download/AriaDownloadService.cs @@ -282,7 +282,7 @@ namespace DownKyi.Services.Download ListenPort = SettingsManager.GetInstance().GetAriaListenPort(), Token = "downkyi", LogLevel = SettingsManager.GetInstance().GetAriaLogLevel(), - MaxConcurrentDownloads = SettingsManager.GetInstance().GetAriaMaxConcurrentDownloads(), + MaxConcurrentDownloads = SettingsManager.GetInstance().GetMaxCurrentDownloads(), MaxConnectionPerServer = 8, // 最大取16 Split = SettingsManager.GetInstance().GetAriaSplit(), //MaxTries = 5, diff --git a/DownKyi/Services/Download/BuiltinDownloadService.cs b/DownKyi/Services/Download/BuiltinDownloadService.cs index b7d89d3..d0a71e1 100644 --- a/DownKyi/Services/Download/BuiltinDownloadService.cs +++ b/DownKyi/Services/Download/BuiltinDownloadService.cs @@ -1,6 +1,7 @@ using DownKyi.Core.BiliApi.Login; using DownKyi.Core.BiliApi.VideoStream.Models; using DownKyi.Core.Downloader; +using DownKyi.Core.Settings; using DownKyi.Core.Utils; using DownKyi.Models; using DownKyi.Utils; @@ -256,8 +257,11 @@ namespace DownKyi.Services.Download foreach (var url in urls) { // 创建下载器 + var mtd = new MultiThreadDownloader(url, + Environment.GetEnvironmentVariable("temp"), + Path.Combine(path, localFileName), + SettingsManager.GetInstance().GetSplit()); // 配置网络请求 - var mtd = new MultiThreadDownloader(url, Environment.GetEnvironmentVariable("temp"), Path.Combine(path, localFileName), 8); mtd.Configure(req => { req.CookieContainer = LoginHelper.GetLoginInfoCookies(); @@ -265,10 +269,10 @@ namespace DownKyi.Services.Download req.Referer = "https://www.bilibili.com"; req.Headers.Add("Origin", "https://www.bilibili.com"); - if (false) + if (SettingsManager.GetInstance().IsHttpProxy() == AllowStatus.YES) { - // TODO - req.Proxy = new WebProxy("127.0.0.1", 1080); + req.Proxy = new WebProxy(SettingsManager.GetInstance().GetHttpProxy(), + SettingsManager.GetInstance().GetHttpProxyListenPort()); } }); diff --git a/DownKyi/Services/Download/DownloadService.cs b/DownKyi/Services/Download/DownloadService.cs index df34c52..5a070f5 100644 --- a/DownKyi/Services/Download/DownloadService.cs +++ b/DownKyi/Services/Download/DownloadService.cs @@ -345,7 +345,7 @@ namespace DownKyi.Services.Download while (true) { - int maxDownloading = SettingsManager.GetInstance().GetAriaMaxConcurrentDownloads(); + int maxDownloading = SettingsManager.GetInstance().GetMaxCurrentDownloads(); int downloadingCount = 0; try diff --git a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs index fedbd87..0aa3468 100644 --- a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs @@ -2,10 +2,12 @@ using DownKyi.Core.Settings; using DownKyi.Core.Utils.Validator; using DownKyi.Events; +using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; using Prism.Regions; +using Prism.Services.Dialogs; using System.Collections.Generic; namespace DownKyi.ViewModels.Settings @@ -18,111 +20,182 @@ namespace DownKyi.ViewModels.Settings #region 页面属性申明 + private bool builtin; + public bool Builtin + { + get => builtin; + set => SetProperty(ref builtin, value); + } + + private bool aria2c; + public bool Aria2c + { + get => aria2c; + set => SetProperty(ref aria2c, value); + } + + private List maxCurrentDownloads; + public List MaxCurrentDownloads + { + get => maxCurrentDownloads; + set => SetProperty(ref maxCurrentDownloads, value); + } + + private int selectedMaxCurrentDownload; + public int SelectedMaxCurrentDownload + { + get => selectedMaxCurrentDownload; + set => SetProperty(ref selectedMaxCurrentDownload, value); + } + + private List splits; + public List Splits + { + get => splits; + set => SetProperty(ref splits, value); + } + + private int selectedSplit; + public int SelectedSplit + { + get => selectedSplit; + set => SetProperty(ref selectedSplit, value); + } + + private bool isHttpProxy; + public bool IsHttpProxy + { + get => isHttpProxy; + set => SetProperty(ref isHttpProxy, value); + } + + private string httpProxy; + public string HttpProxy + { + get => httpProxy; + set => SetProperty(ref httpProxy, value); + } + + private int httpProxyPort; + public int HttpProxyPort + { + get => httpProxyPort; + set => SetProperty(ref httpProxyPort, value); + } + private int ariaListenPort; public int AriaListenPort { - get { return ariaListenPort; } - set { SetProperty(ref ariaListenPort, value); } + get => ariaListenPort; + set => SetProperty(ref ariaListenPort, value); } private List ariaLogLevels; public List AriaLogLevels { - get { return ariaLogLevels; } - set { SetProperty(ref ariaLogLevels, value); } + get => ariaLogLevels; + set => SetProperty(ref ariaLogLevels, value); } private string selectedAriaLogLevel; public string SelectedAriaLogLevel { - get { return selectedAriaLogLevel; } - set { SetProperty(ref selectedAriaLogLevel, value); } + get => selectedAriaLogLevel; + set => SetProperty(ref selectedAriaLogLevel, value); } private List ariaMaxConcurrentDownloads; public List AriaMaxConcurrentDownloads { - get { return ariaMaxConcurrentDownloads; } - set { SetProperty(ref ariaMaxConcurrentDownloads, value); } + get => ariaMaxConcurrentDownloads; + set => SetProperty(ref ariaMaxConcurrentDownloads, value); } private int selectedAriaMaxConcurrentDownload; public int SelectedAriaMaxConcurrentDownload { - get { return selectedAriaMaxConcurrentDownload; } - set { SetProperty(ref selectedAriaMaxConcurrentDownload, value); } + get => selectedAriaMaxConcurrentDownload; + set => SetProperty(ref selectedAriaMaxConcurrentDownload, value); } private List ariaSplits; public List AriaSplits { - get { return ariaSplits; } - set { SetProperty(ref ariaSplits, value); } + get => ariaSplits; + set => SetProperty(ref ariaSplits, value); } private int selectedAriaSplit; public int SelectedAriaSplit { - get { return selectedAriaSplit; } - set { SetProperty(ref selectedAriaSplit, value); } + get => selectedAriaSplit; + set => SetProperty(ref selectedAriaSplit, value); } private int ariaMaxOverallDownloadLimit; public int AriaMaxOverallDownloadLimit { - get { return ariaMaxOverallDownloadLimit; } - set { SetProperty(ref ariaMaxOverallDownloadLimit, value); } + get => ariaMaxOverallDownloadLimit; + set => SetProperty(ref ariaMaxOverallDownloadLimit, value); } private int ariaMaxDownloadLimit; public int AriaMaxDownloadLimit { - get { return ariaMaxDownloadLimit; } - set { SetProperty(ref ariaMaxDownloadLimit, value); } + get => ariaMaxDownloadLimit; + set => SetProperty(ref ariaMaxDownloadLimit, value); } private bool isAriaHttpProxy; public bool IsAriaHttpProxy { - get { return isAriaHttpProxy; } - set { SetProperty(ref isAriaHttpProxy, value); } + get => isAriaHttpProxy; + set => SetProperty(ref isAriaHttpProxy, value); } private string ariaHttpProxy; public string AriaHttpProxy { - get { return ariaHttpProxy; } - set { SetProperty(ref ariaHttpProxy, value); } + get => ariaHttpProxy; + set => SetProperty(ref ariaHttpProxy, value); } private int ariaHttpProxyPort; public int AriaHttpProxyPort { - get { return ariaHttpProxyPort; } - set { SetProperty(ref ariaHttpProxyPort, value); } + get => ariaHttpProxyPort; + set => SetProperty(ref ariaHttpProxyPort, value); } private List ariaFileAllocations; public List AriaFileAllocations { - get { return ariaFileAllocations; } - set { SetProperty(ref ariaFileAllocations, value); } + get => ariaFileAllocations; + set => SetProperty(ref ariaFileAllocations, value); } private string selectedAriaFileAllocation; public string SelectedAriaFileAllocation { - get { return selectedAriaFileAllocation; } - set { SetProperty(ref selectedAriaFileAllocation, value); } + get => selectedAriaFileAllocation; + set => SetProperty(ref selectedAriaFileAllocation, value); } #endregion - public ViewNetworkViewModel(IEventAggregator eventAggregator) : base(eventAggregator) + public ViewNetworkViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator, dialogService) { #region 属性初始化 + // builtin同时下载数 + MaxCurrentDownloads = new List(); + for (int i = 1; i <= 10; i++) { MaxCurrentDownloads.Add(i); } + + // builtin最大线程数 + Splits = new List(); + for (int i = 1; i <= 10; i++) { Splits.Add(i); } + // Aria的日志等级 AriaLogLevels = new List { @@ -154,7 +227,7 @@ namespace DownKyi.ViewModels.Settings } /// - /// 导航到VideoDetail页面时执行 + /// 导航到页面时执行 /// /// public override void OnNavigatedTo(NavigationContext navigationContext) @@ -163,6 +236,36 @@ namespace DownKyi.ViewModels.Settings isOnNavigatedTo = true; + // 选择下载器 + var downloader = SettingsManager.GetInstance().GetDownloader(); + switch (downloader) + { + case Downloader.NOT_SET: + break; + case Downloader.BUILT_IN: + Builtin = true; + break; + case Downloader.ARIA: + Aria2c = true; + break; + } + + // builtin同时下载数 + SelectedMaxCurrentDownload = SettingsManager.GetInstance().GetMaxCurrentDownloads(); + + // builtin最大线程数 + SelectedSplit = SettingsManager.GetInstance().GetSplit(); + + // 是否开启builtin http代理 + AllowStatus isHttpProxy = SettingsManager.GetInstance().IsHttpProxy(); + IsHttpProxy = isHttpProxy == AllowStatus.YES; + + // builtin的http代理的地址 + HttpProxy = SettingsManager.GetInstance().GetHttpProxy(); + + // builtin的http代理的端口 + HttpProxyPort = SettingsManager.GetInstance().GetHttpProxyListenPort(); + // Aria服务器端口 AriaListenPort = SettingsManager.GetInstance().GetAriaListenPort(); @@ -171,7 +274,7 @@ namespace DownKyi.ViewModels.Settings SelectedAriaLogLevel = ariaLogLevel.ToString("G"); // Aria同时下载数 - SelectedAriaMaxConcurrentDownload = SettingsManager.GetInstance().GetAriaMaxConcurrentDownloads(); + SelectedAriaMaxConcurrentDownload = SettingsManager.GetInstance().GetMaxCurrentDownloads(); // Aria最大线程数 SelectedAriaSplit = SettingsManager.GetInstance().GetAriaSplit(); @@ -201,6 +304,120 @@ namespace DownKyi.ViewModels.Settings #region 命令申明 + // 下载器选择事件 + private DelegateCommand selectDownloaderCommand; + public DelegateCommand SelectDownloaderCommand => selectDownloaderCommand ?? (selectDownloaderCommand = new DelegateCommand(ExecuteSelectDownloaderCommand)); + + /// + /// 下载器选择事件 + /// + /// + private void ExecuteSelectDownloaderCommand(string parameter) + { + Downloader downloader; + switch (parameter) + { + case "Builtin": + downloader = Downloader.BUILT_IN; + break; + case "Aria2c": + downloader = Downloader.ARIA; + break; + default: + downloader = SettingsManager.GetInstance().GetDownloader(); + break; + } + + bool isSucceed = SettingsManager.GetInstance().SetDownloader(downloader); + PublishTip(isSucceed); + + AlertService alertService = new AlertService(dialogService); + ButtonResult result = alertService.ShowInfo(DictionaryResource.GetString("ConfirmReboot")); + if (result == ButtonResult.OK) + { + System.Windows.Application.Current.Shutdown(); + System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); + } + } + + // builtin同时下载数事件 + private DelegateCommand maxCurrentDownloadsCommand; + public DelegateCommand MaxCurrentDownloadsCommand => maxCurrentDownloadsCommand ?? (maxCurrentDownloadsCommand = new DelegateCommand(ExecuteMaxCurrentDownloadsCommand)); + + /// + /// builtin同时下载数事件 + /// + /// + private void ExecuteMaxCurrentDownloadsCommand(object parameter) + { + SelectedMaxCurrentDownload = (int)parameter; + + bool isSucceed = SettingsManager.GetInstance().SetMaxCurrentDownloads(SelectedMaxCurrentDownload); + PublishTip(isSucceed); + } + + // builtin最大线程数事件 + private DelegateCommand splitsCommand; + public DelegateCommand SplitsCommand => splitsCommand ?? (splitsCommand = new DelegateCommand(ExecuteSplitsCommand)); + + /// + /// builtin最大线程数事件 + /// + /// + private void ExecuteSplitsCommand(object parameter) + { + SelectedSplit = (int)parameter; + + bool isSucceed = SettingsManager.GetInstance().SetSplit(SelectedSplit); + PublishTip(isSucceed); + } + + // 是否开启builtin http代理事件 + private DelegateCommand isHttpProxyCommand; + public DelegateCommand IsHttpProxyCommand => isHttpProxyCommand ?? (isHttpProxyCommand = new DelegateCommand(ExecuteIsHttpProxyCommand)); + + /// + /// 是否开启builtin http代理事件 + /// + private void ExecuteIsHttpProxyCommand() + { + AllowStatus isHttpProxy = IsHttpProxy ? AllowStatus.YES : AllowStatus.NO; + + bool isSucceed = SettingsManager.GetInstance().IsHttpProxy(isHttpProxy); + PublishTip(isSucceed); + } + + // builtin的http代理的地址事件 + private DelegateCommand httpProxyCommand; + public DelegateCommand HttpProxyCommand => httpProxyCommand ?? (httpProxyCommand = new DelegateCommand(ExecuteHttpProxyCommand)); + + /// + /// builtin的http代理的地址事件 + /// + /// + private void ExecuteHttpProxyCommand(string parameter) + { + bool isSucceed = SettingsManager.GetInstance().SetHttpProxy(parameter); + PublishTip(isSucceed); + } + + // builtin的http代理的端口事件 + private DelegateCommand httpProxyPortCommand; + public DelegateCommand HttpProxyPortCommand => httpProxyPortCommand ?? (httpProxyPortCommand = new DelegateCommand(ExecuteHttpProxyPortCommand)); + + /// + /// builtin的http代理的端口事件 + /// + /// + private void ExecuteHttpProxyPortCommand(string parameter) + { + int httpProxyPort = (int)Number.GetInt(parameter); + HttpProxyPort = httpProxyPort; + + bool isSucceed = SettingsManager.GetInstance().SetHttpProxyListenPort(HttpProxyPort); + PublishTip(isSucceed); + } + // Aria服务器端口事件 private DelegateCommand ariaListenPortCommand; public DelegateCommand AriaListenPortCommand => ariaListenPortCommand ?? (ariaListenPortCommand = new DelegateCommand(ExecuteAriaListenPortCommand)); @@ -267,7 +484,7 @@ namespace DownKyi.ViewModels.Settings { SelectedAriaMaxConcurrentDownload = (int)parameter; - bool isSucceed = SettingsManager.GetInstance().SetAriaMaxConcurrentDownloads(SelectedAriaMaxConcurrentDownload); + bool isSucceed = SettingsManager.GetInstance().SetMaxCurrentDownloads(SelectedAriaMaxConcurrentDownload); PublishTip(isSucceed); } diff --git a/DownKyi/Views/Settings/ViewNetwork.xaml b/DownKyi/Views/Settings/ViewNetwork.xaml index fc64dff..4430c61 100644 --- a/DownKyi/Views/Settings/ViewNetwork.xaml +++ b/DownKyi/Views/Settings/ViewNetwork.xaml @@ -16,244 +16,425 @@ Text="{DynamicResource Network}" /> - + - - - - - - + Text="{DynamicResource SelectDownloader}" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - + - - - - - + IsChecked="{Binding Aria2c}" + Style="{StaticResource RadioStyle}" /> - - + + - + Background="{DynamicResource BrushBorder}" /> - + - + - - - - - - - - - + - - - - + ItemsSource="{Binding MaxCurrentDownloads}" + SelectedValue="{Binding SelectedMaxCurrentDownload}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + IsChecked="{Binding IsAriaHttpProxy, Mode=TwoWay}" + Style="{StaticResource CheckBoxStyle}" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +