Merge pull request #359 from gnh1201/dev
Some checks are pending
CodeQL / Analyze (javascript) (push) Waiting to run
Deploy Jekyll with GitHub Pages dependencies preinstalled / build (push) Waiting to run
Deploy Jekyll with GitHub Pages dependencies preinstalled / deploy (push) Blocked by required conditions

Add support *.dll.gz file in Assembly Loader
This commit is contained in:
Namhyeon Go 2025-12-06 00:46:24 +09:00 committed by GitHub
commit e5dd13fd1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,54 @@ namespace WelsonJS.Launcher
}
private static bool TryDownloadGzipToFile(string gzUrl, string dest)
{
string tempFile = dest + ".tmp";
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(tempFile, FileMode.Create, FileAccess.Write))
{
gz.CopyTo(fs);
}
File.Move(tempFile, dest);
return true;
}
}
catch (Exception ex)
{
Logger?.Warn("Failed to download or decompress gzipped file from {0}: {1}", gzUrl, ex.Message);
}
finally
{
if (File.Exists(tempFile))
{
try
{
File.Delete(tempFile);
}
catch (Exception ex)
{
Logger?.Info("Failed to delete temp file {0}: {1}", tempFile, ex.Message);
}
}
}
return false;
}
private static bool IsFrameworkAssembly(string name)
{
return name.StartsWith("System", StringComparison.OrdinalIgnoreCase) ||