| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Text;
|
|---|
| 4 | using System.Xml.Serialization;
|
|---|
| 5 | using System.IO;
|
|---|
| 6 |
|
|---|
| 7 | namespace 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 | }
|
|---|