Skip to content

Commit

Permalink
移除订阅中非bt的下载
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Feb 21, 2024
1 parent bce09b7 commit b8e1cc6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Aria2Fast/Service/Aria2ApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public async Task<bool> 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)
Expand Down
22 changes: 11 additions & 11 deletions Aria2Fast/Service/Model/TaskModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down
63 changes: 32 additions & 31 deletions Aria2Fast/Service/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
//}
}

}
Expand Down
5 changes: 4 additions & 1 deletion Aria2Fast/View/WkySubscriptionListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public WkySubscriptionListView(ObservableCollection<SubscriptionModel> viewModel
//主动刷新?
this.ViewModel = viewModel;
this.ViewModel = SubscriptionManager.Instance.SubscriptionModel; //订阅列表绑定
this.SubscriptionButton.IsEnabled = false;
this.SubscriptionButton.IsEnabled = Aria2ApiManager.Instance.Connected;


//

Aria2ApiManager.Instance.EventReceived
.OfType<LoginResultEvent>()
Expand Down
36 changes: 21 additions & 15 deletions Aria2Fast/View/WkyTaskListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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)
Expand All @@ -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)
{
Expand All @@ -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 ||
Expand Down Expand Up @@ -215,33 +219,35 @@ 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";
}
}


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)
{
await Aria2ApiManager.Instance.DeleteFile(item.Data.Gid);
}
Expand Down

0 comments on commit b8e1cc6

Please sign in to comment.