-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathProgram.cs
61 lines (53 loc) · 1.96 KB
/
Program.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
namespace MapPortingUtility
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
internal static class Program
{
public const string PATHS_FILE_NAME = "PATHS.YML";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public static bool ReadPaths(out Paths paths)
{
paths = new Paths();
if (System.IO.File.Exists(PATHS_FILE_NAME)) {
try {
var deserializer = new YamlDotNet.Serialization.DeserializerBuilder()
.IgnoreUnmatchedProperties()
.IgnoreFields()
.Build();
paths = deserializer.Deserialize<Paths>(System.IO.File.ReadAllText(PATHS_FILE_NAME));
return true;
}
catch {
return false;
}
}
return false;
}
public static void WritePaths(Paths paths)
{
var serializer = new YamlDotNet.Serialization.SerializerBuilder()
.IgnoreFields()
.Build();
try {
string pathsStr = serializer.Serialize(paths);
System.IO.File.WriteAllText(PATHS_FILE_NAME, pathsStr);
}
catch (Exception e) {
MessageBox.Show($"An error occured while writing paths:\n{e}\n\nYou may have to configure your paths again next time you launch the program", "Error while writing paths", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}