mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-12-05 22:04:43 +00:00
Add support *.dll.gz file in Assembly Loader
Add support for *.dll.gz files in Assembly Loader to make downloads faster.
This commit is contained in:
parent
7abf705c6e
commit
4e3c2bc52c
|
|
@ -6,6 +6,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
|
|
@ -322,19 +323,29 @@ namespace WelsonJS.Launcher
|
|||
|
||||
try
|
||||
{
|
||||
res = Http.GetAsync(url).GetAwaiter().GetResult();
|
||||
if (res.StatusCode == HttpStatusCode.NotFound)
|
||||
string gzUrl = url + ".gz";
|
||||
bool isDll = url.EndsWith(".dll", StringComparison.OrdinalIgnoreCase); // *.dll.gz
|
||||
bool downloaded = false;
|
||||
|
||||
if (isDll && TryDownloadGzipToFile(gzUrl, dest))
|
||||
{
|
||||
Logger.Warn("404 Not Found for {0}", url);
|
||||
return;
|
||||
Logger.Info("Downloaded and decompressed gzip file to: {0}", dest);
|
||||
downloaded = true;
|
||||
}
|
||||
|
||||
res.EnsureSuccessStatusCode();
|
||||
|
||||
using (Stream s = res.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
|
||||
using (FileStream fs = new FileStream(dest, FileMode.Create, FileAccess.Write))
|
||||
if (!downloaded)
|
||||
{
|
||||
s.CopyTo(fs);
|
||||
Logger.Info("Downloading file from: {0}", url);
|
||||
res = Http.GetAsync(url).GetAwaiter().GetResult();
|
||||
res.EnsureSuccessStatusCode();
|
||||
|
||||
using (Stream s = res.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
|
||||
using (var fs = new FileStream(dest, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
s.CopyTo(fs);
|
||||
}
|
||||
|
||||
Logger.Info("Downloaded file to: {0}", dest);
|
||||
}
|
||||
|
||||
if (!File.Exists(dest))
|
||||
|
|
@ -342,11 +353,6 @@ namespace WelsonJS.Launcher
|
|||
throw new FileNotFoundException("File not found after download", dest);
|
||||
}
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
Logger.Error("HTTP error for {0}: {1}", url, ex.Message);
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("Error downloading {0}: {1}", url, ex.Message);
|
||||
|
|
@ -359,6 +365,34 @@ namespace WelsonJS.Launcher
|
|||
}
|
||||
|
||||
|
||||
private static bool TryDownloadGzipToFile(string gzUrl, string dest)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var res = Http.GetAsync(gzUrl).GetAwaiter().GetResult())
|
||||
{
|
||||
if (res.StatusCode == HttpStatusCode.NotFound)
|
||||
return false;
|
||||
|
||||
res.EnsureSuccessStatusCode();
|
||||
|
||||
using (Stream s = res.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
|
||||
using (var gz = new GZipStream(s, CompressionMode.Decompress))
|
||||
using (var fs = new FileStream(dest, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
gz.CopyTo(fs);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static bool IsFrameworkAssembly(string name)
|
||||
{
|
||||
return name.StartsWith("System", StringComparison.OrdinalIgnoreCase) ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user