OSDN Git Service

assign node.path and node.local_position.
[tdcgexplorer/tso2mqo.git] / Config.cs
index e9b497c..23265ce 100644 (file)
--- a/Config.cs
+++ b/Config.cs
@@ -1,90 +1,96 @@
-using System;\r
-using System.Collections.Generic;\r
-using System.IO;\r
-using System.Text;\r
-using System.Xml.Serialization;\r
-\r
-namespace Tso2MqoGui\r
-{\r
-    [XmlRoot("TsoMqoConfig")]\r
-    [Serializable]\r
-    public class Config\r
-    {\r
-        public struct KeyAndValue\r
-        {\r
-            [XmlAttribute("key")]   public string   Key;\r
-            [XmlAttribute("value")] public string   Value;\r
-\r
-            public KeyAndValue(string k, string v)\r
-            {\r
-                Key     = k;\r
-                Value   = v;\r
-            }\r
-        }\r
-\r
-        public static Config    Instance;\r
-\r
-        public static string    AssemblyPath    { get { return Path.GetDirectoryName(Type.Assembly.Location); } }\r
-        public static string    ConfigFile      { get { return Path.Combine(AssemblyPath, "config.xml"); } }\r
-        public static Type      Type            { get { return typeof(Config); } }\r
-\r
-        [XmlElement("object_bone_list")] public List<KeyAndValue>   object_bone_list    = new List<KeyAndValue>();\r
-        [XmlIgnore] public Dictionary<string, string>               object_bone_map     = new Dictionary<string,string>();\r
-\r
-        static Config()\r
-        {\r
-            Load();\r
-        }\r
-\r
-        public static void Load()\r
-        {\r
-            try\r
-            {\r
-                using(FileStream fs= File.OpenRead(ConfigFile))\r
-                {\r
-                    XmlSerializer   s   = new XmlSerializer(Type);\r
-                    Instance            = s.Deserialize(fs) as Config;\r
-                    Instance.AfterDeserialize();\r
-                }\r
-            } catch(Exception e)\r
-            {\r
-                System.Diagnostics.Debug.WriteLine(e.ToString());\r
-                Instance                = new Config();\r
-            }\r
-        }\r
-\r
-        public static void Save()\r
-        {\r
-            try\r
-            {\r
-                using(FileStream fs= File.OpenWrite(ConfigFile))\r
-                {\r
-                    fs.SetLength(0);\r
-                    XmlSerializer   s   = new XmlSerializer(Type);\r
-                    Instance.BeforeSerialize();\r
-                    s.Serialize(fs, Instance);\r
-                    fs.Flush();\r
-                }\r
-            } catch(Exception e)\r
-            {\r
-                System.Diagnostics.Debug.WriteLine(e.ToString());\r
-            }\r
-        }\r
-\r
-        public void BeforeSerialize()\r
-        {\r
-            object_bone_list.Clear();\r
-\r
-            foreach(string i in object_bone_map.Keys)\r
-                object_bone_list.Add(new KeyAndValue(i, object_bone_map[i]));\r
-        }\r
-\r
-        public void AfterDeserialize()\r
-        {\r
-            object_bone_map.Clear();\r
-\r
-            foreach(KeyAndValue i in object_bone_list)\r
-                object_bone_map.Add(i.Key, i.Value);\r
-        }\r
-    }\r
-}\r
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Xml.Serialization;
+
+namespace Tso2MqoGui
+{
+    [XmlRoot("TsoMqoConfig")]
+    [Serializable]
+    public class Config
+    {
+        public struct KeyAndValue
+        {
+            [XmlAttribute("key")]
+            public string Key;
+            [XmlAttribute("value")]
+            public string Value;
+
+            public KeyAndValue(string k, string v)
+            {
+                Key = k;
+                Value = v;
+            }
+        }
+
+        public static Config Instance;
+
+        public static string AssemblyPath { get { return Path.GetDirectoryName(Type.Assembly.Location); } }
+        public static string ConfigFile { get { return Path.Combine(AssemblyPath, "config.xml"); } }
+        public static Type Type { get { return typeof(Config); } }
+
+        [XmlElement("object_bone_list")]
+        public List<KeyAndValue> object_bone_list = new List<KeyAndValue>();
+        [XmlIgnore]
+        public Dictionary<string, string> object_bone_map = new Dictionary<string, string>();
+
+        static Config()
+        {
+            Load();
+        }
+
+        public static void Load()
+        {
+            try
+            {
+                using (FileStream fs = File.OpenRead(ConfigFile))
+                {
+                    XmlSerializer s = new XmlSerializer(Type);
+                    Instance = s.Deserialize(fs) as Config;
+                    Instance.AfterDeserialize();
+                }
+            }
+            catch (Exception exception)
+            {
+                System.Diagnostics.Debug.WriteLine(exception.ToString());
+                Instance = new Config();
+            }
+        }
+
+        public static void Save()
+        {
+            try
+            {
+                using (FileStream fs = File.OpenWrite(ConfigFile))
+                {
+                    fs.SetLength(0);
+                    XmlSerializer s = new XmlSerializer(Type);
+                    Instance.BeforeSerialize();
+                    s.Serialize(fs, Instance);
+                    fs.Flush();
+                }
+            }
+            catch (Exception exception)
+            {
+                System.Diagnostics.Debug.WriteLine(exception.ToString());
+            }
+        }
+
+        public void BeforeSerialize()
+        {
+            object_bone_list.Clear();
+
+            foreach (string i in object_bone_map.Keys)
+                object_bone_list.Add(new KeyAndValue(i, object_bone_map[i]));
+        }
+
+        public void AfterDeserialize()
+        {
+            object_bone_map.Clear();
+
+            foreach (KeyAndValue i in object_bone_list)
+                object_bone_map.Add(i.Key, i.Value);
+        }
+    }
+}
\ No newline at end of file