Refactor settings and enhance download manager

Refactor application to use SettingService for managing settings.
Update project to target Windows desktop application.
Enhance DownloadManagerService for better task handling.
Add new dependencies and remove obsolete settings files.
Improve UI feedback and notifications for user actions.
This commit is contained in:
Misaki
2024-07-05 01:56:38 +09:00
parent 4acbd6ba49
commit 939637cc96
28 changed files with 542 additions and 261 deletions

View File

@@ -1,4 +1,5 @@
using DownloadManager.Utilities;
using System.IO;
namespace DownloadManager.Models.UrlGetter
{
@@ -6,8 +7,15 @@ namespace DownloadManager.Models.UrlGetter
{
public async Task<FileUrl> GetFileUrl(string taskUrl)
{
var fileName = System.IO.Path.GetFileName(taskUrl).ToUnescapedString();
string? fileName = null;
await Task.Run(() =>
{
var extension = Path.GetExtension(taskUrl);
fileName = string.IsNullOrEmpty(extension) ? "index.html" : Path.GetFileName(taskUrl).ToUnescapedString();
});
return new FileUrl(taskUrl, fileName, null);
}
}
}
}

View File

@@ -7,7 +7,7 @@
return type switch
{
UrlGetterType.Direct => new DirectUrlGetter(),
UrlGetterType.Yande => new YandeUrlGetter(),
UrlGetterType.YandePost => new YandeUrlGetter(),
_ => throw new ArgumentException("Invalid UrlGetterType"),
};
}

View File

@@ -7,6 +7,6 @@ namespace DownloadManager.Models.UrlGetter
[Description("Direct")]
Direct,
[Description("Yande post URL")]
Yande,
YandePost,
}
}

View File

@@ -13,6 +13,9 @@ public class YandeUrlGetter : IUrlGetter
public async Task<FileUrl> GetFileUrl(string taskUrl)
{
if (!taskUrl.StartsWith("https://yande.re/post/show/"))
return new FileUrl(null, null, null);
// Get the ID of the post from the URL
var id = taskUrl.Split("https://yande.re/post/show/").Last();

18
Models/UserSetting.cs Normal file
View File

@@ -0,0 +1,18 @@
using Wpf.Ui.Appearance;
using Wpf.Ui.Controls;
namespace DownloadManager.Models
{
public class UserSetting
{
public ApplicationTheme Theme { get; set; } = ApplicationTheme.Dark;
public WindowBackdropType Backdrop { get; set; } = WindowBackdropType.Mica;
public string DefaultSaveLocation { get; set; } = string.Empty;
public int SplitCount { get; set; } = 1;
public bool UseParallelDownload { get; set; } = false;
public int RetryCount { get; set; } = 5;
public int MaxActiveDownloadCount { get; set; } = 3;
public bool SystemNotification { get; set; } = true;
}
}