-// Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
+// Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
// \r
-// This program is part of KancolleSniffer.\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
//\r
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
\r
using System;\r
+using System.Collections.Generic;\r
using System.IO;\r
-using System.Windows.Forms;\r
-using Codeplex.Data;\r
+using System.Xml.Serialization;\r
\r
namespace KancolleSniffer\r
{\r
+ public interface IHaveState\r
+ {\r
+ bool NeedSave { get; }\r
+ void SaveState(Status status);\r
+ void LoadState(Status status);\r
+ }\r
+\r
public class Status\r
{\r
- private readonly string _statusFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),\r
- "status.json");\r
+ public static bool Restoring { get; set; }\r
+ public Achievement Achievement { get; set; }\r
+ public List<MaterialCount> MaterialHistory { get; set; }\r
+ public double CondRegenTime { get; set; }\r
+ public ExMapInfo.ExMapState ExMapState { get; set; }\r
+ public QuestStatus[] QuestList { get; set; }\r
+ public QuestCount[] QuestCountList { get; set; }\r
+ public DateTime QuestLastReset { get; set; }\r
\r
- public int ExperiencePoint { get; set; }\r
- public DateTime LastResetTime { get; set; }\r
+ private const string FileName = "status.xml";\r
+ private static readonly string StatusFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);\r
+\r
+ public Status()\r
+ {\r
+ CondRegenTime = double.MinValue;\r
+ }\r
\r
public void Load()\r
{\r
try\r
{\r
- var obj = (Status)DynamicJson.Parse(File.ReadAllText(_statusFileName));\r
+ Restoring = true;\r
+ var serializer = new XmlSerializer(typeof(Status));\r
+ Status status;\r
+ using (var file = File.OpenText(StatusFile))\r
+ status = (Status)serializer.Deserialize(file);\r
foreach (var property in GetType().GetProperties())\r
- property.SetValue(this, property.GetValue(obj, null), null);\r
+ property.SetValue(this, property.GetValue(status, null), null);\r
}\r
catch (FileNotFoundException)\r
{\r
}\r
+ catch (InvalidOperationException ex)\r
+ {\r
+ throw new Exception(FileName + "が壊れています。", ex);\r
+ }\r
+ finally\r
+ {\r
+ Restoring = false;\r
+ }\r
}\r
\r
public void Save()\r
{\r
- File.WriteAllText(_statusFileName, DynamicJson.Serialize(this));\r
+ var serializer = new XmlSerializer(typeof(Status));\r
+ using (var file = File.CreateText(StatusFile + ".tmp"))\r
+ serializer.Serialize(file, this);\r
+ File.Copy(StatusFile + ".tmp", StatusFile, true);\r
+ File.Delete(StatusFile + ".tmp");\r
}\r
}\r
-}\r
+}
\ No newline at end of file