Skip to content

Commit

Permalink
Fix crash when saving peferences
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Sep 12, 2024
1 parent 3c1ecb1 commit 524f2bf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/Resources/Controls/EnhancedDataGrid.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//https://bengribaudo.com/blog/2012/03/14/1942/saving-restoring-wpf-datagrid-columns-size-sorting-and-order

using COMPASS.Services;
using COMPASS.Tools;
using Newtonsoft.Json;
using System;
using System.Collections;
Expand Down Expand Up @@ -67,9 +68,16 @@ private void UpdateColumnInfo()
prefsService.Preferences.UIState.SortDirection = sd.Direction;
}

Properties.Settings.Default["DataGridCollumnInfo"] = json;
Properties.Settings.Default.Save();
updatingColumnInfo = false;
try
{
Properties.Settings.Default["DataGridCollumnInfo"] = json;
Properties.Settings.Default.Save();
updatingColumnInfo = false;
}
catch (Exception ex)
{
Logger.Error("Failed to save Preferences", ex);
}
}
protected override void OnColumnReordered(DataGridColumnEventArgs e)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Services/PreferencesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ private PreferencesService() { }

public void SavePreferences()
{
Properties.Settings.Default.Save();

if (_preferences == null) return; //don't save when they aren't loaded
PreferencesDto dto = _preferences.ToDto();

try
{
Properties.Settings.Default.Save();

if (_preferences == null) return; //don't save when they aren't loaded
PreferencesDto dto = _preferences.ToDto();

string tempFileName = PreferencesFilePath + ".tmp";

lock (writeLocker)
Expand Down
13 changes: 10 additions & 3 deletions src/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ private void UpgradeSettings()
{
if (Properties.Settings.Default.justUpdated)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.justUpdated = false;
Properties.Settings.Default.Save();
try
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.justUpdated = false;
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
Logger.Error("Failed to Update & Save Preferences", ex);
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,16 @@ public static string CompassDataPath

set
{
Properties.Settings.Default.CompassDataPath = value;
EnvironmentVarsService.CompassDataPath = value;
Properties.Settings.Default.Save();
try
{
Properties.Settings.Default.CompassDataPath = value;
EnvironmentVarsService.CompassDataPath = value;
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
Logger.Error("Failed to update Compass Data Path", ex);
}
}
}

Expand Down

0 comments on commit 524f2bf

Please sign in to comment.