OSDN Git Service

C# 6.0の記法を使用する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Config.cs
1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\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 const int DefaultListenPort = 8080;\r
29         public const string AutoConfigUrl = "http://kancollesniffer.osdn.jp/proxy.pac";\r
30         public bool Auto { get; set; }\r
31         public int Listen { get; set; }\r
32         public bool UseUpstream { get; set; }\r
33         public int UpstreamPort { get; set; }\r
34 \r
35         public ProxyConfig()\r
36         {\r
37             Auto = true;\r
38             Listen = DefaultListenPort;\r
39             UseUpstream = false;\r
40             UpstreamPort = 8888;\r
41         }\r
42 \r
43         public ProxyConfig Clone() => (ProxyConfig)MemberwiseClone();\r
44     }\r
45 \r
46     public class ShipListConfig\r
47     {\r
48         public Point Location { get; set; }\r
49         public Size Size { get; set; }\r
50         public bool ShipType { get; set; }\r
51         public List<int>[] ShipGroup { get; set; }\r
52 \r
53         public ShipListConfig()\r
54         {\r
55             Location = new Point(int.MinValue, int.MinValue);\r
56             ShipGroup = new List<int>[ShipListForm.GroupCount];\r
57             for (var i = 0; i < ShipGroup.Length; i++)\r
58                 ShipGroup[i] = new List<int>();\r
59         }\r
60     }\r
61 \r
62     public class LogConfig\r
63     {\r
64         public bool On { get; set; }\r
65         public string OutputDir { get; set; }\r
66         public int MaterialLogInterval { get; set; }\r
67         public bool ServerOn { get; set; }\r
68         public int Listen { get; set; }\r
69 \r
70         public LogConfig()\r
71         {\r
72             On = true;\r
73             OutputDir = Path.GetDirectoryName(Application.ExecutablePath);\r
74             MaterialLogInterval = 10;\r
75             ServerOn = true;\r
76             Listen = 8008;\r
77         }\r
78     }\r
79 \r
80     public class Config\r
81     {\r
82         private readonly string _configFileName =\r
83             Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? "", "config.json");\r
84 \r
85         public Point Location { get; set; }\r
86         public bool TopMost { get; set; }\r
87         public bool HideOnMinimized { get; set; }\r
88         public bool FlashWindow { get; set; }\r
89         public bool ShowBaloonTip { get; set; }\r
90         public bool PlaySound { get; set; }\r
91         public int MarginShips { get; set; }\r
92         public int MarginEquips { get; set; }\r
93         public List<int> NotifyConditions { get; set; }\r
94         public List<int> ResetHours { get; set; }\r
95         public bool AlwaysShowResultRank { get; set; }\r
96         public int SoundVolume { get; set; }\r
97         public string MissionSoundFile { get; set; }\r
98         public string NDockSoundFile { get; set; }\r
99         public string KDockSoundFile { get; set; }\r
100         public string MaxShipsSoundFile { get; set; }\r
101         public string MaxEquipsSoundFile { get; set; }\r
102         public string DamagedShipSoundFile { get; set; }\r
103         public string Akashi20MinSoundFile { get; set; }\r
104         public string AkashiProgressSoundFile { get; set; }\r
105         public string AkashiCompleteSoundFile { get; set; }\r
106         public string ConditionSoundFile { get; set; }\r
107         public bool DebugLogging { get; set; }\r
108         public string DebugLogFile { get; set; }\r
109         public ProxyConfig Proxy { get; set; }\r
110         public ShipListConfig ShipList { get; set; }\r
111         public LogConfig Log { get; set; }\r
112 \r
113         public Config()\r
114         {\r
115             Location = new Point(int.MinValue, int.MinValue);\r
116             FlashWindow = ShowBaloonTip = PlaySound = true;\r
117             MarginShips = 4;\r
118             MarginEquips = 10;\r
119             NotifyConditions = new List<int>(new[] {40, 49});\r
120             ResetHours = new List<int>(new[] {2});\r
121             AlwaysShowResultRank = false;\r
122             SoundVolume = 100;\r
123             var dir = Path.GetDirectoryName(Application.ExecutablePath) ?? "";\r
124             MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
125             NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
126             KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
127             MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
128             MaxEquipsSoundFile = Path.Combine(dir, "soubi.mp3");\r
129             DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3");\r
130             Akashi20MinSoundFile = Path.Combine(dir, "20min.mp3");\r
131             AkashiProgressSoundFile = Path.Combine(dir, "syuuri.mp3");\r
132             AkashiCompleteSoundFile = Path.Combine(dir, "syuuri2.mp3");\r
133             ConditionSoundFile = Path.Combine(dir, "hirou.mp3");\r
134             DebugLogFile = Path.Combine(dir, "log.txt");\r
135             Proxy = new ProxyConfig();\r
136             ShipList = new ShipListConfig();\r
137             Log = new LogConfig();\r
138         }\r
139 \r
140         public void Load()\r
141         {\r
142             try\r
143             {\r
144                 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
145                 foreach (var property in GetType().GetProperties())\r
146                     property.SetValue(this, property.GetValue(config, null), null);\r
147             }\r
148             catch (FileNotFoundException)\r
149             {\r
150             }\r
151         }\r
152 \r
153         public void Save()\r
154         {\r
155             File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
156         }\r
157     }\r
158 }