Use new web api for serving online dependencies

* Resolves #1675
* Resolves #1688
This commit is contained in:
ds5678 2025-03-08 11:18:34 -08:00
parent 431d69cd8c
commit ed32e738d0
5 changed files with 146 additions and 11 deletions

View File

@ -0,0 +1,18 @@
using static AssetRipper.Import.AssetRipperRuntimeInformation;
namespace AssetRipper.GUI.Web;
internal static class HttpClientBuilder
{
internal static HttpClient CreateHttpClient()
{
string productName = GameFileLoader.Premium ? "AssetRipper.GUI.Premium" : "AssetRipper.GUI.Free";
HttpClient client = new();
client.DefaultRequestHeaders.UserAgent.Add(new(productName, Build.Version));
client.DefaultRequestHeaders.UserAgent.Add(new($"({Build.Configuration}; {ProcessArchitecture}; {Build.Type})"));
client.DefaultRequestHeaders.UserAgent.Add(new($"({OS.Name}; {OS.Version}; {RamQuantity})"));
client.DefaultRequestHeaders.UserAgent.Add(new($"({CompileTime})"));
return client;
}
}

View File

@ -15,8 +15,8 @@ internal static class OnlineDependencies
/// </summary>
internal static class Babylon
{
public const string SourceMain = "https://cdn.babylonjs.com/babylon.js";
public const string SourceLoader = "https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js";
public const string SourceMain = "https://assetripper.com/files/babylon/7.0.0/main";
public const string SourceLoader = "https://assetripper.com/files/babylon/7.0.0/loader";
public const string PathMain = "/js/babylon.js";
public const string PathLoader = "/js/babylonjs.loaders.min.js";
@ -38,7 +38,7 @@ internal static class OnlineDependencies
/// </summary>
internal static class Bootstrap
{
public const string SourceMain = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css";
public const string SourceMain = "https://assetripper.com/files/bootstrap/5.3.2/css";
public const string IntegrityMain = "sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN";
public const string PathMain = "/css/bootstrap.min.css";
@ -53,7 +53,7 @@ internal static class OnlineDependencies
}.Close();
}
public const string SourceBundle = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js";
public const string SourceBundle = "https://assetripper.com/files/bootstrap/5.3.2/js";
public const string IntegrityBundle = "sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL";
public const string PathBundle = "/js/bootstrap.bundle.min.js";
@ -79,7 +79,7 @@ internal static class OnlineDependencies
/// </summary>
internal static class Popper
{
public const string Source = "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js";
public const string Source = "https://assetripper.com/files/popper/2.11.8/js";
public const string Integrity = "sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r";
public const string Path = "/js/popper.min.js";
@ -104,8 +104,8 @@ internal static class OnlineDependencies
/// </summary>
internal static class Vue
{
public const string Development = "https://unpkg.com/vue@3/dist/vue.global.js";
public const string Production = "https://unpkg.com/vue@3/dist/vue.global.prod.js";
public const string Development = "https://assetripper.com/files/vue/3.5.13/dev";
public const string Production = "https://assetripper.com/files/vue/3.5.13/prod";
public const string Path = "/js/vue.js";
internal static void WriteScriptReference(TextWriter writer)

View File

@ -46,9 +46,7 @@ public static partial class StaticContentLoader
}
else
{
using HttpClient client = new();
client.DefaultRequestHeaders.UserAgent.Add(new("AssetRipper", AssetRipperRuntimeInformation.Build.Version));
client.DefaultRequestHeaders.UserAgent.Add(new($"({AssetRipperRuntimeInformation.OS.Name}; {AssetRipperRuntimeInformation.ProcessArchitecture})"));
using HttpClient client = HttpClientBuilder.CreateHttpClient();
byte[] data;
HttpResponseMessage response = await client.GetAsync(source);

View File

@ -4,6 +4,7 @@
<IsTrimmable>true</IsTrimmable>
<OutputPath>..\0Bins\Other\AssetRipper.Import\$(Configuration)\</OutputPath>
<IntermediateOutputPath>..\0Bins\obj\AssetRipper.Import\$(Configuration)\</IntermediateOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>

View File

@ -1,11 +1,13 @@
using AssetRipper.Import.Utils;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
namespace AssetRipper.Import;
public static class AssetRipperRuntimeInformation
public static partial class AssetRipperRuntimeInformation
{
public static class Build
{
@ -21,8 +23,14 @@ public static class AssetRipperRuntimeInformation
}
}
/// <summary>
/// Either "Debug" or "Release"
/// </summary>
public static string Configuration => Debug ? "Debug" : "Release";
/// <summary>
/// Either "Compiled" or "Published"
/// </summary>
public static string Type => File.Exists(ExecutingDirectory.Combine("AssetRipper.Assets.dll")) ? "Compiled" : "Published";
public static string? Version => typeof(AssetRipperRuntimeInformation).Assembly.GetName().Version?.ToString();
@ -110,6 +118,13 @@ public static class AssetRipperRuntimeInformation
}
}
/// <summary>
/// Get the time the application was compiled.
/// </summary>
/// <remarks>
/// This format matches the format used in <see cref="CurrentTime"/>
/// </remarks>
/// <returns>A string like "Thu Nov 24 18:39:37 UTC 2022"</returns>
public static string CompileTime
{
get
@ -169,4 +184,107 @@ public static class AssetRipperRuntimeInformation
public static string Version => Environment.OSVersion.VersionString;
}
public static string RamQuantity
{
get
{
if (TryGetSystemMemory(out long totalMemoryInKilobytes))
{
return $"{totalMemoryInKilobytes / 1024 / 1024} GB";
}
else
{
return "Unknown GB";
}
}
}
private static bool TryGetSystemMemory(out long totalMemoryInKilobytes)
{
if (OperatingSystem.IsWindows())
{
return TryGetSystemMemoryWindows(out totalMemoryInKilobytes);
}
else if (OperatingSystem.IsLinux())
{
return TryGetSystemMemoryLinux(out totalMemoryInKilobytes);
}
else if (OperatingSystem.IsMacOS())
{
return TryGetSystemMemoryMacOS(out totalMemoryInKilobytes);
}
else
{
totalMemoryInKilobytes = default;
return false;
}
}
[SupportedOSPlatform("windows")]
[LibraryImport("kernel32.dll", EntryPoint = "GetPhysicallyInstalledSystemMemory")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool TryGetSystemMemoryWindows(out long totalMemoryInKilobytes);
[SupportedOSPlatform("macos")]
private static bool TryGetSystemMemoryMacOS(out long totalMemoryInKilobytes)
{
try
{
using Process process = new()
{
StartInfo = new ProcessStartInfo
{
FileName = "/usr/sbin/sysctl",
Arguments = "hw.memsize",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// Output is in format: hw.memsize: 17179869184
string[] parts = output.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 2 && long.TryParse(parts[1], out long memoryInBytes))
{
totalMemoryInKilobytes = memoryInBytes / 1024;
return true;
}
}
catch
{
}
totalMemoryInKilobytes = default;
return false;
}
[SupportedOSPlatform("linux")]
private static bool TryGetSystemMemoryLinux(out long totalMemoryInKilobytes)
{
totalMemoryInKilobytes = 0;
try
{
using StreamReader reader = new("/proc/meminfo");
string? line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("MemTotal:", StringComparison.Ordinal))
{
string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 3 && long.TryParse(parts[1], out long memoryInKilobytes))
{
totalMemoryInKilobytes = memoryInKilobytes;
return true;
}
}
}
}
catch
{
}
return false;
}
}