From 6d25b9db69a61bc62fa39a756c6b4ae403d71f56 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Wed, 29 Jul 2020 22:42:57 -0400 Subject: [PATCH] feat: add error window for bad configs --- HudSwap/Plugin.cs | 9 +++++++-- HudSwap/PluginUI.cs | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/HudSwap/Plugin.cs b/HudSwap/Plugin.cs index efdbec1..fa9880d 100644 --- a/HudSwap/Plugin.cs +++ b/HudSwap/Plugin.cs @@ -1,4 +1,5 @@ using Dalamud.Plugin; +using System; namespace HudSwap { public class HudSwapPlugin : IDalamudPlugin { @@ -11,8 +12,12 @@ namespace HudSwap { public void Initialize(DalamudPluginInterface pluginInterface) { this.pi = pluginInterface; - - this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration(); + try { + this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration(); + } catch (Exception) { + this.pi.UiBuilder.OnBuildUi += PluginUI.ConfigError; + return; + } this.config.Initialize(this.pi); this.ui = new PluginUI(this, this.pi); diff --git a/HudSwap/PluginUI.cs b/HudSwap/PluginUI.cs index 6b3adee..7b047b4 100644 --- a/HudSwap/PluginUI.cs +++ b/HudSwap/PluginUI.cs @@ -32,6 +32,17 @@ namespace HudSwap { private string importName = ""; private Guid selectedLayout = Guid.Empty; + private static bool configErrorOpen = true; + public static void ConfigError() { + if (ImGui.Begin("HudSwap error", ref configErrorOpen)) { + ImGui.Text("Could not load HudSwap configuration."); + ImGui.Spacing(); + ImGui.Text("If you are updating from a previous version, please\ndelete your configuration file and restart the game."); + + ImGui.End(); + } + } + public void DrawSettings() { if (!this.SettingsVisible) { return;