Skip to content

Commit 2de410a

Browse files
committed
load and export settings fixed
1 parent 803403e commit 2de410a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

GUI/MainForm.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,17 @@ private void ExportSettingsMenu_Click(object sender, EventArgs e) {
681681
DefaultExt = ".config",
682682
FileName = "OpenHardwareMonitor.config",
683683
Filter = "Config files|*.config",
684-
RestoreDirectory = true,
685-
Title = "Export Settings As"
684+
RestoreDirectory = false,
685+
Title = "Export Settings As",
686+
InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath),
686687
};
687688
if (dlg.ShowDialog() != DialogResult.OK)
688689
return;
690+
var oldPortableValue = settings.GetValue("portable", false);
691+
settings.SetValue("portable", true);
689692
settings.SaveToFile(dlg.FileName);
693+
if (!oldPortableValue)
694+
settings.SetValue("portable", oldPortableValue);
690695
MessageBox.Show("Settings export completed successfully!", "Export Settings", MessageBoxButtons.OK, MessageBoxIcon.Information);
691696
}
692697
}

Utilities/PersistentSettings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public void Load() {
2525
if (File.Exists(configFilePath)) {
2626
try {
2727
var json = File.ReadAllText(configFilePath);
28-
settings = json.FromJson<IDictionary<string, string>>();
29-
return;
28+
var data = json.FromJson<IDictionary<string, string>>();
29+
if (data != null) {
30+
settings = data;
31+
return;
32+
}
3033
}
3134
catch (Exception) {
3235
}

0 commit comments

Comments
 (0)