Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Save As" dialogue for appsettings.json in Setup Wizard #606

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions MBBSEmu/UI/Setup/SetupView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -493,17 +493,38 @@ 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 Settings", "Select the path and file name to save your settings.\n\nWe recommend using the filename \"appsettings.json\"", new List<string>() { ".json"})
{
Width = Dim.Percent(75),
Height = Dim.Percent(75)
};
saveFileDialog.DirectoryPath = Directory.GetCurrentDirectory();
saveFileDialog.FilePath = "appsettings.json";
saveFileDialog.AllowsOtherFileTypes = false;
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");
}
};

Expand Down
Loading