From e196fa7d198e5252bbdc4b133e6fe1a6feeac656 Mon Sep 17 00:00:00 2001 From: aiqinxuancai Date: Fri, 15 Mar 2024 13:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E7=94=A8=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E4=BD=BF=E7=94=A8=E8=BF=87=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=8B=86=E5=88=86=E7=94=B5=E5=BD=B1?= =?UTF-8?q?=E5=8F=8A=E5=89=A7=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria2Fast/Service/AppConfig.cs | 17 ++- Aria2Fast/Service/AppConfigExpand.cs | 133 +++++++++++++++++++++ Aria2Fast/Service/Aria2ApiManager.cs | 5 +- Aria2Fast/View/AddSubscriptionView.xaml | 10 +- Aria2Fast/View/AddSubscriptionView.xaml.cs | 28 ++--- Aria2Fast/View/AddTaskView.xaml | 10 +- Aria2Fast/View/AddTaskView.xaml.cs | 34 +++--- 7 files changed, 188 insertions(+), 49 deletions(-) create mode 100644 Aria2Fast/Service/AppConfigExpand.cs diff --git a/Aria2Fast/Service/AppConfig.cs b/Aria2Fast/Service/AppConfig.cs index 849e790..fae8468 100644 --- a/Aria2Fast/Service/AppConfig.cs +++ b/Aria2Fast/Service/AppConfig.cs @@ -67,18 +67,15 @@ private void AppConfigData_PropertyChanged(object? sender, PropertyChangedEventA } - /// - /// 分区路径->存储路径 - /// 【RPC URL->存储路径】 + /// 任务的保存路径 /// - public Dictionary AddTaskSavePathDict { get; set; } = new Dictionary(); + public Dictionary> AddTaskSavePathList { get; set; } = new Dictionary>(); /// - /// 分区路径->存储路径 - /// 【分区路径->存储路径】 + /// 订阅的保存路径 /// - public Dictionary AddSubscriptionSavePathDict { get; set; } = new Dictionary(); + public Dictionary> AddSubscriptionSavePathList { get; set; } = new Dictionary>(); /// /// 常用过滤器名称(不区分RPC了) @@ -86,10 +83,8 @@ private void AppConfigData_PropertyChanged(object? sender, PropertyChangedEventA public List AddSubscriptionFilterList { get; set; } = new List(); //OSS相关设置 - public bool OSSSynchronizeOpen { get; set; } = false; - public string OSSEndpoint { get; set; } = string.Empty; public string OSSBucket { get; set; } = string.Empty; @@ -191,7 +186,7 @@ public string Aria2RpcHost /// /// 配置项读取、写入、存储逻辑 /// - public class AppConfig + public partial class AppConfig { private static readonly AppConfig instance = new AppConfig(); @@ -275,6 +270,8 @@ private void AppConfigData_PropertyChanged(object? sender, PropertyChangedEventA Save(); } + + public void Save() { try diff --git a/Aria2Fast/Service/AppConfigExpand.cs b/Aria2Fast/Service/AppConfigExpand.cs new file mode 100644 index 0000000..8cd85c9 --- /dev/null +++ b/Aria2Fast/Service/AppConfigExpand.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Aria2Fast.Service +{ + /// + /// 扩展常用下载路径的保存 + /// + public partial class AppConfig + { + + public void InitLocalPath(string dir) + { + var dict = ConfigData.AddTaskSavePathList; + + dict[ConfigData.Aria2RpcAuto] = new List + { + dir, + Path.Combine(dir, "movies"), + Path.Combine(dir, "tvshows") + }; + + dict = ConfigData.AddSubscriptionSavePathList; + dict[ConfigData.Aria2RpcAuto] = new List + { + dir, + Path.Combine(dir, "movies"), + Path.Combine(dir, "tvshows") + }; + + Save(); + + + } + + + public List GetDownloadPathWithAddTask() + { + var dict = ConfigData.AddTaskSavePathList; + + if (dict.ContainsKey(ConfigData.Aria2RpcAuto)) + { + return dict[ConfigData.Aria2RpcAuto]; + } + //返回默认的值并写入 + + dict[ConfigData.Aria2RpcAuto] = new List + { + "/downloads" , + "/downloads/movies", + "/downloads/tvshows" + }; + + Save(); + + return dict[ConfigData.Aria2RpcAuto]; + } + + public List GetDownloadPathWithAddSubscription() + { + var dict = ConfigData.AddSubscriptionSavePathList; + + if (dict.ContainsKey(ConfigData.Aria2RpcAuto)) + { + return dict[ConfigData.Aria2RpcAuto]; + } + //返回默认的值并写入 + + dict[ConfigData.Aria2RpcAuto] = new List + { + "/downloads" , + "/downloads/movies", + "/downloads/tvshows" + }; + + Save(); + + return dict[ConfigData.Aria2RpcAuto]; + } + + public void SaveDownloadPathWithAddTask(string path) + { + var dict = ConfigData.AddTaskSavePathList; + + if (!dict.ContainsKey(ConfigData.Aria2RpcAuto)) + { + dict[ConfigData.Aria2RpcAuto] = new List(); + } + var list = dict[ConfigData.Aria2RpcAuto]; + + var hasValue = list.Any(a => a == path); + if (hasValue) + { + list.Remove(path); + } + if (list.Count > 8) + { + list.RemoveAt(list.Count - 1); + } + + list.Insert(0, path); + Save(); + } + + public void SaveDownloadPathWithAddSubscription(string path) + { + var dict = ConfigData.AddSubscriptionSavePathList; + + if (!dict.ContainsKey(ConfigData.Aria2RpcAuto)) + { + dict[ConfigData.Aria2RpcAuto] = new List(); + } + var list = dict[ConfigData.Aria2RpcAuto]; + + var hasValue = list.Any(a => a == path); + if (hasValue) + { + list.Remove(path); + } + if (list.Count > 8) + { + list.RemoveAt(list.Count - 1); + } + + list.Insert(0, path); + Save(); + } + } +} diff --git a/Aria2Fast/Service/Aria2ApiManager.cs b/Aria2Fast/Service/Aria2ApiManager.cs index 9caba76..bd095aa 100644 --- a/Aria2Fast/Service/Aria2ApiManager.cs +++ b/Aria2Fast/Service/Aria2ApiManager.cs @@ -148,11 +148,10 @@ private void StartupLocalAria2() AppConfig.Instance.ConfigData.Aria2RpcLocal = rpc; AppConfig.Instance.ConfigData.Aria2TokenLocal = secret; - if (firstRun) + if (firstRun || !AppConfig.Instance.ConfigData.AddTaskSavePathList.ContainsKey(AppConfig.Instance.ConfigData.Aria2RpcAuto)) { AppConfig.Instance.ConfigData.Aria2LocalSavePath = dir; - AppConfig.Instance.ConfigData.AddTaskSavePathDict[AppConfig.Instance.ConfigData.Aria2RpcAuto] = dir; - AppConfig.Instance.Save(); + AppConfig.Instance.InitLocalPath(dir); } EasyLogManager.Logger.Info($"本地Aria2:{rpc}"); diff --git a/Aria2Fast/View/AddSubscriptionView.xaml b/Aria2Fast/View/AddSubscriptionView.xaml index f4fb303..389d4cf 100644 --- a/Aria2Fast/View/AddSubscriptionView.xaml +++ b/Aria2Fast/View/AddSubscriptionView.xaml @@ -117,13 +117,13 @@ - + IsEditable="True" /> diff --git a/Aria2Fast/View/AddSubscriptionView.xaml.cs b/Aria2Fast/View/AddSubscriptionView.xaml.cs index 356657f..f32873b 100644 --- a/Aria2Fast/View/AddSubscriptionView.xaml.cs +++ b/Aria2Fast/View/AddSubscriptionView.xaml.cs @@ -69,20 +69,20 @@ private void LoadDefaultPathSelected() { try { - if (AppConfig.Instance.ConfigData.AddSubscriptionSavePathDict.TryGetValue(AppConfig.Instance.ConfigData.Aria2RpcAuto, out var path)) + var paths = AppConfig.Instance.GetDownloadPathWithAddSubscription(); + foreach (var item in paths) { - this.TextBoxPath.Text = path; - } - else - { - this.TextBoxPath.Text = "/downloads"; + PathComboBox.Items.Add(item); } + PathComboBox.SelectedIndex = 0; + } catch (Exception ex) { EasyLogManager.Logger.Error(ex); } + } @@ -91,9 +91,9 @@ private async void ConfirmButton_Click(object sender, RoutedEventArgs e) if (AppConfig.Instance.ConfigData.Aria2UseLocal) { //检查本地目录存在 - if (!PathHelper.LocalPathCheckAndCreate(TextBoxPath.Text)) + if (!PathHelper.LocalPathCheckAndCreate(PathComboBox.Text)) { - MainWindow.Instance.ShowSnackbar("失败", $"目录 {TextBoxPath.Text} 无法使用"); + MainWindow.Instance.ShowSnackbar("失败", $"目录 {PathComboBox.Text} 无法使用"); return; } } @@ -129,7 +129,7 @@ await Task.Run(() => { url = UrlTextBox.Text; regex = RegexTextBox.Text; regexEnable = RegexCheckBox.IsChecked == true ? true : false; - path = TextBoxPath.Text; + path = PathComboBox.Text; autoDir = AutoDirSwitch.IsChecked == true ? true : false; }); @@ -150,18 +150,18 @@ await Task.Run(() => { if (string.IsNullOrWhiteSpace(title)) { - path = TextBoxPath.Text; + path = PathComboBox.Text; } else { - path = TextBoxPath.Text + (TextBoxPath.Text.EndsWith("/") ? "" : "/") + title; + path = PathComboBox.Text + (PathComboBox.Text.EndsWith("/") ? "" : "/") + title; } SubscriptionManager.Instance.Add(url, path, regex, regexEnable, autoDir: autoDir); EasyLogManager.Logger.Info($"订阅已添加:{title} {url}"); MainWindow.Instance.ShowSnackbar("添加成功", $"已添加订阅{title}", SymbolRegular.AddCircle24); - + AppConfig.Instance.SaveDownloadPathWithAddSubscription(PathComboBox.Text); if (!string.IsNullOrWhiteSpace(RegexTextBox.Text)) { var list = AppConfig.Instance.ConfigData.AddSubscriptionFilterList; @@ -222,8 +222,8 @@ private void CancelButton_Click(object sender, RoutedEventArgs e) private void TextBoxPath_TextChanged(object sender, TextChangedEventArgs e) { //当前选择的设备ID - AppConfig.Instance.ConfigData.AddSubscriptionSavePathDict[AppConfig.Instance.ConfigData.Aria2RpcAuto] = TextBoxPath.Text; - AppConfig.Instance.Save(); + //AppConfig.Instance.ConfigData.AddSubscriptionSavePathDict[AppConfig.Instance.ConfigData.Aria2RpcAuto] = TextBoxPath.Text; + //AppConfig.Instance.Save(); } private async void UrlTextBox_TextChanged(object sender, TextChangedEventArgs e) diff --git a/Aria2Fast/View/AddTaskView.xaml b/Aria2Fast/View/AddTaskView.xaml index 6c91920..74acb4a 100644 --- a/Aria2Fast/View/AddTaskView.xaml +++ b/Aria2Fast/View/AddTaskView.xaml @@ -63,13 +63,19 @@ - + +