ZeroLauncher/dialog/DownloadControl.xaml.cs
2024-03-09 18:29:16 +08:00

68 lines
2.3 KiB
C#

using Downloader;
using System.ComponentModel;
using System.Windows.Controls;
namespace Zerolauncher.dialog
{
/// <summary>
/// DownloadControl.xaml 的交互逻辑
/// </summary>
public partial class DownloadControl1 : UserControl
{
const string cache_dir = "./.cache/auto.cache";
static bool is_strat = false;
public DownloadControl1()
{
InitializeComponent();
if (!is_strat) text2.Text = "正在连接服务器";
}
public static void DoDownload(string fileUrl)
{
var downloadOpt = new DownloadConfiguration()
{
ChunkCount = 8, // file parts to download, the default value is 1
ParallelDownload = true // download parts of the file as parallel or not. The default value is false
};
var downloader = new DownloadService(downloadOpt);
// Provide `FileName` and `TotalBytesToReceive` at the start of each download
downloader.DownloadStarted += OnDownloadStarted;
// Provide any information about download progress,
// like progress percentage of sum of chunks, total speed,
// average speed, total received bytes and received bytes array
// to live streaming.
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
// Download completed event that can include errors or
// canceled or download completed successfully.
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
}
private static void OnDownloadFileCompleted(object? sender, AsyncCompletedEventArgs e)
{
}
private static void OnDownloadProgressChanged(object? sender, DownloadProgressChangedEventArgs e)
{
if (UpdateDialog.ui_enale)
{
UpdateDialog.editControl.pbDown.Value = e.ProgressPercentage;
UpdateDialog.editControl.text2.Text = $"{e.AverageBytesPerSecondSpeed}";
}
throw new NotImplementedException();
}
private static void OnDownloadStarted(object? sender, DownloadStartedEventArgs e)
{
is_strat = true;
if (UpdateDialog.ui_enale) UpdateDialog.editControl.text1.Text = "零蛋正在更新装备...";
}
}
}