OSDN Git Service

1e836af2c1e0efa1f5fa1f6ed0a9b4ba9ea7d5da
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Config.cs
1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System.Collections.Generic;\r
19 using System.Drawing;\r
20 using System.IO;\r
21 using System.Windows.Forms;\r
22 using Codeplex.Data;\r
23 \r
24 namespace KancolleSniffer\r
25 {\r
26     public class ProxyConfig\r
27     {\r
28         public bool Auto { get; set; }\r
29         public int Listen { get; set; }\r
30         public bool UseUpstream { get; set; }\r
31         public int UpstreamPort { get; set; }\r
32 \r
33         public ProxyConfig()\r
34         {\r
35             Auto = true;\r
36             Listen = 8080;\r
37             UseUpstream = false;\r
38             UpstreamPort = 8888;\r
39         }\r
40     }\r
41 \r
42     public class Config\r
43     {\r
44         private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json");\r
45 \r
46         public Point Location { get; set; }\r
47         public bool TopMost { get; set; }\r
48         public bool FlashWindow { get; set; }\r
49         public bool ShowBaloonTip { get; set; }\r
50         public bool PlaySound { get; set; }\r
51         public int MarginShips { get; set; }\r
52         public List<int> ResetHours { get; set; }\r
53         public int SoundVolume { get; set; }\r
54         public string MissionSoundFile { get; set; }\r
55         public string NDockSoundFile { get; set; }\r
56         public string KDockSoundFile { get; set; }\r
57         public string MaxShipsSoundFile { get; set; }\r
58         public string DamagedShipSoundFile { get; set; }\r
59         public string Akashi20MinSoundFile { get; set; }\r
60         public string AkashiProgressSoundFile { get; set; }\r
61         public bool Logging { get; set; }\r
62         public string LogFile { get; set; }\r
63         public ProxyConfig Proxy { get; set; }\r
64 \r
65         public Config()\r
66         {\r
67             Location = new Point(int.MinValue, int.MinValue);\r
68             FlashWindow = ShowBaloonTip = PlaySound = true;\r
69             MarginShips = 4;\r
70             ResetHours = new List<int>();\r
71             SoundVolume = 100;\r
72             var dir = Path.GetDirectoryName(Application.ExecutablePath);\r
73 // ReSharper disable AssignNullToNotNullAttribute\r
74             MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
75             NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
76             KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
77             MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
78             DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3");\r
79             Akashi20MinSoundFile = Path.Combine(dir, "20min.mp3");\r
80             AkashiProgressSoundFile = Path.Combine(dir, "syuuri.mp3");\r
81             LogFile = Path.Combine(dir, "log.txt");\r
82 // ReSharper restore AssignNullToNotNullAttribute\r
83             Proxy = new ProxyConfig();\r
84         }\r
85 \r
86         public void Load()\r
87         {\r
88             try\r
89             {\r
90                 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
91                 foreach (var property in GetType().GetProperties())\r
92                     property.SetValue(this, property.GetValue(config, null), null);\r
93             }\r
94             catch (FileNotFoundException)\r
95             {\r
96             }\r
97         }\r
98 \r
99         public void Save()\r
100         {\r
101             File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
102         }\r
103     }\r
104 }