-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
37 lines (32 loc) · 1.39 KB
/
Settings.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 Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpeedMatcher
{
public class Settings
{
public string SprogPort { get; set; } = string.Empty;
public static Settings? LoadSettings()
{
string fn = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyMR/SpeedMatcher/Settings.json");
string s = File.ReadAllText(fn);
return JsonConvert.DeserializeObject<Settings>(s);
}
public static void SaveSettings(Settings? settings)
{
if (settings == null) { throw new Exception("Can't save a null settings object."); }
JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Include;
string fn = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyMR/SpeedMatcher/Settings.json");
string s = JsonConvert.SerializeObject(settings, Formatting.Indented);
if (!Directory.Exists(Path.GetDirectoryName(fn))) { Directory.CreateDirectory(Path.GetDirectoryName(fn)); };
File.WriteAllText(fn, s);
}
}
}