mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11:27 -07:00
font mod: validate chosen file is actually a font
This commit is contained in:
parent
2aa5367e1f
commit
6f1e023012
9
Bloxstrap/Resources/Strings.Designer.cs
generated
9
Bloxstrap/Resources/Strings.Designer.cs
generated
@ -2565,6 +2565,15 @@ namespace Bloxstrap.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The file you have chosen does not appear to be a valid font file..
|
||||
/// </summary>
|
||||
public static string Menu_Mods_Misc_CustomFont_Invalid {
|
||||
get {
|
||||
return ResourceManager.GetString("Menu.Mods.Misc.CustomFont.Invalid", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Remove applied font.
|
||||
/// </summary>
|
||||
|
@ -967,6 +967,9 @@ Selecting 'No' will ignore this warning and continue installation.</value>
|
||||
<data name="Menu.Mods.Misc.CustomFont.Description" xml:space="preserve">
|
||||
<value>Forces every in-game font to be a font that you choose.</value>
|
||||
</data>
|
||||
<data name="Menu.Mods.Misc.CustomFont.Invalid" xml:space="preserve">
|
||||
<value>The file you have chosen does not appear to be a valid font file.</value>
|
||||
</data>
|
||||
<data name="Menu.Mods.Misc.CustomFont.Remove" xml:space="preserve">
|
||||
<value>Remove applied font</value>
|
||||
</data>
|
||||
|
@ -13,6 +13,13 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
|
||||
private bool _usingCustomFont => App.IsFirstRun && App.CustomFontLocation is not null || !App.IsFirstRun && File.Exists(Paths.CustomFont);
|
||||
|
||||
private readonly Dictionary<string, byte[]> FontHeaders = new()
|
||||
{
|
||||
{ "ttf", new byte[4] { 0x00, 0x01, 0x00, 0x00 } },
|
||||
{ "otf", new byte[4] { 0x4F, 0x54, 0x54, 0x4F } },
|
||||
{ "ttc", new byte[4] { 0x74, 0x74, 0x63, 0x66 } }
|
||||
};
|
||||
|
||||
private void ManageCustomFont()
|
||||
{
|
||||
if (_usingCustomFont)
|
||||
@ -32,6 +39,14 @@ namespace Bloxstrap.UI.ViewModels.Menu
|
||||
if (dialog.ShowDialog() != true)
|
||||
return;
|
||||
|
||||
string type = dialog.FileName.Substring(dialog.FileName.Length-3, 3).ToLower();
|
||||
|
||||
if (!File.ReadAllBytes(dialog.FileName).Take(4).SequenceEqual(FontHeaders[type]))
|
||||
{
|
||||
Frontend.ShowMessageBox(Resources.Strings.Menu_Mods_Misc_CustomFont_Invalid, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (App.IsFirstRun)
|
||||
{
|
||||
App.CustomFontLocation = dialog.FileName;
|
||||
|
Loading…
Reference in New Issue
Block a user