mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-06-04 11:05:50 +08:00
create a setup builder impl from MicaSetup
This commit is contained in:
28
Build/MicaSetup/Helper/SimpleDownloadHelper.cs
Normal file
28
Build/MicaSetup/Helper/SimpleDownloadHelper.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace MicaSetup.Helper;
|
||||
|
||||
public static class SimpleDownloadHelper
|
||||
{
|
||||
public static bool DownloadFile(string address, string fileName, DownloadProgressChangedEventHandler callback = null!)
|
||||
{
|
||||
try
|
||||
{
|
||||
using WebClient client = new();
|
||||
client.DownloadProgressChanged += (sender, e) =>
|
||||
{
|
||||
Logger.Debug($"[DownloadFile] {address} saved to '{fileName}', {e.ProgressPercentage}% completed.");
|
||||
callback?.Invoke(sender, e);
|
||||
};
|
||||
|
||||
client.DownloadFile(address, fileName);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user