Merge pull request #20

fix: close the database on plugin load failure
This commit is contained in:
Infi
2024-04-18 14:09:04 +02:00
committed by GitHub
+24 -11
View File
@@ -1,4 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Reflection; using System.Reflection;
using ChatTwo.Ipc; using ChatTwo.Ipc;
@@ -65,6 +66,8 @@ public sealed class Plugin : IDalamudPlugin
#pragma warning disable CS8618 #pragma warning disable CS8618
public Plugin() public Plugin()
{
try
{ {
GameStarted = Process.GetCurrentProcess().StartTime.ToUniversalTime(); GameStarted = Process.GetCurrentProcess().StartTime.ToUniversalTime();
@@ -112,8 +115,18 @@ public sealed class Plugin : IDalamudPlugin
Interface.UiBuilder.Draw += Draw; Interface.UiBuilder.Draw += Draw;
Interface.LanguageChanged += LanguageChanged; Interface.LanguageChanged += LanguageChanged;
} }
catch
{
Dispose();
// Re-throw the exception to fail the plugin load.
throw;
}
}
#pragma warning restore CS8618 #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() public void Dispose()
{ {
Interface.LanguageChanged -= LanguageChanged; Interface.LanguageChanged -= LanguageChanged;
@@ -121,18 +134,18 @@ public sealed class Plugin : IDalamudPlugin
Framework.Update -= FrameworkUpdate; Framework.Update -= FrameworkUpdate;
GameFunctions.GameFunctions.SetChatInteractable(true); GameFunctions.GameFunctions.SetChatInteractable(true);
WindowSystem.RemoveAllWindows(); WindowSystem?.RemoveAllWindows();
ChatLogWindow.Dispose(); ChatLogWindow?.Dispose();
SettingsWindow.Dispose(); SettingsWindow?.Dispose();
SeStringDebugger.Dispose(); SeStringDebugger?.Dispose();
ExtraChat.Dispose(); ExtraChat?.Dispose();
Ipc.Dispose(); Ipc?.Dispose();
Store.Dispose(); Store?.Dispose();
Functions.Dispose(); Functions?.Dispose();
TextureCache.Dispose(); TextureCache?.Dispose();
Common.Dispose(); Common?.Dispose();
Commands.Dispose(); Commands?.Dispose();
} }
private void Draw() private void Draw()