Skip to content

Commit

Permalink
Unload module when module config file is corrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
RainOrigami committed Sep 7, 2023
1 parent 59438a4 commit 439f5c0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions BattleBitAPIRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,15 @@ private void ModuleConfiguration_OnLoadingRequest(object? sender, BattleBitModul
if (File.Exists(filePath))
{
configurationValue = JsonConvert.DeserializeObject(File.ReadAllText(filePath), property.PropertyType) as ModuleConfiguration;
if (configurationValue is null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Failed to load configuration {property.Name} for module {module.GetType().Name}.");
Console.ResetColor();

module.Unload();
return;
}
configurationValue.Initialize(module, property, serverName);
configurationValue.OnLoadingRequest += ModuleConfiguration_OnLoadingRequest;
configurationValue.OnSavingRequest += ModuleConfiguration_OnSavingRequest;
Expand Down

0 comments on commit 439f5c0

Please sign in to comment.