From 630b2dce8c556f17abb22540347da11948aaa8bf Mon Sep 17 00:00:00 2001 From: "Eric P. Nusbaum" Date: Sun, 26 Nov 2023 20:04:18 -0500 Subject: [PATCH 1/2] Add "Save As" dialogue for appsettings.json in Setup Wizard - Adds "Save As" File Dialogue at end of setup - Confirms file path in confirmation dialogue --- MBBSEmu/UI/Setup/SetupView.cs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/MBBSEmu/UI/Setup/SetupView.cs b/MBBSEmu/UI/Setup/SetupView.cs index a91175be..2786a50f 100644 --- a/MBBSEmu/UI/Setup/SetupView.cs +++ b/MBBSEmu/UI/Setup/SetupView.cs @@ -493,17 +493,39 @@ public override void Setup() if (MessageBox.Query("Confirm", "Are you sure you want to write these settings to appsettings.json?", "Yes", "No") == 0) { - //Write settings to appsettings.json - var appSettingsJson = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true }); - File.WriteAllText("appsettings.json", appSettingsJson); + //Prompt a File Dialog to save appsettings.json to the desired location + var saveFileDialog = new SaveDialog("Save appsettings.json", "Save", new List() { ".json"}) + { + Width = Dim.Percent(50), + Height = Dim.Percent(50) + }; + saveFileDialog.DirectoryPath = Directory.GetCurrentDirectory(); + saveFileDialog.FilePath = "appsettings.json"; + saveFileDialog.AllowsOtherFileTypes = false; + saveFileDialog.CanCreateDirectories = true; + Application.Run(saveFileDialog); + + var appSettingsFilePath = saveFileDialog.FilePath.ToString(); + + if(saveFileDialog.Canceled || string.IsNullOrEmpty(appSettingsFilePath)) + { + //Exit Out + MessageBox.ErrorQuery("Error", "Setup Cancelled", "Ok"); + } + else + { + //Write settings to appsettings.json + var appSettingsJson = JsonSerializer.Serialize(appSettings, new JsonSerializerOptions() { WriteIndented = true }); + File.WriteAllText(appSettingsFilePath, appSettingsJson); + //Show a message box to confirm settings were written + MessageBox.Query("Success", $"Settings were successfully written to:\n{appSettingsFilePath}", "Ok"); + } + //Close the Wizard wizard.Running = false; wizard.Visible = false; this.RequestStop(); - - //Show a message box to confirm settings were written - MessageBox.Query("Success", "Settings were successfully written to appsettings.json", "Ok"); } }; From 6e5f2208e594513770562aab48c4cd7b4bdf6b80 Mon Sep 17 00:00:00 2001 From: "Eric P. Nusbaum" Date: Sun, 26 Nov 2023 20:52:15 -0500 Subject: [PATCH 2/2] Small UI Cleanups --- MBBSEmu/UI/Setup/SetupView.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/MBBSEmu/UI/Setup/SetupView.cs b/MBBSEmu/UI/Setup/SetupView.cs index 2786a50f..5ca2a69a 100644 --- a/MBBSEmu/UI/Setup/SetupView.cs +++ b/MBBSEmu/UI/Setup/SetupView.cs @@ -53,7 +53,7 @@ public override void Setup() var wizard = new Wizard("Initial Setup Wizard") { Width = Dim.Percent(90), - Height = Dim.Percent(75) + Height = Dim.Percent(80) }; //Initial Setep (Welcome Message) @@ -494,15 +494,14 @@ public override void Setup() "Yes", "No") == 0) { //Prompt a File Dialog to save appsettings.json to the desired location - var saveFileDialog = new SaveDialog("Save appsettings.json", "Save", new List() { ".json"}) + var saveFileDialog = new SaveDialog("Save Settings", "Select the path and file name to save your settings.\n\nWe recommend using the filename \"appsettings.json\"", new List() { ".json"}) { - Width = Dim.Percent(50), - Height = Dim.Percent(50) + Width = Dim.Percent(75), + Height = Dim.Percent(75) }; saveFileDialog.DirectoryPath = Directory.GetCurrentDirectory(); saveFileDialog.FilePath = "appsettings.json"; saveFileDialog.AllowsOtherFileTypes = false; - saveFileDialog.CanCreateDirectories = true; Application.Run(saveFileDialog); var appSettingsFilePath = saveFileDialog.FilePath.ToString();