From b8e1cc62425ef19991df84dd6779f5126d56807f Mon Sep 17 00:00:00 2001 From: aiqinxuancai Date: Wed, 21 Feb 2024 16:14:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=AE=A2=E9=98=85=E4=B8=AD?= =?UTF-8?q?=E9=9D=9Ebt=E7=9A=84=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria2Fast/Service/Aria2ApiManager.cs | 2 +- Aria2Fast/Service/Model/TaskModel.cs | 22 +++---- Aria2Fast/Service/SubscriptionManager.cs | 63 ++++++++++--------- .../View/WkySubscriptionListView.xaml.cs | 5 +- Aria2Fast/View/WkyTaskListView.xaml.cs | 36 ++++++----- 5 files changed, 69 insertions(+), 59 deletions(-) diff --git a/Aria2Fast/Service/Aria2ApiManager.cs b/Aria2Fast/Service/Aria2ApiManager.cs index 20c8354..8b96711 100644 --- a/Aria2Fast/Service/Aria2ApiManager.cs +++ b/Aria2Fast/Service/Aria2ApiManager.cs @@ -302,7 +302,7 @@ public async Task DeleteFile(string gid) try { Debug.WriteLine($"删除任务:{gid}"); - var result = await _client.ForceRemoveAsync(gid); + var result = await _client.RemoveAsync(gid); return IsGid(result); } catch (Exception ex) diff --git a/Aria2Fast/Service/Model/TaskModel.cs b/Aria2Fast/Service/Model/TaskModel.cs index 5df3345..934c473 100644 --- a/Aria2Fast/Service/Model/TaskModel.cs +++ b/Aria2Fast/Service/Model/TaskModel.cs @@ -22,11 +22,11 @@ public bool FromSubscription { get { - if (!string.IsNullOrWhiteSpace(Data.Gid) && - SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.Gid)) - { - return true; - } + //if (!string.IsNullOrWhiteSpace(Data.Gid) && + // SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.Gid)) + //{ + // return true; + //} if (!string.IsNullOrWhiteSpace(Data.InfoHash) && SubscriptionManager.Instance.TaskUrlToSubscriptionName.ContainsKey(Data.InfoHash)) { @@ -73,13 +73,13 @@ public string SubscriptionName { if (FromSubscription) { - var name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.Gid]; - if (!string.IsNullOrWhiteSpace(name)) - { - return name; - } + //var name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.Gid]; + //if (!string.IsNullOrWhiteSpace(name)) + //{ + // return name; + //} - name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.InfoHash!]; + var name = (string)SubscriptionManager.Instance.TaskUrlToSubscriptionName[Data.InfoHash!]; if (!string.IsNullOrWhiteSpace(name)) { return name; diff --git a/Aria2Fast/Service/SubscriptionManager.cs b/Aria2Fast/Service/SubscriptionManager.cs index 5a277d7..676bcc0 100644 --- a/Aria2Fast/Service/SubscriptionManager.cs +++ b/Aria2Fast/Service/SubscriptionManager.cs @@ -429,37 +429,38 @@ public async void CheckSubscriptionOne(SubscriptionModel subscription) } else { - //其他类型订阅,如https、ftp - try - { - savePath = await AutoEpisodeTitle(subscription, subject, savePath); - - EasyLogManager.Logger.Info($"添加下载{subject} {link.Uri} {savePath}"); - var aria2Result = Aria2ApiManager.Instance.DownloadUrl(downloadUrl, savePath).Result; - - if (aria2Result.isSuccessed) - { - TaskUrlToSubscriptionName[aria2Result.Gid] = subject; - if (!string.IsNullOrWhiteSpace(aria2Result.InfoHash)) - { - TaskUrlToSubscriptionName[aria2Result.InfoHash] = subject; - } - } - - if (aria2Result.isSuccessed) - { - subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now }); - EasyLogManager.Logger.Info($"添加成功"); - } - else - { - EasyLogManager.Logger.Error($"添加失败"); - } - } - catch (Exception ex) - { - EasyLogManager.Logger.Error(ex.ToString()); - } + //其他类型订阅,如https、ftp? + //try + //{ + + // savePath = await AutoEpisodeTitle(subscription, subject, savePath); + + // EasyLogManager.Logger.Info($"添加下载{subject} {link.Uri} {savePath}"); + // var aria2Result = Aria2ApiManager.Instance.DownloadUrl(downloadUrl, savePath).Result; + + // if (aria2Result.isSuccessed) + // { + // TaskUrlToSubscriptionName[aria2Result.Gid] = subject; + // if (!string.IsNullOrWhiteSpace(aria2Result.InfoHash)) + // { + // TaskUrlToSubscriptionName[aria2Result.InfoHash] = subject; + // } + // } + + // if (aria2Result.isSuccessed) + // { + // subscription.AlreadyAddedDownloadModel.Add(new SubscriptionSubTaskModel() { Name = subject, Url = downloadUrl, Time = DateTime.Now }); + // EasyLogManager.Logger.Info($"添加成功"); + // } + // else + // { + // EasyLogManager.Logger.Error($"添加失败"); + // } + //} + //catch (Exception ex) + //{ + // EasyLogManager.Logger.Error(ex.ToString()); + //} } } diff --git a/Aria2Fast/View/WkySubscriptionListView.xaml.cs b/Aria2Fast/View/WkySubscriptionListView.xaml.cs index 23c379a..d9ff036 100644 --- a/Aria2Fast/View/WkySubscriptionListView.xaml.cs +++ b/Aria2Fast/View/WkySubscriptionListView.xaml.cs @@ -41,7 +41,10 @@ public WkySubscriptionListView(ObservableCollection viewModel //主动刷新? this.ViewModel = viewModel; this.ViewModel = SubscriptionManager.Instance.SubscriptionModel; //订阅列表绑定 - this.SubscriptionButton.IsEnabled = false; + this.SubscriptionButton.IsEnabled = Aria2ApiManager.Instance.Connected; + + + // Aria2ApiManager.Instance.EventReceived .OfType() diff --git a/Aria2Fast/View/WkyTaskListView.xaml.cs b/Aria2Fast/View/WkyTaskListView.xaml.cs index 7ec0c1b..20833ae 100644 --- a/Aria2Fast/View/WkyTaskListView.xaml.cs +++ b/Aria2Fast/View/WkyTaskListView.xaml.cs @@ -97,11 +97,12 @@ private async void MenuCopyTitle_Click(object sender, RoutedEventArgs e) { try { + var selectedItems = _selectedItems; var title = ""; - foreach (var item in _selectedItems) + foreach (var item in selectedItems) { title += item.SubscriptionName; - if (item != _selectedItems.Last()) + if (item != selectedItems.Last()) { title += "\n"; } @@ -119,7 +120,8 @@ private async void MenuRestart_Click(object sender, RoutedEventArgs e) { try { - foreach (var item in _selectedItems) + var selectedItems = _selectedItems; + foreach (var item in selectedItems) { if (item.Data.Status == Aria2ApiManager.KARIA2_STATUS_PAUSED || item.Data.Status == Aria2ApiManager.KARIA2_STATUS_ERROR) @@ -140,8 +142,8 @@ private async void MenuStop_Click(object sender, RoutedEventArgs e) { try { - - foreach (var item in _selectedItems) + var selectedItems = _selectedItems; + foreach (var item in selectedItems) { if (item.Data.Status != Aria2ApiManager.KARIA2_STATUS_COMPLETE) { @@ -160,30 +162,32 @@ private async void MenuStop_Click(object sender, RoutedEventArgs e) private async void MenuDelete_Click(object sender, RoutedEventArgs e) { + var selectedItems = _selectedItems; + var title = ""; - foreach (var item in _selectedItems) + foreach (var item in selectedItems) { title += item.SubscriptionName; - if (item != _selectedItems.Last()) + if (item != selectedItems.Last()) { title += "\n"; } } var content = ""; - if (_selectedItems.Count == 1) + if (selectedItems.Count == 1) { content = $"是否确认删除任务:\r\n{title}?"; } else { - content = $"是否确认删除{_selectedItems.Count}个任务?"; + content = $"是否确认删除{selectedItems.Count}个任务?"; } MainWindow.Instance.ShowMessageBox("提示", content, async () => { try { - foreach (var item in _selectedItems) + foreach (var item in selectedItems) { if (item.Data.Status == Aria2ApiManager.KARIA2_STATUS_ERROR || item.Data.Status == Aria2ApiManager.KARIA2_STATUS_REMOVED || @@ -215,11 +219,13 @@ private async void MenuDelete_Click(object sender, RoutedEventArgs e) private async void MenuDeleteFile_Click(object sender, RoutedEventArgs e) { + var selectedItems = _selectedItems; + var title = ""; - foreach (var item in _selectedItems) + foreach (var item in selectedItems) { title += item.SubscriptionName; //TODO - if (item != _selectedItems.Last()) + if (item != selectedItems.Last()) { title += "\n"; } @@ -227,13 +233,13 @@ private async void MenuDeleteFile_Click(object sender, RoutedEventArgs e) var content = ""; - if (_selectedItems.Count == 1) + if (selectedItems.Count == 1) { content = $"是否确认删除任务及文件:\r\n{title}?"; } else { - content = $"是否确认删除{_selectedItems.Count}个任务及文件?"; + content = $"是否确认删除{selectedItems.Count}个任务及文件?"; } @@ -241,7 +247,7 @@ private async void MenuDeleteFile_Click(object sender, RoutedEventArgs e) MainWindow.Instance.ShowMessageBox("提示", content, async () => { try { - foreach (var item in _selectedItems) + foreach (var item in selectedItems) { await Aria2ApiManager.Instance.DeleteFile(item.Data.Gid); }