Repository navigation
Expand file tree
/
Copy pathAppSettings.cs
More file actions
74 lines (65 loc) · 1.87 KB
/
Copy pathAppSettings.cs
File metadata and controls
74 lines (65 loc) · 1.87 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.IO;
using System.Xml.Serialization;
namespace BackgroundClicker.Wpf
{
[Serializable]
public class AppSettings
{
private const string FolderName = "BackgroundClickerWpf";
private const string FileName = "settings.xml";
public string LanguageCode { get; set; }
public static string GetSettingsFilePath()
{
string dir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
FolderName);
try
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
catch
{
dir = AppDomain.CurrentDomain.BaseDirectory;
}
return Path.Combine(dir, FileName);
}
public static AppSettings Load()
{
string path = GetSettingsFilePath();
try
{
if (File.Exists(path))
{
using (var stream = File.OpenRead(path))
{
var serializer = new XmlSerializer(typeof(AppSettings));
var loaded = serializer.Deserialize(stream) as AppSettings;
if (loaded != null) return loaded;
}
}
}
catch
{
}
return new AppSettings();
}
public void Save()
{
try
{
using (var stream = File.Create(GetSettingsFilePath()))
{
var serializer = new XmlSerializer(typeof(AppSettings));
serializer.Serialize(stream, this);
}
}
catch
{
}
}
}
}