Retry source requests
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m4s
Build / Build Nuget package (NuGet) (push) Successful in 1m6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m10s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m18s
Build / Build Launcher (push) Successful in 1m54s

Handle missing sources
Minor Optimizations
Move thread pool improvement to debug while we fix it
This commit is contained in:
2025-06-01 11:11:50 -04:00
parent 2f492d9ed1
commit b12f1cc2f1
11 changed files with 72 additions and 54 deletions

View File

@@ -19,7 +19,8 @@
<Publicize Include="Sandbox.Game:Sandbox.MySandboxGame.form" /> <Publicize Include="Sandbox.Game:Sandbox.MySandboxGame.form" />
<Publicize Include="Sandbox.Game:Sandbox.MySandboxGame.RenderThread_SizeChanged" /> <Publicize Include="Sandbox.Game:Sandbox.MySandboxGame.RenderThread_SizeChanged" />
<Publicize Include="VRage.Render;VRage.Render11;VRage.Platform.Windows;VRage.Scripting;VRage.Input" IncludeCompilerGeneratedMembers="false" /> <Publicize Include="VRage.Render;VRage.Render11;VRage.Platform.Windows;VRage.Scripting;VRage.Input" IncludeCompilerGeneratedMembers="false" />
</ItemGroup> <Publicize Include="VRage.Scripting:VRage.Scripting.Rewriters.ProtoTagRewriter" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.Net90" Version="1.8.0" /> <PackageReference Include="Basic.Reference.Assemblies.Net90" Version="1.8.0" />

View File

@@ -195,8 +195,11 @@ public class Launcher : ICorePlugin
private static void InitThreadPool() private static void InitThreadPool()
{ {
#if DEBUG
ParallelTasks.Parallel.Scheduler = new ThreadPoolScheduler(); ParallelTasks.Parallel.Scheduler = new ThreadPoolScheduler();
// MySandboxGame.InitMultithreading(); #else
MySandboxGame.InitMultithreading();
#endif
} }
private static void ConfigureSettings() private static void ConfigureSettings()

View File

@@ -1,21 +0,0 @@
using HarmonyLib;
using Sandbox.Game.World;
namespace CringeLauncher.Patches;
[HarmonyPatch(typeof(MyScriptManager), nameof(MyScriptManager.Init))]
public static class DarkTardMissingNamespacePatch
{
private static void Prefix(Dictionary<string, string> ___m_compatibilityChanges)
{
___m_compatibilityChanges["using System.Runtime.Remoting.Metadata.W3cXsd2001;"] = "";
___m_compatibilityChanges["using System.IO.Ports;"] = "";
___m_compatibilityChanges["using System.Runtime.Remoting;"] = "";
___m_compatibilityChanges["using System.Runtime.Remoting.Messaging;"] = "";
___m_compatibilityChanges["using System.Numerics;"] = "";
___m_compatibilityChanges["using System.Runtime.Remoting.Lifetime;"] = "";
___m_compatibilityChanges["using System.Net.Configuration;"] = "";
___m_compatibilityChanges["using System.Reflection.Metadata.Ecma335;"] = "";
___m_compatibilityChanges["using Microsoft.VisualBasic;"] = "";
}
}

View File

@@ -1,18 +1,18 @@
using HarmonyLib; using HarmonyLib;
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using VRage.Scripting;
using CringeLauncher.SyntaxRewriters; using CringeLauncher.SyntaxRewriters;
using VRage.Scripting.Rewriters;
namespace CringeLauncher.Patches; namespace CringeLauncher.Patches;
[HarmonyPatch(typeof(MyScriptCompiler), "InjectMod")] [HarmonyPatch(typeof(ProtoTagRewriter), "Rewrite")]
internal static class ModRewriterPatch internal static class ModRewriterPatch
{ {
public static void Prefix(ref CSharpCompilation compilation, ref SyntaxTree syntaxTree) public static bool Prefix(CSharpCompilation compilation, SyntaxTree syntaxTree, ref SyntaxTree __result)
{ {
var fixedSyntaxTree = MissingUsingRewriter.Rewrite(compilation, syntaxTree); __result = MissingUsingRewriter.Rewrite(compilation, syntaxTree);
compilation = compilation.ReplaceSyntaxTree(syntaxTree, fixedSyntaxTree);
syntaxTree = fixedSyntaxTree; return false;
} }
} }

