Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Fix crash when saving account data
Browse files Browse the repository at this point in the history
Apparently, SelectedItem cannot be casted to a nullable type. This also expands the try block to prevent any other possible crashes when saving account data.
  • Loading branch information
MatthewL246 committed Aug 30, 2022
1 parent e2f6275 commit 6d72c66
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,24 +501,24 @@ private void ReloadOrStop(object sender, RoutedEventArgs e)
/// <summary>Saves the current account's login info and settings.</summary>
private async Task SaveAccountDataAsync()
{
JsonObject accountDataObject = new()
try
{
["username"] = username.Text,
["password"] = passwordHash.Password,
JsonObject accountDataObject = new()
{
["username"] = username.Text,
["password"] = passwordHash.Password,

["accountServer"] = accountServer.Text,
["discoveryServer"] = discoveryServer.Text,
["portalServer"] = portalServer.Text,
["accountServer"] = accountServer.Text,
["discoveryServer"] = discoveryServer.Text,
["portalServer"] = portalServer.Text,

["languageId"] = (int?)languageBox.SelectedItem,
["countryId"] = (int?)countryBox.SelectedItem,
["console"] = (string?)consoleSelect.SelectedItem,
};
["languageId"] = (int)languageBox.SelectedItem,
["countryId"] = (int)countryBox.SelectedItem,
["console"] = (string)consoleSelect.SelectedItem,
};

JsonSerializerOptions options = new() { WriteIndented = true };
JsonSerializerOptions options = new() { WriteIndented = true };

try
{
await File.WriteAllTextAsync(accountDataJsonPath, accountDataObject.ToJsonString(options));
}
catch (Exception ex)
Expand Down

0 comments on commit 6d72c66

Please sign in to comment.