Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
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();
		}
	}
}