View File

@@ -2,12 +2,13 @@
using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Diagnostics; using System.Diagnostics;
using VRage.Scripting.Rewriters;
namespace CringeLauncher.SyntaxRewriters; namespace CringeLauncher.SyntaxRewriters;
internal sealed class MissingUsingRewriter : CSharpSyntaxRewriter internal sealed class MissingUsingRewriter : ProtoTagRewriter //use existing rewriter to prevent another iteration
{ {
private readonly SemanticModel _semanticModel; private readonly SemanticModel _semanticModel;
private MissingUsingRewriter(CSharpCompilation compilation, SyntaxTree tree) => _semanticModel = compilation.GetSemanticModel(tree); private MissingUsingRewriter(CSharpCompilation compilation, SyntaxTree tree) : base(compilation, tree) => _semanticModel = compilation.GetSemanticModel(tree);
public static SyntaxTree Rewrite(CSharpCompilation compilation, SyntaxTree tree) public static SyntaxTree Rewrite(CSharpCompilation compilation, SyntaxTree tree)
{ {

View File

@@ -43,7 +43,7 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
var configPath = Path.Join(_dir.FullName, "packages.json"); var configPath = Path.Join(_dir.FullName, "packages.json");
if (File.Exists(configPath)) if (File.Exists(configPath))
await using (var stream = File.OpenRead(configPath)) await using (var stream = File.OpenRead(configPath))
packagesConfig = JsonSerializer.Deserialize<PackagesConfig>(stream, NuGetClient.SerializerOptions)!; packagesConfig = await JsonSerializer.DeserializeAsync<PackagesConfig>(stream, NuGetClient.SerializerOptions)!;
if (packagesConfig == null) if (packagesConfig == null)
{ {
@@ -114,7 +114,15 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
foreach (var package in packages) foreach (var package in packages)
{ {
if (builtInPackages.ContainsKey(package.Package.Id)) continue; if (builtInPackages.ContainsKey(package.Package.Id)) continue;
var client = await sourceMapping.GetClientAsync(package.Package.Id);
if (client == null)
{
Log.Warn("Client not found for {Package}", package.Package.Id);
continue;
}
var dir = Path.Join(package.Directory.FullName, "lib", package.ResolvedFramework.GetShortFolderName()); var dir = Path.Join(package.Directory.FullName, "lib", package.ResolvedFramework.GetShortFolderName());
var path = Path.Join(dir, $"{package.Package.Id}.deps.json"); var path = Path.Join(dir, $"{package.Package.Id}.deps.json");
@@ -123,6 +131,8 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
try try
{ {
await using var stream = File.Create(path); await using var stream = File.Create(path);
//client should not be null for calls to this
await manifestBuilder.WriteDependencyManifestAsync(stream, package.Entry, _runtimeFramework); await manifestBuilder.WriteDependencyManifestAsync(stream, package.Entry, _runtimeFramework);
} }
catch (Exception ex) catch (Exception ex)
@@ -132,8 +142,7 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
throw; throw;
} }
} }
var client = await sourceMapping.GetClientAsync(package.Package.Id);
var sourceName = packagesConfig.Sources.First(b => b.Url == client.ToString()).Name; var sourceName = packagesConfig.Sources.First(b => b.Url == client.ToString()).Name;
LoadComponent(plugins, Path.Join(dir, $"{package.Package.Id}.dll"), LoadComponent(plugins, Path.Join(dir, $"{package.Package.Id}.dll"),
new(package.Package.Id, package.Package.Version, sourceName)); new(package.Package.Id, package.Package.Version, sourceName));

View File

@@ -20,6 +20,9 @@ public class PackageResolver(NuGetFramework runtimeFramework, ImmutableArray<Pac
{ {
var client = await packageSources.GetClientAsync(reference.Id); var client = await packageSources.GetClientAsync(reference.Id);
if (client == null)
continue; //todo: check cached files. test with Internet disconnected
RegistrationRoot? registrationRoot; RegistrationRoot? registrationRoot;
try try
@@ -67,7 +70,7 @@ public class PackageResolver(NuGetFramework runtimeFramework, ImmutableArray<Pac
{ {
var client = await packageSources.GetClientAsync(package.Id); var client = await packageSources.GetClientAsync(package.Id);
if (!catalogEntry.DependencyGroups.HasValue) if (client == null || !catalogEntry.DependencyGroups.HasValue)
continue; continue;
var nearestGroup = NuGetFrameworkUtility.GetNearest(catalogEntry.DependencyGroups.Value, runtimeFramework, var nearestGroup = NuGetFrameworkUtility.GetNearest(catalogEntry.DependencyGroups.Value, runtimeFramework,
@@ -92,6 +95,9 @@ public class PackageResolver(NuGetFramework runtimeFramework, ImmutableArray<Pac
foreach (var (id, versionRange) in dependencies) foreach (var (id, versionRange) in dependencies)
{ {
var client = await packageSources.GetClientAsync(id); var client = await packageSources.GetClientAsync(id);
if (client == null)
continue;
RegistrationRoot? registrationRoot; RegistrationRoot? registrationRoot;

View File

@@ -512,7 +512,7 @@ internal class PluginListComponent : IRenderComponent
await foreach (var source in _sourceMapping) await foreach (var source in _sourceMapping)
{ {
if (_selectedSources is not null && _selectedSources.All(b => b.Url != source.ToString())) if (source == null || _selectedSources is not null && _selectedSources.All(b => b.Url != source.ToString()))
continue; continue;
try try

View File

@@ -149,7 +149,8 @@ public class DependencyManifestBuilder(DirectoryInfo cacheDirectory, PackageSour
]; ];
} }
var client = await packageSources.GetClientAsync(entry.Id); //don't call this method if client is null
var client = await packageSources.GetClientAsync(entry.Id)!;
dir.Create(); dir.Create();

View File

@@ -97,25 +97,43 @@ public class NuGetClient
return _client.GetFromJsonAsync<SearchResult>(builder.Uri, SerializerOptions)!; return _client.GetFromJsonAsync<SearchResult>(builder.Uri, SerializerOptions)!;
} }
public static async Task<NuGetClient> CreateFromIndexUrlAsync(string indexUrl) public static async Task<NuGetClient?> CreateFromIndexUrlAsync(string indexUrl)
{ {
var client = new HttpClient(new HttpClientHandler var client = new HttpClient(new HttpClientHandler
{ {
AutomaticDecompression = DecompressionMethods.All AutomaticDecompression = DecompressionMethods.All,
}); });
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions); NuGetClient? ngClient = null;
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
if (!packageBaseAddress.EndsWith('/')) const int MaxRetries = 10;
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
return new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search)); for (var i = 0; i < MaxRetries; i++)
{
try
{
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
ngClient = new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
break;
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.Message);
}
}
return ngClient;
} }
public override string ToString() => _index.ToString(); public override string ToString() => _index.ToString();

View File

@@ -7,19 +7,19 @@ namespace NuGet;
public class PackageSourceMapping(ImmutableArray<PackageSource> sources) public class PackageSourceMapping(ImmutableArray<PackageSource> sources)
{ {
private readonly ImmutableArray<(string pattern, Task<NuGetClient> client)> _clients = [ private readonly ImmutableArray<(string pattern, Task<NuGetClient?> client)> _clients = [
..sources.Select(b => ..sources.Select(b =>
(b.Pattern, (b.Pattern,
NuGetClient.CreateFromIndexUrlAsync(b.Url))) NuGetClient.CreateFromIndexUrlAsync(b.Url)))
]; ];
public Task<NuGetClient> GetClientAsync(string packageId) => public Task<NuGetClient?> GetClientAsync(string packageId) =>
_clients.FirstOrDefault(b => Regex.IsMatch(packageId, b.pattern)).client; _clients.FirstOrDefault(b => Regex.IsMatch(packageId, b.pattern)).client;
public ConfiguredCancelableAsyncEnumerable<NuGetClient>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) public ConfiguredCancelableAsyncEnumerable<NuGetClient?>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
{ {
return _clients.ToAsyncEnumerable() return _clients.ToAsyncEnumerable()
.SelectAwait(b => new ValueTask<NuGetClient>(b.client)) .SelectAwait(b => new ValueTask<NuGetClient?>(b.client))
.WithCancellation(cancellationToken) .WithCancellation(cancellationToken)
.GetAsyncEnumerator(); .GetAsyncEnumerator();
} }