Rework emoji font mod

This commit is contained in:
pizzaboxer 2023-07-14 23:20:58 +01:00
parent e683af373d
commit 88ea69c56d
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 23 additions and 17 deletions

View File

@ -1010,27 +1010,24 @@ namespace Bloxstrap
await CheckModPreset(App.Settings.Prop.UseDisableAppPatch && !_launchCommandLine.Contains("--deeplink"), @"ExtraContent\places\Mobile.rbxl", "");
// emoji presets are downloaded remotely from github due to how large they are
string emojiFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\TwemojiMozilla.ttf");
string contentFonts = Path.Combine(Directories.Modifications, "content\\fonts");
string emojiFontLocation = Path.Combine(contentFonts, "TwemojiMozilla.ttf");
string emojiFontHash = File.Exists(emojiFontLocation) ? Utility.MD5Hash.FromFile(emojiFontLocation) : "";
if (App.Settings.Prop.PreferredEmojiType == EmojiType.Default && App.State.Prop.CurrentEmojiType != EmojiType.Default)
if (App.Settings.Prop.EmojiType == EmojiType.Default && EmojiTypeEx.Hashes.Values.Contains(emojiFontHash))
{
if (File.Exists(emojiFontLocation))
File.Delete(emojiFontLocation);
App.State.Prop.CurrentEmojiType = EmojiType.Default;
}
else if (App.Settings.Prop.PreferredEmojiType != EmojiType.Default && App.State.Prop.CurrentEmojiType != App.Settings.Prop.PreferredEmojiType)
else if (App.Settings.Prop.EmojiType != EmojiType.Default && emojiFontHash != App.Settings.Prop.EmojiType.GetHash())
{
if (File.Exists(emojiFontLocation))
if (emojiFontHash != "")
File.Delete(emojiFontLocation);
string remoteEmojiLocation = App.Settings.Prop.PreferredEmojiType.GetRemoteLocation();
Directory.CreateDirectory(contentFonts);
var response = await App.HttpClient.GetAsync(remoteEmojiLocation);
var response = await App.HttpClient.GetAsync(App.Settings.Prop.EmojiType.GetUrl());
await using var fileStream = new FileStream(emojiFontLocation, FileMode.CreateNew);
await response.Content.CopyToAsync(fileStream);
App.State.Prop.CurrentEmojiType = App.Settings.Prop.PreferredEmojiType;
}
foreach (string file in Directory.GetFiles(modFolder, "*.*", SearchOption.AllDirectories))

View File

@ -23,7 +23,17 @@ namespace Bloxstrap.Extensions
{ EmojiType.Windows8, "Win8.1SegoeUIEmoji.ttf" },
};
public static string GetRemoteLocation(this EmojiType emojiType)
public static IReadOnlyDictionary<EmojiType, string> Hashes => new Dictionary<EmojiType, string>
{
{ EmojiType.Catmoji, "98138f398a8cde897074dd2b8d53eca0" },
{ EmojiType.Windows11, "d50758427673578ddf6c9edcdbf367f5" },
{ EmojiType.Windows10, "d8a7eecbebf9dfdf622db8ccda63aff5" },
{ EmojiType.Windows8, "2b01c6caabbe95afc92aa63b9bf100f3" },
};
public static string GetHash(this EmojiType emojiType) => Hashes[emojiType];
public static string GetUrl(this EmojiType emojiType)
{
if (emojiType == EmojiType.Default)
return "";

View File

@ -31,7 +31,7 @@ namespace Bloxstrap.Models
public bool UseOldCharacterSounds { get; set; } = false;
public bool UseOldMouseCursor { get; set; } = false;
public bool UseDisableAppPatch { get; set; } = false;
public EmojiType PreferredEmojiType { get; set; } = EmojiType.Default;
public EmojiType EmojiType { get; set; } = EmojiType.Default;
public bool DisableFullscreenOptimizations { get; set; } = false;
}
}

View File

@ -7,7 +7,6 @@ namespace Bloxstrap.Models
public class State
{
public string VersionGuid { get; set; } = "";
public EmojiType CurrentEmojiType { get; set; } = EmojiType.Default;
public List<string> ModManifest { get; set; } = new();
}
}

View File

@ -44,8 +44,8 @@ namespace Bloxstrap.UI.ViewModels.Menu
public string SelectedEmojiType
{
get => EmojiTypes.FirstOrDefault(x => x.Value == App.Settings.Prop.PreferredEmojiType).Key;
set => App.Settings.Prop.PreferredEmojiType = EmojiTypes[value];
get => EmojiTypes.FirstOrDefault(x => x.Value == App.Settings.Prop.EmojiType).Key;
set => App.Settings.Prop.EmojiType = EmojiTypes[value];
}
public bool DisableFullscreenOptimizationsEnabled