From 52beaaa5e233183f327222231cf11bad1e2be3ca Mon Sep 17 00:00:00 2001 From: Cinka Date: Wed, 29 Jan 2025 12:46:23 +0300 Subject: [PATCH] - add: FallBack think --- Nebula.Shared/CurrentConVar.cs | 6 +++ Nebula.Shared/Services/EngineService.cs | 52 ++++++++++++++++++++----- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Nebula.Shared/CurrentConVar.cs b/Nebula.Shared/CurrentConVar.cs index 5f06b2c..a9c8762 100644 --- a/Nebula.Shared/CurrentConVar.cs +++ b/Nebula.Shared/CurrentConVar.cs @@ -1,3 +1,4 @@ +using Nebula.Shared.Models; using Nebula.Shared.Services; namespace Nebula.Shared; @@ -32,4 +33,9 @@ public static class CurrentConVar public static readonly ConVar Favorites = ConVarBuilder.Build("server.favorites", []); + + public static readonly ConVar> EngineManifestBackup = + ConVarBuilder.Build>("engine.manifest.backup"); + public static readonly ConVar ModuleManifestBackup = + ConVarBuilder.Build("module.manifest.backup"); } \ No newline at end of file diff --git a/Nebula.Shared/Services/EngineService.cs b/Nebula.Shared/Services/EngineService.cs index 273561c..b80f6fd 100644 --- a/Nebula.Shared/Services/EngineService.cs +++ b/Nebula.Shared/Services/EngineService.cs @@ -35,18 +35,52 @@ public sealed class EngineService public async Task LoadEngineManifest(CancellationToken cancellationToken) { - var info = await _restService.GetAsync>( - new Uri(_varService.GetConfigValue(CurrentConVar.EngineManifestUrl)!), cancellationToken); - var moduleInfo = await _restService.GetAsync( - new Uri(_varService.GetConfigValue(CurrentConVar.EngineModuleManifestUrl)!), cancellationToken); + try + { + _debugService.Log("Fetching engine manifest from: " + CurrentConVar.EngineManifestUrl); + var info = await _restService.GetAsync>( + new Uri(_varService.GetConfigValue(CurrentConVar.EngineManifestUrl)!), cancellationToken); + if (info.Value is null) + throw new Exception("Engine version info is null"); - if (info.Value is null) return; - VersionInfos = info.Value; + VersionInfos = info.Value; + + _varService.SetConfigValue(CurrentConVar.EngineManifestBackup, info.Value); + } + catch (Exception e) + { + _debugService.Debug("Trying fallback engine manifest..."); + if (!_varService.TryGetConfigValue(CurrentConVar.EngineManifestBackup, out var engineInfo)) + { + throw new Exception("No engine info data available",e); + } - if (moduleInfo.Value is null) return; - ModuleInfos = moduleInfo.Value.Modules; + VersionInfos = engineInfo; + } - foreach (var f in ModuleInfos.Keys) _debugService.Debug(f); + try + { + _debugService.Log("Fetching module manifest from: " + CurrentConVar.EngineModuleManifestUrl); + var moduleInfo = await _restService.GetAsync( + new Uri(_varService.GetConfigValue(CurrentConVar.EngineModuleManifestUrl)!), cancellationToken); + + if (moduleInfo.Value is null) + throw new Exception("Module version info is null"); + + ModuleInfos = moduleInfo.Value.Modules; + _varService.SetConfigValue(CurrentConVar.ModuleManifestBackup, moduleInfo.Value); + } + catch (Exception e) + { + _debugService.Debug("Trying fallback module manifest..."); + if (!_varService.TryGetConfigValue(CurrentConVar.ModuleManifestBackup, out var modulesInfo)) + { + throw new Exception("No module info data available",e); + } + + ModuleInfos = modulesInfo.Modules; + } + } public EngineBuildInfo? GetVersionInfo(string version)