root/lang/csharp/Criw-0/SettingManager.cs @ 36255

Revision 1736, 2.1 kB (checked in by mayuki, 6 years ago)

lang/csharp: WZERO3などで動くIRCクライアントのサンプル実装 Criw-0 を追加。

  • Property svn:keywords set to Id
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml.Serialization;
5using System.IO;
6
7namespace Misuzilla.Applications.Mobile.Criw0
8{
9    public class SettingManager
10    {
11        private static XmlSerializer xmlSerializer;
12        private static Setting setting;
13
14        private SettingManager() { }
15        static SettingManager()
16        {
17            xmlSerializer = new XmlSerializer(typeof(Setting));
18            setting = new Setting();
19        }
20
21        public static Setting Setting
22        {
23            get { return setting; }
24        }
25
26        public static void Save()
27        {
28            String dir = Path.Combine(
29                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
30                @"Misuzilla\Criw-0"
31            );
32            if (!Directory.Exists(dir))
33            {
34                Directory.CreateDirectory(dir);
35            }
36            Save(setting, Path.Combine(dir, "Settings.xml"));
37        }
38        public static void Save(Setting setting, String filePath)
39        {
40            using (TextWriter w = new StreamWriter(File.Open(filePath, FileMode.Create))) {
41                Save(setting, w);
42            }
43        }
44        public static void Save(Setting setting, TextWriter writer)
45        {
46            xmlSerializer.Serialize(writer, setting);
47        }
48
49        public static void Load()
50        {
51            String path = Path.Combine(
52                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
53                @"Misuzilla\Criw-0\Settings.xml"
54            );
55           
56            if (!File.Exists(path)) return;
57
58            setting = Load(path);
59        }
60        public static Setting Load(String filePath)
61        {
62            using (StreamReader s = new StreamReader(File.OpenRead(filePath)))
63            {
64                return Load(s);
65            }
66        }
67        public static Setting Load(TextReader reader)
68        {
69            return xmlSerializer.Deserialize(reader) as Setting;
70        }
71    }
72}
Note: See TracBrowser for help on using the browser.