From 4b1a2c427ec5681b603da33a35c5cb15cea5c62a Mon Sep 17 00:00:00 2001 From: Markus Date: Thu, 19 Sep 2024 02:26:55 +0100 Subject: [PATCH] CoreConfig: Prevent "Error invoking callback" if core.json not found (#576) Thanks @markus-wa --- .../CounterStrikeSharp.API/Core/CoreConfig.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/managed/CounterStrikeSharp.API/Core/CoreConfig.cs b/managed/CounterStrikeSharp.API/Core/CoreConfig.cs index e7a1088ec..7771456bf 100644 --- a/managed/CounterStrikeSharp.API/Core/CoreConfig.cs +++ b/managed/CounterStrikeSharp.API/Core/CoreConfig.cs @@ -151,27 +151,28 @@ public void Load() _commandsRegistered = true; } - if (!File.Exists(_coreConfigPath)) + if (File.Exists(_coreConfigPath)) { - _logger.LogWarning( - "Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.", - _coreConfigPath); - return; - } - - try - { - var data = JsonSerializer.Deserialize(File.ReadAllText(_coreConfigPath), - new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip }); - - if (data != null) + try + { + var data = JsonSerializer.Deserialize(File.ReadAllText(_coreConfigPath), + new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip }); + + if (data != null) + { + _coreConfig = data; + } + } + catch (Exception ex) { - _coreConfig = data; + _logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used"); } } - catch (Exception ex) + else { - _logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used"); + _logger.LogWarning( + "Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.", + _coreConfigPath); } var serverCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)