Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreConfig: Prevent "Error invoking callback" if core.json not found #576

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions managed/CounterStrikeSharp.API/Core/CoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreConfigData>(File.ReadAllText(_coreConfigPath),
new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip });

if (data != null)
try
{
var data = JsonSerializer.Deserialize<CoreConfigData>(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)
Expand Down
Loading