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 // ReSharper disable once IdentifierTypo
\r
35 public double CondRegenTime { get; set; }
\r
36 public ExMapInfo.ExMapState ExMapState { get; set; }
\r
37 public QuestStatus[] QuestList { get; set; }
\r
38 public QuestCount[] QuestCountList { get; set; }
\r
39 public DateTime QuestLastReset { get; set; }
\r
41 private const string FileName = "status.xml";
\r
42 private static readonly string StatusFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileName);
\r
46 CondRegenTime = double.MinValue;
\r
54 var serializer = new XmlSerializer(typeof(Status));
\r
56 using (var file = File.OpenText(StatusFile))
\r
57 status = (Status)serializer.Deserialize(file);
\r
58 foreach (var property in GetType().GetProperties())
\r
59 property.SetValue(this, property.GetValue(status, null), null);
\r
61 catch (FileNotFoundException)
\r
64 catch (InvalidOperationException ex)
\r
66 throw new Exception(FileName + "が壊れています。", ex);
\r
76 var serializer = new XmlSerializer(typeof(Status));
\r
77 using (var file = File.CreateText(StatusFile + ".tmp"))
\r
78 serializer.Serialize(file, this);
\r
79 File.Copy(StatusFile + ".tmp", StatusFile, true);
\r
80 File.Delete(StatusFile + ".tmp");
\r