From 6d891ff416fc88e57a0c5d1a49955bbf27d1c686 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sat, 17 Apr 2021 03:26:51 +0200 Subject: [PATCH] feat: show error message if font doesn't exist --- Dalamud/Interface/InterfaceManager.cs | 16 ++++++++++++++++ Dalamud/Util.cs | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/Dalamud/Interface/InterfaceManager.cs b/Dalamud/Interface/InterfaceManager.cs index fe59f0708..b987855de 100644 --- a/Dalamud/Interface/InterfaceManager.cs +++ b/Dalamud/Interface/InterfaceManager.cs @@ -308,6 +308,13 @@ namespace Dalamud.Interface public static ImFontPtr DefaultFont { get; private set; } public static ImFontPtr IconFont { get; private set; } + private static void ShowFontError(string path) + { + Util.Fatal( + $"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", + "Error"); + } + private unsafe void SetupFonts() { this.fontBuildSignal.Reset(); @@ -320,12 +327,18 @@ namespace Dalamud.Interface var fontPathJp = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf"); + if (!File.Exists(fontPathJp)) + ShowFontError(fontPathJp); + var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned); DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, japaneseRangeHandle.AddrOfPinnedObject()); var fontPathGame = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "gamesym.ttf"); + if (!File.Exists(fontPathGame)) + ShowFontError(fontPathGame); + var gameRangeHandle = GCHandle.Alloc(new ushort[] { 0xE020, @@ -337,6 +350,9 @@ namespace Dalamud.Interface var fontPathIcon = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf"); + if (!File.Exists(fontPathIcon)) + ShowFontError(fontPathIcon); + var iconRangeHandle = GCHandle.Alloc(new ushort[] { 0xE000, diff --git a/Dalamud/Util.cs b/Dalamud/Util.cs index e83458e83..5afec37c2 100644 --- a/Dalamud/Util.cs +++ b/Dalamud/Util.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -146,5 +147,14 @@ namespace Dalamud ImGui.TextColored(ImGuiColors.HealerGreen, $" {fieldInfo.Name}: {fieldInfo.GetValue(obj)}"); } } + + [DllImport("user32.dll", SetLastError = true, CharSet= CharSet.Auto)] + public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type); + + public static void Fatal(string message, string caption) + { + MessageBox(Process.GetCurrentProcess().MainWindowHandle, message, caption, 0); + Environment.Exit(-1); + } } }