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.IO;\r
19 using System.Windows.Forms;\r
20 using Codeplex.Data;\r
21 \r
22 namespace KancolleSniffer\r
23 {\r
24     public class Config\r
25     {\r
26         private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json");\r
27 \r
28         public bool FlashWindow { get; set; }\r
29         public bool ShowBaloonTip { get; set; }\r
30         public bool PlaySound { get; set; }\r
31         public int MarginShips { get; set; }\r
32         public int SoundVolume { get; set; }\r
33         public string MissionSoundFile { get; set; }\r
34         public string NDockSoundFile { get; set; }\r
35         public string KDockSoundFile { get; set; }\r
36         public string MaxShipsSoundFile { get; set; }\r
37 \r
38         public Config()\r
39         {\r
40             FlashWindow = ShowBaloonTip = PlaySound = true;\r
41             MarginShips = 4;\r
42             SoundVolume = 100;\r
43             var dir = Path.GetDirectoryName(Application.ExecutablePath);\r
44 // ReSharper disable AssignNullToNotNullAttribute\r
45             MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
46             NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
47             KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
48             MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
49 // ReSharper restore AssignNullToNotNullAttribute\r
50         }\r
51 \r
52         public void Load()\r
53         {\r
54             try\r
55             {\r
56                 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
57                 foreach (var property in GetType().GetProperties())\r
58                     property.SetValue(this, property.GetValue(config, null), null);\r
59             }\r
60             catch (FileNotFoundException)\r
61             {\r
62             }\r
63         }\r
64 \r
65         public void Save()\r
66         {\r
67             File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
68         }\r
69     }\r
70 }