2 using System.Collections.Generic;
5 using System.Xml.Serialization;
9 [XmlRoot("TsoMqoConfig")]
13 public struct KeyAndValue
17 [XmlAttribute("value")]
20 public KeyAndValue(string k, string v)
27 public static Config Instance;
29 public static string AssemblyPath { get { return Path.GetDirectoryName(Type.Assembly.Location); } }
30 public static string ConfigFile { get { return Path.Combine(AssemblyPath, "config.xml"); } }
31 public static Type Type { get { return typeof(Config); } }
33 [XmlElement("object_bone_list")]
34 public List<KeyAndValue> object_bone_list = new List<KeyAndValue>();
36 public Dictionary<string, string> object_bone_map = new Dictionary<string, string>();
43 public static void Load()
47 using (FileStream fs = File.OpenRead(ConfigFile))
49 XmlSerializer s = new XmlSerializer(Type);
50 Instance = s.Deserialize(fs) as Config;
51 Instance.AfterDeserialize();
54 catch (Exception exception)
56 System.Diagnostics.Debug.WriteLine(exception.ToString());
57 Instance = new Config();
61 public static void Save()
65 using (FileStream fs = File.OpenWrite(ConfigFile))
68 XmlSerializer s = new XmlSerializer(Type);
69 Instance.BeforeSerialize();
70 s.Serialize(fs, Instance);
74 catch (Exception exception)
76 System.Diagnostics.Debug.WriteLine(exception.ToString());
80 public void BeforeSerialize()
82 object_bone_list.Clear();
84 foreach (string i in object_bone_map.Keys)
85 object_bone_list.Add(new KeyAndValue(i, object_bone_map[i]));
88 public void AfterDeserialize()
90 object_bone_map.Clear();
92 foreach (KeyAndValue i in object_bone_list)
93 object_bone_map.Add(i.Key, i.Value);