create a setup builder impl from MicaSetup

This commit is contained in:
ema
2023-12-04 01:36:02 +08:00
parent edc597a19a
commit a6891e29dc
465 changed files with 34946 additions and 75 deletions

View 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;
}
}