fix: close the database on plugin load failure

This commit is contained in:
Dean Sheather
2024-04-18 21:56:05 +10:00
parent e7ca4ee6a6
commit a6decf97fb
+24 -11
View File
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using ChatTwo.Ipc;
@@ -65,6 +66,8 @@ public sealed class Plugin : IDalamudPlugin
#pragma warning disable CS8618
public Plugin()
{
try
{
GameStarted = Process.GetCurrentProcess().StartTime.ToUniversalTime();
@@ -112,8 +115,18 @@ public sealed class Plugin : IDalamudPlugin
Interface.UiBuilder.Draw += Draw;
Interface.LanguageChanged += LanguageChanged;
}
catch
{
Dispose();
// Re-throw the exception to fail the plugin load.
throw;
}
}
#pragma warning restore CS8618
// Suppressing this warning because Dispose() is called in Plugin() if the
// load fails, so some values may not be initialized.
[SuppressMessage("ReSharper", "ConditionalAccessQualifierIsNonNullableAccordingToAPIContract")]
public void Dispose()
{
Interface.LanguageChanged -= LanguageChanged;
@@ -121,18 +134,18 @@ public sealed class Plugin : IDalamudPlugin
Framework.Update -= FrameworkUpdate;
GameFunctions.GameFunctions.SetChatInteractable(true);
WindowSystem.RemoveAllWindows();
ChatLogWindow.Dispose();
SettingsWindow.Dispose();
SeStringDebugger.Dispose();
WindowSystem?.RemoveAllWindows();
ChatLogWindow?.Dispose();
SettingsWindow?.Dispose();
SeStringDebugger?.Dispose();
ExtraChat.Dispose();
Ipc.Dispose();
Store.Dispose();
Functions.Dispose();
TextureCache.Dispose();
Common.Dispose();
Commands.Dispose();
ExtraChat?.Dispose();
Ipc?.Dispose();
Store?.Dispose();
Functions?.Dispose();
TextureCache?.Dispose();
Common?.Dispose();
Commands?.Dispose();
}
private void Draw()