update logging and add pl splash as the main one
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
All checks were successful
Build / Build Launcher (push) Successful in 2m31s
This commit is contained in:
@@ -11,38 +11,27 @@ public static class GitHub
|
||||
private const string repoZipUrl = "https://github.com/{0}/archive/{1}.zip";
|
||||
private const string rawUrl = "https://raw.githubusercontent.com/{0}/{1}/";
|
||||
|
||||
public static Stream DownloadRepo(string name, string commit, out string fileName)
|
||||
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.WriteLine("Downloading " + uri);
|
||||
var request = WebRequest.CreateHttp(uri);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
request.Timeout = Main.Instance.Config.NetworkTimeout;
|
||||
LogFile.Log.Debug("Downloading {Uri}", uri);
|
||||
using var response = Client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead).Result;
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
fileName = response.Headers["Content-Disposition"];
|
||||
if (fileName != null)
|
||||
{
|
||||
var index = fileName.IndexOf("filename=");
|
||||
if (index >= 0)
|
||||
{
|
||||
index += "filename=".Length;
|
||||
fileName = fileName.Substring(index).Trim('"');
|
||||
}
|
||||
}
|
||||
fileName = response.Content.Headers.ContentDisposition?.FileName;
|
||||
|
||||
return response.GetResponseStream();
|
||||
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.WriteLine("Downloading " + uri);
|
||||
var request = WebRequest.CreateHttp(uri);
|
||||
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||
request.Timeout = Main.Instance.Config.NetworkTimeout;
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
return response.GetResponseStream();
|
||||
LogFile.Log.Debug("Downloading {Uri}", uri);
|
||||
return Client.GetStreamAsync(uri).Result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user