forked from arsentuf-protag/SUBSTitute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserSettings.cs
48 lines (39 loc) · 1.36 KB
/
UserSettings.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
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Sungaila.SUBSTitute
{
/// <summary>
/// Contains settings which should persisted when the application was closed.
/// The settings are (de-)serialized as a XML file in the application root directory.
/// </summary>
public sealed class UserSettings
{
private const string SETTING_FILENAME = "UserSettings.xml";
public char? LastSelectedDriveLetter { get; set; }
public string? LastMappedDirectory { get; set; }
public string? LastBrowserRootDirectory { get; set; }
public bool IsExpanded { get; set; } = true;
public static void Save(UserSettings userSettings)
{
var serializer = new XmlSerializer(typeof(UserSettings));
using var writer = XmlWriter.Create(SETTING_FILENAME);
serializer.Serialize(writer, userSettings);
}
public static UserSettings? Load()
{
try
{
var serializer = new XmlSerializer(typeof(UserSettings));
using var reader = XmlReader.Create(SETTING_FILENAME);
return serializer.Deserialize(reader) as UserSettings;
}
catch
{
return null;
}
}
}
}