OSDN Git Service

艦娘一覧のグループ分け機能を実装する
[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 ShipListConfig\r
43     {\r
44         public Point Location { get; set; }\r
45         public Size Size { get; set; }\r
46         public bool ShipType { get; set; }\r
47         public List<int>[] ShipGroup { get; set; }\r
48 \r
49         public ShipListConfig()\r
50         {\r
51             Location = new Point(int.MinValue, int.MinValue);\r
52             ShipGroup = new List<int>[ShipListForm.GroupCount];\r
53             for (var i = 0; i < ShipGroup.Length; i++)\r
54                 ShipGroup[i] = new List<int>();\r
55         }\r
56     }\r
57 \r
58     public class Config\r
59     {\r
60         private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json");\r
61 \r
62         public Point Location { get; set; }\r
63         public bool TopMost { get; set; }\r
64         public bool HideOnMinimized { get; set; }\r
65         public bool FlashWindow { get; set; }\r
66         public bool ShowBaloonTip { get; set; }\r
67         public bool PlaySound { get; set; }\r
68         public int MarginShips { get; set; }\r
69         public int MarginEquips { get; set; }\r
70         public List<int> NotifyConditions { get; set; }\r
71         public List<int> ResetHours { get; set; }\r
72         public int SoundVolume { get; set; }\r
73         public string MissionSoundFile { get; set; }\r
74         public string NDockSoundFile { get; set; }\r
75         public string KDockSoundFile { get; set; }\r
76         public string MaxShipsSoundFile { get; set; }\r
77         public string MaxEquipsSoundFile { get; set; }\r
78         public string DamagedShipSoundFile { get; set; }\r
79         public string Akashi20MinSoundFile { get; set; }\r
80         public string AkashiProgressSoundFile { get; set; }\r
81         public string ConditionSoundFile { get; set; }\r
82         public bool Logging { get; set; }\r
83         public string LogFile { get; set; }\r
84         public ProxyConfig Proxy { get; set; }\r
85         public ShipListConfig ShipList { get; set; }\r
86 \r
87         public Config()\r
88         {\r
89             Location = new Point(int.MinValue, int.MinValue);\r
90             FlashWindow = ShowBaloonTip = PlaySound = true;\r
91             MarginShips = 4;\r
92             MarginEquips = 10;\r
93             NotifyConditions = new List<int>(new[] {40, 49});\r
94             ResetHours = new List<int>();\r
95             SoundVolume = 100;\r
96             var dir = Path.GetDirectoryName(Application.ExecutablePath);\r
97 // ReSharper disable AssignNullToNotNullAttribute\r
98             MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
99             NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
100             KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
101             MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
102             MaxEquipsSoundFile = Path.Combine(dir, "soubi.mp3");\r
103             DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3");\r
104             Akashi20MinSoundFile = Path.Combine(dir, "20min.mp3");\r
105             AkashiProgressSoundFile = Path.Combine(dir, "syuuri.mp3");\r
106             ConditionSoundFile = Path.Combine(dir, "hirou.mp3");\r
107             LogFile = Path.Combine(dir, "log.txt");\r
108 // ReSharper restore AssignNullToNotNullAttribute\r
109             Proxy = new ProxyConfig();\r
110             ShipList = new ShipListConfig();\r
111         }\r
112 \r
113         public void Load()\r
114         {\r
115             try\r
116             {\r
117                 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
118                 foreach (var property in GetType().GetProperties())\r
119                     property.SetValue(this, property.GetValue(config, null), null);\r
120             }\r
121             catch (FileNotFoundException)\r
122             {\r
123             }\r
124         }\r
125 \r
126         public void Save()\r
127         {\r
128             File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
129         }\r
130     }\r
131 }