From 84c3121b6f31e9310982a43a043bd7a0b50ecfed Mon Sep 17 00:00:00 2001 From: Matt Pannella Date: Thu, 21 Sep 2023 22:01:35 -0400 Subject: [PATCH] better settings menu (#188) --- pocket_updater.csproj | 2 +- src/Program.cs | 59 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/pocket_updater.csproj b/pocket_updater.csproj index 9a01d556..9983784c 100644 --- a/pocket_updater.csproj +++ b/pocket_updater.csproj @@ -6,7 +6,7 @@ net6.0 enable enable - 2.35.0 + 2.36.0 Keep your Analogue Pocket up to date 2023 Matt Pannella Matt Pannella diff --git a/src/Program.cs b/src/Program.cs index e6fd8e93..c810d91f 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -289,9 +289,8 @@ private static async Task Main(string[] args) Pause(); break; case 7: - RunConfigWizard(); + NewSettingsMenu(); SetUpdaterFlags(); - Pause(); break; case 8: flag = false; @@ -936,16 +935,66 @@ private static int DisplayMenu() return 0; } + private static async Task NewSettingsMenu() + { + Console.Clear(); + + var menuItems = new Dictionary(){ + {"download_firmware", "Download Firmware Updates during 'Update All'"}, + {"download_assets", "Download Missing Assets (ROMs and BIOS Files) during 'Update All'"}, + {"build_instance_jsons", "Build game JSON files for supported cores during 'Update All'"}, + {"delete_skipped_cores", "Delete untracked cores during 'Update All'"}, + {"fix_jt_names", "Automatically rename Jotego cores during 'Update All"}, + {"crc_check", "Use CRC check when checking ROMs and BIOS files"}, + {"preserve_platforms_folder", "Preserve 'Platforms' folder during 'Update All'"}, + {"skip_alternative_assets", "Skip alternative roms when downloading assets"}, + {"use_custom_archive", "Use custom asset archive"} + }; + + var type = typeof(Config); + + var menu = new ConsoleMenu() + .Configure(config => + { + config.Selector = "=>"; + config.EnableWriteTitle = false; + config.WriteHeaderAction = () => Console.WriteLine("Settings"); + config.SelectedItemBackgroundColor = Console.ForegroundColor; + config.SelectedItemForegroundColor = Console.BackgroundColor; + config.WriteItemAction = item => Console.Write("{1}", item.Index, item.Name); + }); + + foreach(var (name, text) in menuItems) { + var property = type.GetProperty(name); + var value = (bool)property.GetValue(settings.GetConfig()); + var title = settingsMenuItem(text, value); + menu.Add(title, (thisMenu) => { property.SetValue(settings.GetConfig(), !value); thisMenu.CurrentItem.Name = settingsMenuItem(text, !value);}); + } + + menu.Add("Save", (thisMenu) => {thisMenu.CloseMenu();}); + + menu.Show(); + + settings.SaveSettings(); + } + + private static string settingsMenuItem(string title, bool value) + { + var x = " "; + if (value) { + x = "X"; + } + + return $"[{x}] {title}"; + } + private static async Task ImagePackSelector(string path) { Console.Clear(); Console.WriteLine("Checking for image packs...\n"); ImagePack[] packs = await ImagePacksService.GetImagePacks(); if(packs.Length > 0) { - - int choice = 0; - var menu = new ConsoleMenu() .Configure(config => {