2025-06-17 21:07:32 +03:00
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Nebula.Shared;
|
|
|
|
|
using Nebula.Shared.Models;
|
|
|
|
|
using Nebula.Shared.Services;
|
2025-12-06 23:25:25 +03:00
|
|
|
using Nebula.Shared.Utils;
|
2025-06-17 21:07:32 +03:00
|
|
|
|
|
|
|
|
namespace Nebula.Launcher.ProcessHelper;
|
|
|
|
|
|
|
|
|
|
[ServiceRegister]
|
2025-07-13 10:07:36 +03:00
|
|
|
public sealed class GameRunnerPreparer(IServiceProvider provider, ContentService contentService, EngineService engineService)
|
2025-06-17 21:07:32 +03:00
|
|
|
{
|
2025-12-11 21:47:54 +03:00
|
|
|
public async Task<GameProcessStartInfoProvider> GetGameProcessStartInfoProvider(RobustUrl address, ILoadingHandlerFactory loadingHandlerFactory, CancellationToken cancellationToken = default)
|
2025-06-17 21:07:32 +03:00
|
|
|
{
|
|
|
|
|
var buildInfo = await contentService.GetBuildInfo(address, cancellationToken);
|
|
|
|
|
|
2025-12-06 23:25:25 +03:00
|
|
|
var engine = await engineService.EnsureEngine(buildInfo.BuildInfo.Build.EngineVersion, loadingHandlerFactory, cancellationToken);
|
2025-06-17 21:07:32 +03:00
|
|
|
|
|
|
|
|
if (engine is null)
|
|
|
|
|
throw new Exception("Engine version not found: " + buildInfo.BuildInfo.Build.EngineVersion);
|
|
|
|
|
|
2026-01-16 21:02:34 +03:00
|
|
|
var hashApi = await contentService.EnsureItems(buildInfo, loadingHandlerFactory, cancellationToken);
|
2025-12-06 23:25:25 +03:00
|
|
|
|
|
|
|
|
if (hashApi.TryOpen("manifest.yml", out var stream))
|
|
|
|
|
{
|
|
|
|
|
var modules = ContentManifestParser.ExtractModules(stream);
|
|
|
|
|
|
|
|
|
|
foreach (var moduleStr in modules)
|
|
|
|
|
{
|
|
|
|
|
var module = await engineService.EnsureEngineModules(moduleStr, loadingHandlerFactory, buildInfo.BuildInfo.Build.EngineVersion);
|
|
|
|
|
if(module is null)
|
|
|
|
|
throw new Exception("Module not found: " + moduleStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await stream.DisposeAsync();
|
|
|
|
|
}
|
2025-06-17 21:07:32 +03:00
|
|
|
|
2025-12-11 21:47:54 +03:00
|
|
|
return
|
2025-06-17 21:07:32 +03:00
|
|
|
provider.GetService<GameProcessStartInfoProvider>()!.WithBuildInfo(buildInfo.BuildInfo.Auth.PublicKey,
|
|
|
|
|
address);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|