annotate Preferences.cs @ 120:780169621672

* Remove rogue print statement
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Nov 2012 20:51:49 +0000
parents 0f88d32b22cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
1 // This file (Preferences.cs) is a part of the IBBoard library and is copyright 2009 IBBoard.
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
2 //
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
0352fa33ee8f Closes #8 - license code
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
4
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
5 using System;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
6 using System.Collections;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
7 using System.IO;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
8 using System.Xml;
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.Reflection;
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
10 using IBBoard.IO;
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
12 //TODO: Add import/export
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
13 namespace IBBoard
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
14 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
15 /// <summary>
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
16 /// Summary description for Preferences.
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
17 /// </summary>
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
18 public class Preferences
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
19 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
20 private static Type stringType = typeof(string);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
21 private static Type hashtableType = typeof(Hashtable);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
22 private Hashtable htGlobal;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
23 private Hashtable htLocal;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
24
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
25 private string app;
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 private bool modified = false;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 public Preferences(string appName)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 app = appName;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 LoadPreferences();
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
33 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
34
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
35 private void LoadPreferences()
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
36 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
37 htGlobal = new Hashtable();
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 htLocal = new Hashtable();
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
40 string globalPath = Path.Combine(Constants.ExecutablePath, app + "Pref.xml");
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 if (File.Exists(globalPath))
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
43 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
44 XmlDocument xmld = new XmlDocument();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
45 xmld.Load(globalPath);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
46 XmlNodeList nl = xmld.LastChild.ChildNodes;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
47 XmlNodeList nlHash;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
48 MethodInfo m;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
49 Type t;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
50 Hashtable htTemp;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
51
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
52 if (nl == null || nl.Count==0)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
53 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
54 throw new InvalidFileException("Preference file "+globalPath+" did not contain any preferences");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
55 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
56
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
57 for (int i = 0; i<nl.Count; i++)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
58 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
59 t = Type.GetType(nl[i].Attributes["type"].Value, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
60
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
61 if (t!=stringType)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
62 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
63 if (t==hashtableType)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
64 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
65 htTemp = new Hashtable();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
66 nlHash = nl[i].ChildNodes;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
67
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
68 for (int j = 0; j<nlHash.Count; j++)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
69 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
70 if (nlHash[j].NodeType.GetType()==typeof(XmlElement))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
71 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
72 t = Type.GetType(nlHash[j].Attributes["type"].Value, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
73 m = t.GetMethod("Parse", new Type[]{stringType});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
74 htTemp[nlHash[j].Attributes["key"].Value] = m.Invoke(null, new object[]{nlHash[j].InnerText});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
75 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
76 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
77
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
78 htGlobal[nl[i].Attributes["id"].Value] = htTemp;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
79 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
80 else if (t.IsEnum)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
81 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
82 htGlobal[nl[i].Attributes["id"].Value] = Enum.Parse(t, nl[i].InnerText, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
83 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
84 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
85 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
86 m = t.GetMethod("Parse", new Type[]{stringType});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
87 htGlobal[nl[i].Attributes["id"].Value] = m.Invoke(null, new object[]{nl[i].InnerText});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
88 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
89 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
90 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
91 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
92 htGlobal[nl[i].Attributes["id"].Value] = nl[i].InnerText;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
93 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
94 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
95
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
96 LoadLocalPreferences();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
97 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
98 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
99 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
100 throw new FileNotFoundException("Could not find default preferences at "+globalPath);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
101 }
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 }
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
103
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
104 private void LoadLocalPreferences()
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
105 {
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
106 string path = Path.Combine(Constants.UserDataPath, "preferences.xml");
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
107
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
108 if (File.Exists(path))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
109 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
110 XmlDocument xmld = new XmlDocument();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
111 xmld.Load(path);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
112 XmlNodeList nl = xmld.LastChild.ChildNodes;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
113 XmlNodeList nlHash;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
114 MethodInfo m;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
115 Type t;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
116 Hashtable htTemp = new Hashtable();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
117
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
118 nl = xmld.LastChild.ChildNodes;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
119
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
120 for (int i = 0; i<nl.Count; i++)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
121 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
122 if (!htGlobal.ContainsKey(nl[i].Attributes["id"].Value))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
123 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
124 throw new InvalidFileException("User preferences file contains a value for key \""+nl[i].Attributes["id"].Value+"\" which is not contained in the main preferences");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
125 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
126
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
127 t = Type.GetType(nl[i].Attributes["type"].Value, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
128 if (t!=stringType)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
129 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
130 if (t==hashtableType)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
131 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
132 htTemp = new Hashtable();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
133 nlHash = nl[i].ChildNodes;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
134 Hashtable htTempInner = new Hashtable();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
135
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
136 for (int j = 0; j<nlHash.Count; j++)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
137 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
138 if (nlHash[j].NodeType==XmlNodeType.Element)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
139 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
140 t = Type.GetType(nlHash[j].Attributes["type"].Value, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
141 m = t.GetMethod("Parse", new Type[]{stringType});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
142 htTempInner[nlHash[j].Attributes["key"].Value] = m.Invoke(null, new object[]{nlHash[j].InnerText});
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
143 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
144 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
145
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
146 htTemp[nl[i].Attributes["id"].Value] = htTempInner;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
147 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
148 else if (t.IsEnum)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
149 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
150 htTemp[nl[i].Attributes["id"].Value] = Enum.Parse(t, nl[i].InnerText, true);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
151 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
152 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
153 {
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 m = t.GetMethod("Parse", new Type[]{stringType});
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 if (m!=null)
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
157 {
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 htTemp[nl[i].Attributes["id"].Value] = m.Invoke(null, new object[]{nl[i].InnerText});
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
159 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
160 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
161 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
162 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
163 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
164 htTemp[nl[i].Attributes["id"].Value] = nl[i].InnerText;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
165 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
166 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
167
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
168 htLocal = htTemp;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
169 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
170 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
171
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
172 public void ReloadPreferences()
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
173 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
174 htLocal.Clear();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
175 LoadLocalPreferences();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
176 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
177
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
178 public object this[string key]
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 {
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
180 get { return this[key, true]; }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
181
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
182 set
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
183 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
184 if (!htGlobal.ContainsKey(key))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
185 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
186 throw new InvalidOperationException("Preference must already exist in the Global Preferences");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
187 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
188
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
189 if (htGlobal[key].GetType()!=value.GetType())
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
190 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
191 throw new InvalidOperationException("Preferences must be set with an object of the same type as the existing preference");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
192 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
193
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
194 if (value is Hashtable)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
195 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
196 throw new InvalidOperationException("Hashtables in Preferences cannot be set, they can only be added to or removed from.");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
197 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
198
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
199 if (htGlobal[key].Equals(value))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
200 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
201 if (htLocal.ContainsKey(key))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
202 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
203 htLocal.Remove(key);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
204 modified = true;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
205 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
206 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
207 else if (!((htLocal[key]==null && value==null) || value.Equals(htLocal[key])))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
208 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
209 htLocal[key] = value;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
210 modified = true;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
211 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
212 //else nothing actually needs modifying
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
215
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 public object this[string key, bool errorOnNoVal]
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
217 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
218 get
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
219 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
220 if (htLocal.ContainsKey(key))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
221 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
222 return htLocal[key];
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
223 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
224 else if (htGlobal.ContainsKey(key))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
225 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
226 if (htGlobal[key] is Hashtable)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
227 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
228 htLocal[key] = ((Hashtable)htGlobal[key]).Clone();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
229 return htLocal[key];
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
230 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
231 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
232 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
233 return htGlobal[key];
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
234 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
235 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
236 else if (errorOnNoVal)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
237 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
238 throw new InvalidOperationException("Key \""+key+"\" was not associated with a preference value");
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
241 return null;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
242 }
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 public bool GetBooleanProperty(string key)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 object obj = this[key, false];
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 bool val = false;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 if (obj is bool)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 obj = (bool)obj;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 return val;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258 public string GetStringProperty(string key)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 object obj = this[key, false];
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 string str = null;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 if (obj is String)
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 str = (String)obj;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 return str;
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
271 //public String
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
272
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
273 public bool IsModified()
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
274 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
275 return modified;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
276 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
277
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
278 public void Save()
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
279 {
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
280 string prefPath = Path.Combine(Constants.UserDataPath, "preferences.xml");
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
281
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
282 if (htLocal.Count>0)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
283 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
284 XmlDocument xmld = new XmlDocument();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
285 xmld.LoadXml("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
286 "<!DOCTYPE prefs["+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
287 "<!ELEMENT preferences (preferece*)> "+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
288 "<!ELEMENT preference (CDATA|prefsub)> "+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
289 "<!ELEMENT prefsub (CDATA)> "+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
290 "<!ATTLIST preference id ID #REQUIRED>"+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
291 "<!ATTLIST preference type CDATA #REQUIRED>"+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
292 "<!ATTLIST prefsub key CDATA #REQUIRED>"+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
293 "<!ATTLIST prefsub type CDATA #REQUIRED>"+
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
294 "]>"+"<preferences></preferences>");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
295 XmlNode xmln = xmld.LastChild;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
296 XmlNode pref;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
297 XmlAttribute attr;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
298 XmlNode prefSub;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
299 XmlAttribute attrSub;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
300 object o;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
301 Hashtable htTemp;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
302 Hashtable htGlobalTemp;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
303
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
304 foreach (string key in htLocal.Keys)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
305 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
306 pref = xmld.CreateNode(XmlNodeType.Element, "preference","");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
307 attr = xmld.CreateAttribute("id");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
308 attr.Value = key;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
309 pref.Attributes.Append(attr);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
310 attr = xmld.CreateAttribute("type");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
311 o = htLocal[key];
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
312
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
313 attr.Value = o.GetType().AssemblyQualifiedName;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
314
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
315 if (o.GetType().ToString() == "System.Collections.Hashtable")
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
316 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
317 htTemp = (Hashtable)o;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
318 htGlobalTemp = (Hashtable)htGlobal[key];
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
319
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
320 foreach(object subkey in htTemp.Keys)
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
321 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
322 if (!htGlobalTemp.ContainsKey(subkey) || !htGlobalTemp[subkey].Equals(htTemp[subkey]))
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
323 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
324 prefSub = xmld.CreateNode(XmlNodeType.Element, "prefsub", "");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
325 attrSub = xmld.CreateAttribute("key");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
326 attrSub.Value = subkey.ToString();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
327 prefSub.Attributes.Append(attrSub);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
328 attrSub = xmld.CreateAttribute("type");
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
329 attrSub.Value = htTemp[subkey].GetType().AssemblyQualifiedName;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
330 prefSub.Attributes.Append(attrSub);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
331 prefSub.InnerText = htTemp[subkey].ToString();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
332 pref.AppendChild(prefSub);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
333 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
334 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
335 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
336 else
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
337 {
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
338 pref.InnerText = o.ToString();
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
339 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
340
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
341 pref.Attributes.Append(attr);
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
342 xmln.AppendChild(pref);
0
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 }
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 if (!Directory.Exists(Constants.UserDataPath))
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346 {
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 Directory.CreateDirectory(Constants.UserDataPath);
961030992bd2 Initial commit of IBBoard libraries
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 }
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
349
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
350 xmld.Save(prefPath);
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
351 }
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
352 else if (File.Exists(prefPath))
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
353 {
107
0f88d32b22cc * Swap to built-in .Net methods (listed on http://www.ironshay.com/post/Use-NET-Built-in-Methods-to-Save-Time-and-Headaches.aspx)
IBBoard <dev@ibboard.co.uk>
parents: 37
diff changeset
354 File.Delete(prefPath);
37
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
355 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
356
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
357 modified = false;
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
358 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
359 }
cc7fae81afec * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 16
diff changeset
360 }