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.RenderThread_SizeChanged" />
<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>
<PackageReference Include="Basic.Reference.Assemblies.Net90" Version="1.8.0" />

View File

@@ -195,8 +195,11 @@ public class Launcher : ICorePlugin
private static void InitThreadPool()
{
#if DEBUG
ParallelTasks.Parallel.Scheduler = new ThreadPoolScheduler();
// MySandboxGame.InitMultithreading();
#else
MySandboxGame.InitMultithreading();
#endif
}
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 Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis;
using VRage.Scripting;
using CringeLauncher.SyntaxRewriters;
using VRage.Scripting.Rewriters;
namespace CringeLauncher.Patches;
[HarmonyPatch(typeof(MyScriptCompiler), "InjectMod")]
[HarmonyPatch(typeof(ProtoTagRewriter), "Rewrite")]
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);
compilation = compilation.ReplaceSyntaxTree(syntaxTree, fixedSyntaxTree);
syntaxTree = fixedSyntaxTree;
__result = MissingUsingRewriter.Rewrite(compilation, syntaxTree);
return false;
}
}

View File

@@ -2,12 +2,13 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Diagnostics;
using VRage.Scripting.Rewriters;
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 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)
{

View File

@@ -43,7 +43,7 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
var configPath = Path.Join(_dir.FullName, "packages.json");
if (File.Exists(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)
{
@@ -115,6 +115,14 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
{
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 path = Path.Join(dir, $"{package.Package.Id}.deps.json");
@@ -123,6 +131,8 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
try
{
await using var stream = File.Create(path);
//client should not be null for calls to this
await manifestBuilder.WriteDependencyManifestAsync(stream, package.Entry, _runtimeFramework);
}
catch (Exception ex)
@@ -133,7 +143,6 @@ public class PluginsLifetime(string gameFolder) : ILoadingStage
}
}
var client = await sourceMapping.GetClientAsync(package.Package.Id);
var sourceName = packagesConfig.Sources.First(b => b.Url == client.ToString()).Name;
LoadComponent(plugins, Path.Join(dir, $"{package.Package.Id}.dll"),
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);
if (client == null)
continue; //todo: check cached files. test with Internet disconnected
RegistrationRoot? registrationRoot;
try
@@ -67,7 +70,7 @@ public class PackageResolver(NuGetFramework runtimeFramework, ImmutableArray<Pac
{
var client = await packageSources.GetClientAsync(package.Id);
if (!catalogEntry.DependencyGroups.HasValue)
if (client == null || !catalogEntry.DependencyGroups.HasValue)
continue;
var nearestGroup = NuGetFrameworkUtility.GetNearest(catalogEntry.DependencyGroups.Value, runtimeFramework,
@@ -93,6 +96,9 @@ public class PackageResolver(NuGetFramework runtimeFramework, ImmutableArray<Pac
{
var client = await packageSources.GetClientAsync(id);
if (client == null)
continue;
RegistrationRoot? registrationRoot;
try

View File

@@ -512,7 +512,7 @@ internal class PluginListComponent : IRenderComponent
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;
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();

View File

@@ -97,25 +97,43 @@ public class NuGetClient
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
{
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");
const int MaxRetries = 10;
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
for (var i = 0; i < MaxRetries; i++)
{
try
{
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
return new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
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();

View File

@@ -7,19 +7,19 @@ namespace NuGet;
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 =>
(b.Pattern,
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;
public ConfiguredCancelableAsyncEnumerable<NuGetClient>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
public ConfiguredCancelableAsyncEnumerable<NuGetClient?>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return _clients.ToAsyncEnumerable()
.SelectAwait(b => new ValueTask<NuGetClient>(b.client))
.SelectAwait(b => new ValueTask<NuGetClient?>(b.client))
.WithCancellation(cancellationToken)
.GetAsyncEnumerator();
}