OSDN Git Service

終了時に戦果がリセットされないようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Status.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 Status\r
25     {\r
26         private readonly string _statusFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),\r
27             "status.json");\r
28 \r
29         public int ExperiencePoint { get; set; }\r
30 \r
31         public void Load()\r
32         {\r
33             try\r
34             {\r
35                 var obj = (Status)DynamicJson.Parse(File.ReadAllText(_statusFileName));\r
36                 foreach (var property in GetType().GetProperties())\r
37                     property.SetValue(this, property.GetValue(obj, null), null);\r
38             }\r
39             catch (FileNotFoundException)\r
40             {\r
41             }\r
42         }\r
43 \r
44         public void Save()\r
45         {\r
46             File.WriteAllText(_statusFileName, DynamicJson.Serialize(this));\r
47         }\r
48     }\r
49 }\r