using System.Net; namespace PluginLoader.Network; public static class GitHub { public const string listRepoName = "sepluginloader/PluginHub"; public const string listRepoCommit = "main"; public const string listRepoHash = "plugins.sha1"; private const string repoZipUrl = "https://github.com/{0}/archive/{1}.zip"; private const string rawUrl = "https://raw.githubusercontent.com/{0}/{1}/"; private static readonly HttpClient Client = new(); public static Stream DownloadRepo(string name, string commit, out string? fileName) { var uri = new Uri(string.Format(repoZipUrl, name, commit), UriKind.Absolute); LogFile.Log.Debug("Downloading {Uri}", uri); using var response = Client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result; fileName = response.Content.Headers.ContentDisposition?.FileName; using var stream = response.Content.ReadAsStream(); var mem = new MemoryStream(); stream.CopyTo(mem); mem.Position = 0; return mem; } public static Stream DownloadFile(string name, string commit, string path) { var uri = new Uri(string.Format(rawUrl, name, commit) + path.TrimStart('/'), UriKind.Absolute); LogFile.Log.Debug("Downloading {Uri}", uri); return Client.GetStreamAsync(uri).Result; } }