Repository URL to install this package:
|
Version:
1.3.1 ▾
|
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Fluctio.FluctioSim.EditorUtils.EditorGeneral;
namespace Fluctio.FluctioSim.EditorUtils.OperatingSystem
{
public static class Downloader
{
private static readonly HttpClient HttpClient = new();
public static string GetDownloadPath(string url)
{
var filename = Path.GetFileName(url);
var downloadPath = Path.Combine(Platform.DownloadsFolderPath, filename);
return downloadPath;
}
public static async Task DownloadFile(string url)
{
var taskName = $"Download {Path.GetFileName(url)}";
var progress = new UnityProgress(taskName, async progress =>
{
// TODO: add progress reporting
var targetPath = GetDownloadPath(url);
await using var stream = await HttpClient.GetStreamAsync(url);
Directory.CreateDirectory(Platform.DownloadsFolderPath);
await using var fs = File.Create(targetPath);
await stream.CopyToAsync(fs);
});
await progress.RunAsync();
}
}
}