Files
se-launcher/PluginLoader/Network/GitHub.cs
zznty fbf02ad716
All checks were successful
Build / Build Launcher (push) Successful in 2m17s
move client mods updates to actual steam api
2024-05-31 17:56:24 +07:00

35 lines
1.3 KiB
C#

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