-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsHandler.cs
37 lines (33 loc) · 938 Bytes
/
SettingsHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace CodeAggregatorGtk
{
public class SettingsHandler
{
private const string SettingsFile = "settings.json";
public Settings Settings { get; set; }
public SettingsHandler()
{
Settings = new Settings();
LoadSettings();
}
public void SaveSettings()
{
var json = JsonConvert.SerializeObject(Settings, Formatting.Indented);
File.WriteAllText(SettingsFile, json);
}
private void LoadSettings()
{
if (File.Exists(SettingsFile))
{
var json = File.ReadAllText(SettingsFile);
Settings = JsonConvert.DeserializeObject<Settings>(json) ?? new Settings();
}
else
{
Settings = new Settings();
}
}
}
}