feat: show error message if font doesn't exist

This commit is contained in:
goat 2021-04-17 03:26:51 +02:00
parent f81a368ed6
commit 6d891ff416
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 26 additions and 0 deletions

View file

@ -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,

View file

@ -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);
}
}
}