From 7e95fb4d8fc4d132ee4633ba38b68a384ff897da Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 13 Aug 2024 00:03:39 +0100 Subject: [PATCH] Deferred settings application system + new shortcut settings this system took way too much effort to think of for some reason idk why --- Bloxstrap/App.xaml.cs | 3 + Bloxstrap/Models/SettingTasks/BaseTask.cs | 47 +++++++++ Bloxstrap/Models/SettingTasks/ISettingTask.cs | 17 ++++ Bloxstrap/Models/SettingTasks/ShortcutTask.cs | 35 +++++++ Bloxstrap/Resources/Strings.Designer.cs | 98 ++++++++++++++----- Bloxstrap/Resources/Strings.resx | 30 ++++-- .../Elements/Installer/Pages/InstallPage.xaml | 9 +- .../UI/Elements/Settings/MainWindow.xaml | 1 + .../Settings/Pages/FastFlagsPage.xaml | 2 +- .../Settings/Pages/ShortcutsPage.xaml | 55 +++++++++++ .../Settings/Pages/ShortcutsPage.xaml.cs | 31 ++++++ .../Settings/MainWindowViewModel.cs | 5 + .../ViewModels/Settings/ShortcutsViewModel.cs | 54 ++++++++++ 13 files changed, 354 insertions(+), 33 deletions(-) create mode 100644 Bloxstrap/Models/SettingTasks/BaseTask.cs create mode 100644 Bloxstrap/Models/SettingTasks/ISettingTask.cs create mode 100644 Bloxstrap/Models/SettingTasks/ShortcutTask.cs create mode 100644 Bloxstrap/UI/Elements/Settings/Pages/ShortcutsPage.xaml create mode 100644 Bloxstrap/UI/Elements/Settings/Pages/ShortcutsPage.xaml.cs create mode 100644 Bloxstrap/UI/ViewModels/Settings/ShortcutsViewModel.cs diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index d49819c..1423e82 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -5,6 +5,7 @@ using System.Windows.Threading; using Microsoft.Win32; using Bloxstrap.Resources; +using Bloxstrap.Models.SettingTasks; namespace Bloxstrap { @@ -32,6 +33,8 @@ namespace Bloxstrap public static readonly Logger Logger = new(); + public static readonly Dictionary PendingSettingTasks = new(); + public static readonly JsonManager Settings = new(); public static readonly JsonManager State = new(); diff --git a/Bloxstrap/Models/SettingTasks/BaseTask.cs b/Bloxstrap/Models/SettingTasks/BaseTask.cs new file mode 100644 index 0000000..21d0c63 --- /dev/null +++ b/Bloxstrap/Models/SettingTasks/BaseTask.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Models.SettingTasks +{ + public class BaseTask : ISettingTask + { + private bool _originalState; + + private bool _newState; + + public string Name { get; set; } = ""; + + public bool OriginalState + { + get + { + return _originalState; + } + + set + { + _originalState = value; + _newState = value; + } + } + + public bool NewState + { + get + { + return _newState; + } + + set + { + App.PendingSettingTasks[Name] = this; + _newState = value; + } + } + + public virtual void Execute() => throw new NotImplementedException(); + } +} diff --git a/Bloxstrap/Models/SettingTasks/ISettingTask.cs b/Bloxstrap/Models/SettingTasks/ISettingTask.cs new file mode 100644 index 0000000..ff441af --- /dev/null +++ b/Bloxstrap/Models/SettingTasks/ISettingTask.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Models.SettingTasks +{ + public interface ISettingTask + { + public bool OriginalState { get; set; } + + public bool NewState { get; set; } + + public void Execute(); + } +} diff --git a/Bloxstrap/Models/SettingTasks/ShortcutTask.cs b/Bloxstrap/Models/SettingTasks/ShortcutTask.cs new file mode 100644 index 0000000..a13a1ce --- /dev/null +++ b/Bloxstrap/Models/SettingTasks/ShortcutTask.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bloxstrap.Models.SettingTasks +{ + public class ShortcutTask : BaseTask, ISettingTask + { + public string ExeFlags { get; set; } = ""; + + public string ShortcutPath { get; set; } + + public ShortcutTask(string shortcutPath) + { + ShortcutPath = shortcutPath; + + OriginalState = File.Exists(ShortcutPath); + } + + public override void Execute() + { + if (NewState == OriginalState) + return; + + if (NewState) + Shortcut.Create(Paths.Application, ExeFlags, ShortcutPath); + else + File.Delete(ShortcutPath); + + OriginalState = NewState; + } + } +} diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 1754ddd..bf92399 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -512,6 +512,33 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to Shortcuts. + /// + public static string Common_Shortcuts { + get { + return ResourceManager.GetString("Common.Shortcuts", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Desktop icon. + /// + public static string Common_Shortcuts_Desktop { + get { + return ResourceManager.GetString("Common.Shortcuts.Desktop", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Start Menu icon. + /// + public static string Common_Shortcuts_StartMenu { + get { + return ResourceManager.GetString("Common.Shortcuts.StartMenu", resourceCulture); + } + } + /// /// Looks up a localized string similar to System default. /// @@ -685,7 +712,7 @@ namespace Bloxstrap.Resources { } /// - /// Looks up a localized string similar to Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through Bloxstrap Settings.. + /// Looks up a localized string similar to Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through the settings.. /// public static string Dialog_CannotCreateShortcuts { get { @@ -1274,29 +1301,11 @@ namespace Bloxstrap.Resources { } /// - /// Looks up a localized string similar to Create Desktop shortcuts. + /// Looks up a localized string similar to These are general shortcuts that bring up a multi-choice launch menu. Shortcuts for specific functions can be created later in the settings.. /// - public static string Installer_Install_Shortcuts_Desktop { + public static string Installer_Install_Shortcuts_Description { get { - return ResourceManager.GetString("Installer.Install.Shortcuts.Desktop", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Create Start Menu shortcuts. - /// - public static string Installer_Install_Shortcuts_StartMenu { - get { - return ResourceManager.GetString("Installer.Install.Shortcuts.StartMenu", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Shortcuts. - /// - public static string Installer_Install_Shortcuts_Title { - get { - return ResourceManager.GetString("Installer.Install.Shortcuts.Title", resourceCulture); + return ResourceManager.GetString("Installer.Install.Shortcuts.Description", resourceCulture); } } @@ -2850,6 +2859,51 @@ namespace Bloxstrap.Resources { } } + /// + /// Looks up a localized string similar to Configure how Bloxstrap can be readily launched.. + /// + public static string Menu_Shortcuts_Description { + get { + return ResourceManager.GetString("Menu.Shortcuts.Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Create shortcuts for quick access to specific functions. These will all be placed on the Desktop.. + /// + public static string Menu_Shortcuts_Function_Description { + get { + return ResourceManager.GetString("Menu.Shortcuts.Function.Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Function. + /// + public static string Menu_Shortcuts_Function_Title { + get { + return ResourceManager.GetString("Menu.Shortcuts.Function.Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to These are the shortcuts that bring up the multi-choice launch menu.. + /// + public static string Menu_Shortcuts_General_Description { + get { + return ResourceManager.GetString("Menu.Shortcuts.General.Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to General. + /// + public static string Menu_Shortcuts_General_Title { + get { + return ResourceManager.GetString("Menu.Shortcuts.General.Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Bloxstrap Settings. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 3572a09..234c918 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1025,14 +1025,14 @@ This installation process will be quick and simple, and you will be able to conf Existing data found. Your mods and settings will be restored. - + Shortcuts - - Create Desktop shortcuts + + Desktop icon - - Create Start Menu shortcuts + + Start Menu icon Bloxstrap has successfully been installed. @@ -1095,11 +1095,29 @@ Bloxstrap was installed at "{1}". You currently do not have the WebView2 runtime installed. Some Roblox features will not work properly without it, such as the desktop app. Would you like to download it now? - Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through Bloxstrap Settings. + Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through the settings. Check the [Bloxstrap Wiki]({0}) first to see if this problem has already been addressed with a fix. If not, then please report this exception to the maintainers of this fork. Do NOT report this to Bloxstrap's GitHub issues, as this is an unoffical build. + + These are general shortcuts that bring up a multi-choice launch menu. Shortcuts for specific functions can be created later in the settings. + + + Configure how Bloxstrap can be readily launched. + + + General + + + These are the shortcuts that bring up the multi-choice launch menu. + + + Function + + + Create shortcuts for quick access to specific functions. These will all be placed on the Desktop. + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/Installer/Pages/InstallPage.xaml b/Bloxstrap/UI/Elements/Installer/Pages/InstallPage.xaml index 9b83fe1..50229c3 100644 --- a/Bloxstrap/UI/Elements/Installer/Pages/InstallPage.xaml +++ b/Bloxstrap/UI/Elements/Installer/Pages/InstallPage.xaml @@ -35,7 +35,7 @@ - +