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 Config\r
27     {\r
28         private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json");\r
29 \r
30         public Point Location { get; set; }\r
31         public bool TopMost { get; set; }\r
32         public bool FlashWindow { get; set; }\r
33         public bool ShowBaloonTip { get; set; }\r
34         public bool PlaySound { get; set; }\r
35         public int MarginShips { get; set; }\r
36         public List<int> ResetHours { get; set; }\r
37         public int SoundVolume { get; set; }\r
38         public string MissionSoundFile { get; set; }\r
39         public string NDockSoundFile { get; set; }\r
40         public string KDockSoundFile { get; set; }\r
41         public string MaxShipsSoundFile { get; set; }\r
42         public string DamagedShipSoundFile { get; set; }\r
43 \r
44         public Config()\r
45         {\r
46             Location = new Point(int.MinValue, int.MinValue);\r
47             FlashWindow = ShowBaloonTip = PlaySound = true;\r
48             MarginShips = 4;\r
49             ResetHours = new List<int>();\r
50             SoundVolume = 100;\r
51             var dir = Path.GetDirectoryName(Application.ExecutablePath);\r
52 // ReSharper disable AssignNullToNotNullAttribute\r
53             MissionSoundFile = Path.Combine(dir, "ensei.mp3");\r
54             NDockSoundFile = Path.Combine(dir, "nyuukyo.mp3");\r
55             KDockSoundFile = Path.Combine(dir, "kenzou.mp3");\r
56             MaxShipsSoundFile = Path.Combine(dir, "kanmusu.mp3");\r
57             DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3");\r
58 // ReSharper restore AssignNullToNotNullAttribute\r
59         }\r
60 \r
61         public void Load()\r
62         {\r
63             try\r
64             {\r
65                 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));\r
66                 foreach (var property in GetType().GetProperties())\r
67                     property.SetValue(this, property.GetValue(config, null), null);\r
68             }\r
69             catch (FileNotFoundException)\r
70             {\r
71             }\r
72         }\r
73 \r
74         public void Save()\r
75         {\r
76             File.WriteAllText(_configFileName, DynamicJson.Serialize(this));\r
77         }\r
78     }\r
79 }