1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using System.Collections.Generic;
\r
18 using System.Xml.Serialization;
\r
20 namespace KancolleSniffer.Model
\r
22 public interface IHaveState
\r
24 bool NeedSave { get; }
\r
25 void SaveState(Status status);
\r
26 void LoadState(Status status);
\r
31 public static bool Restoring { get; set; }
\r
32 public Achievement Achievement { get; set; }
\r
33 public List<MaterialCount> MaterialHistory { get; set; }
\r
34 public double CondRegenTime { get; set; }
\r
35 public ExMapInfo.ExMapState ExMapState { get; set; }
\r
36 public QuestStatus[] QuestList { get; set; }
\r
37 public QuestCount[] QuestCountList { get; set; }
\r
38 public DateTime QuestLastReset { get; set; }
\r
40 private const string FileName = "status.xml";
\r
41 private static readonly string StatusFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
\r
45 CondRegenTime = double.MinValue;
\r
53 var serializer = new XmlSerializer(typeof(Status));
\r
55 using (var file = File.OpenText(StatusFile))
\r
56 status = (Status)serializer.Deserialize(file);
\r
57 foreach (var property in GetType().GetProperties())
\r
58 property.SetValue(this, property.GetValue(status, null), null);
\r
60 catch (FileNotFoundException)
\r
63 catch (InvalidOperationException ex)
\r
65 throw new Exception(FileName + "が壊れています。", ex);
\r
75 var serializer = new XmlSerializer(typeof(Status));
\r
76 using (var file = File.CreateText(StatusFile + ".tmp"))
\r
77 serializer.Serialize(file, this);
\r
78 File.Copy(StatusFile + ".tmp", StatusFile, true);
\r
79 File.Delete(StatusFile + ".tmp");
\r