This repository was archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSettings.cs
More file actions
90 lines (78 loc) · 1.76 KB
/
Copy pathSettings.cs
File metadata and controls
90 lines (78 loc) · 1.76 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace Pather
{
public class Settings
{
// default settings
public string FormTitle = "Form1";
public string UseMount = "Let Task Decide";
public float MountRange = 50f;
public bool MaxResurrection = false;
public int MaxResurrectionAmount = 10;
public int StopAtLevel = -1;
public string TaskFile = "PPather\\tasks.psc";
#region load/save
public const string SettingsFile = "PPather\\PPather.xml";
public void Save()
{
try
{
Stream stream = File.Create(SettingsFile);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(stream, this);
stream.Close();
}
catch
{
}
}
public void MakeDefault()
{
FormTitle = "Form1";
UseMount = "Let Task Decide";
MountRange = 50f;
MaxResurrection = false;
MaxResurrectionAmount = 10;
StopAtLevel = -1;
TaskFile = "PPather\\tasks.psc";
Save();
}
public static Settings Load()
{
try
{
Stream stream = File.OpenRead(SettingsFile);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
instance = (Settings)serializer.Deserialize(stream);
}
catch
{
// in case the xml file does not exist, use the default settings
// that are hard coded in the class definition
instance = new Settings();
}
return instance;
}
#endregion
#region Singleton
private Settings()
{
}
private static Settings instance = null;
public static Settings Instance
{
get
{
if (null == instance)
throw new NullReferenceException("Trying to access Settings instance before it has been loaded");
return instance;
}
}
#endregion
}
}