Skip to content

Commit

Permalink
常用的路径存储可以选择最近使用过的路径,方便拆分电影及剧集
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Mar 15, 2024
1 parent d329cce commit e196fa7
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 49 deletions.
17 changes: 7 additions & 10 deletions Aria2Fast/Service/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,24 @@ private void AppConfigData_PropertyChanged(object? sender, PropertyChangedEventA

}


/// <summary>
/// 分区路径->存储路径
/// 【RPC URL->存储路径】
/// 任务的保存路径
/// </summary>
public Dictionary<string, string> AddTaskSavePathDict { get; set; } = new Dictionary<string, string>();
public Dictionary<string, List<string>> AddTaskSavePathList { get; set; } = new Dictionary<string, List<string>>();

/// <summary>
/// 分区路径->存储路径
/// 【分区路径->存储路径】
/// 订阅的保存路径
/// </summary>
public Dictionary<string, string> AddSubscriptionSavePathDict { get; set; } = new Dictionary<string, string>();
public Dictionary<string, List<string>> AddSubscriptionSavePathList { get; set; } = new Dictionary<string, List<string>>();

/// <summary>
/// 常用过滤器名称(不区分RPC了)
/// </summary>
public List<SubscriptionFilterModel> AddSubscriptionFilterList { get; set; } = new List<SubscriptionFilterModel>();

//OSS相关设置

public bool OSSSynchronizeOpen { get; set; } = false;


public string OSSEndpoint { get; set; } = string.Empty;

public string OSSBucket { get; set; } = string.Empty;
Expand Down Expand Up @@ -191,7 +186,7 @@ public string Aria2RpcHost
/// <summary>
/// 配置项读取、写入、存储逻辑
/// </summary>
public class AppConfig
public partial class AppConfig
{
private static readonly AppConfig instance = new AppConfig();

Expand Down Expand Up @@ -275,6 +270,8 @@ private void AppConfigData_PropertyChanged(object? sender, PropertyChangedEventA
Save();
}



public void Save()
{
try
Expand Down
133 changes: 133 additions & 0 deletions Aria2Fast/Service/AppConfigExpand.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 扩展常用下载路径的保存
/// </summary>
public partial class AppConfig
{

public void InitLocalPath(string dir)
{
var dict = ConfigData.AddTaskSavePathList;

dict[ConfigData.Aria2RpcAuto] = new List<string>
{
dir,
Path.Combine(dir, "movies"),
Path.Combine(dir, "tvshows")
};

dict = ConfigData.AddSubscriptionSavePathList;
dict[ConfigData.Aria2RpcAuto] = new List<string>
{
dir,
Path.Combine(dir, "movies"),
Path.Combine(dir, "tvshows")
};

Save();


}


public List<string> GetDownloadPathWithAddTask()
{
var dict = ConfigData.AddTaskSavePathList;

if (dict.ContainsKey(ConfigData.Aria2RpcAuto))
{
return dict[ConfigData.Aria2RpcAuto];
}
//返回默认的值并写入

dict[ConfigData.Aria2RpcAuto] = new List<string>
{
"/downloads" ,
"/downloads/movies",
"/downloads/tvshows"
};

Save();

return dict[ConfigData.Aria2RpcAuto];
}

public List<string> GetDownloadPathWithAddSubscription()
{
var dict = ConfigData.AddSubscriptionSavePathList;

if (dict.ContainsKey(ConfigData.Aria2RpcAuto))
{
return dict[ConfigData.Aria2RpcAuto];
}
//返回默认的值并写入

dict[ConfigData.Aria2RpcAuto] = new List<string>
{
"/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<string>();
}
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<string>();
}
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();
}
}
}
5 changes: 2 additions & 3 deletions Aria2Fast/Service/Aria2ApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
10 changes: 5 additions & 5 deletions Aria2Fast/View/AddSubscriptionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>
<ui:TextBox
x:Name="TextBoxPath"


<ComboBox
x:Name="PathComboBox"
Grid.Column="2"
Padding="10,5,10,5"
ClearButtonEnabled="False"
PlaceholderText="保存目录"
TextChanged="TextBoxPath_TextChanged" />
IsEditable="True" />

</Grid>

Expand Down
28 changes: 14 additions & 14 deletions Aria2Fast/View/AddSubscriptionView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


}


Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
});

Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions Aria2Fast/View/AddTaskView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>

<ui:TextBox
<ComboBox
x:Name="PathComboBox"
Grid.Column="2"
Padding="10,5,10,5"
IsEditable="True" />

<!--<ui:TextBox
x:Name="TextBoxPath"
Grid.Column="2"
Padding="10,5,10,5"
ClearButtonEnabled="False"
PlaceholderText="保存目录"
TextChanged="TextBoxPath_TextChanged" />
TextChanged="TextBoxPath_TextChanged" />-->
</Grid>
</Border>
<Border
Expand Down
Loading

0 comments on commit e196fa7

Please sign in to comment.