This repository has been archived by the owner on May 16, 2024. It is now read-only.
forked from RossMetacraft/WorldOfAiDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cs
67 lines (62 loc) · 1.66 KB
/
Config.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Metacraft.FlightSimulation.WoaiDownloader
{
[Serializable]
public class Config
{
public string AvsimUsername { get; set; }
public string AvsimPassword { get; set; }
public bool SavePassword { get; set; }
public string Simulator { get; set; }
public string DownloadFolder { get; set; }
public Config()
{
AvsimUsername = string.Empty;
AvsimPassword = string.Empty;
SavePassword = false;
Simulator = "FSX";
DownloadFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
public void Save()
{
try {
string path = GetConfigPath();
FileInfo fi = new FileInfo(path);
if (!fi.Directory.Exists) fi.Directory.Create();
XmlSerializer serializer = new XmlSerializer(typeof(Config));
using (StreamWriter sw = new StreamWriter(path)) serializer.Serialize(sw, this);
}
catch { }
}
public static Config Load()
{
string path = GetConfigPath();
if (!File.Exists(path)) return new Config();
try {
XmlSerializer serializer = new XmlSerializer(typeof(Config));
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) {
XmlTextReader reader = new XmlTextReader(fs);
reader.Normalization = false;
return (Config)serializer.Deserialize(reader);
}
}
catch {
return new Config();
}
}
private static string GetConfigPath()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"WoaiDownloader",
"Config.xml"
);
}
}
}