From f02fba2ce14409e54e8e4c5aefab0cdab43d85a0 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 17:52:23 +0100 Subject: [PATCH] Fix font application mod on first install --- Bloxstrap/App.xaml.cs | 2 ++ Bloxstrap/Bootstrapper.cs | 10 +++++++--- Bloxstrap/Directories.cs | 2 ++ .../UI/ViewModels/Menu/MainWindowViewModel.cs | 2 +- Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs | 19 ++++++++++++++----- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 13ed82b..7b86735 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -17,8 +17,10 @@ namespace Bloxstrap // used only for communicating between app and menu - use Directories.Base for anything else public static string BaseDirectory = null!; + public static string? CustomFontLocation; public static bool ShouldSaveConfigs { get; set; } = false; + public static bool IsSetupComplete { get; set; } = true; public static bool IsFirstRun { get; private set; } = true; public static bool IsQuiet { get; private set; } = false; diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 6d4dbd6..acf1861 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -980,7 +980,6 @@ namespace Bloxstrap bool appDisabled = App.Settings.Prop.UseDisableAppPatch && !_launchCommandLine.Contains("--deeplink"); // cursors - await CheckModPreset(App.Settings.Prop.CursorType == CursorType.From2006, new Dictionary { { @"content\textures\Cursors\KeyboardMouse\ArrowCursor.png", "Cursor.From2006.ArrowCursor.png" }, @@ -1036,9 +1035,14 @@ namespace Bloxstrap // instead of replacing the fonts themselves, we'll just alter the font family manifests string modFontFamiliesFolder = Path.Combine(Directories.Modifications, "content\\fonts\\families"); - string customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf"); - if (File.Exists(customFontLocation)) + if (App.IsFirstRun && App.CustomFontLocation is not null) + { + Directory.CreateDirectory(Path.GetDirectoryName(Directories.CustomFont)!); + File.Copy(App.CustomFontLocation, Directories.CustomFont); + } + + if (File.Exists(Directories.CustomFont)) { App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Begin font check"); diff --git a/Bloxstrap/Directories.cs b/Bloxstrap/Directories.cs index 7f0141e..c98a613 100644 --- a/Bloxstrap/Directories.cs +++ b/Bloxstrap/Directories.cs @@ -19,6 +19,8 @@ public static string Application { get; private set; } = ""; + public static string CustomFont => Path.Combine(Modifications, "content\\fonts\\CustomFont.ttf"); + public static bool Initialized => !String.IsNullOrEmpty(Base); public static void Initialize(string baseDirectory) diff --git a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs index 5464a15..2049a44 100644 --- a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs @@ -75,7 +75,7 @@ namespace Bloxstrap.UI.ViewModels.Menu $"The folder you've chosen to install {App.ProjectName} to already exists and is NOT empty. It is strongly recommended for {App.ProjectName} to be installed to its own independent folder.\n\n" + "Changing to the following location is suggested:\n" + $"{suggestedChange}\n\n" + - "Would you like to change your install location to this?\n" + + "Would you like to change to the suggested location?\n" + "Selecting 'No' will ignore this warning and continue installation.", MessageBoxImage.Warning, MessageBoxButton.YesNoCancel, diff --git a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs index 3502350..a5fde9c 100644 --- a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs @@ -11,14 +11,16 @@ namespace Bloxstrap.UI.ViewModels.Menu { private void OpenModsFolder() => Process.Start("explorer.exe", Directories.Modifications); - private string _customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf"); - private bool _usingCustomFont => File.Exists(_customFontLocation); + private bool _usingCustomFont => App.IsFirstRun && App.CustomFontLocation is not null || !App.IsFirstRun && File.Exists(Directories.CustomFont); private void ManageCustomFont() { if (_usingCustomFont) { - File.Delete(_customFontLocation); + if (App.IsFirstRun) + App.CustomFontLocation = null; + else + File.Delete(Directories.CustomFont); } else { @@ -30,8 +32,15 @@ namespace Bloxstrap.UI.ViewModels.Menu if (dialog.ShowDialog() != true) return; - Directory.CreateDirectory(Path.GetDirectoryName(_customFontLocation)!); - File.Copy(dialog.FileName, _customFontLocation); + if (App.IsFirstRun) + { + App.CustomFontLocation = dialog.FileName; + } + else + { + Directory.CreateDirectory(Path.GetDirectoryName(Directories.CustomFont)!); + File.Copy(dialog.FileName, Directories.CustomFont); + } } OnPropertyChanged(nameof(ChooseCustomFontVisibility));