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
\r
22 public interface IHaveState
\r
24 bool NeedSave { get; }
\r
25 void SaveState(Status status);
\r
26 void LoadState(Status status);
\r
31 private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory;
\r
32 private readonly string _statusFileName;
\r
33 public static bool Restoring { get; set; }
\r
34 public Achievement Achievement { get; set; }
\r
35 public List<MaterialCount> MaterialHistory { get; set; }
\r
36 public double CondRegenTime { get; set; }
\r
37 public ExMapInfo.ExMapState ExMapState { get; set; }
\r
41 _statusFileName = Path.Combine(_baseDir, "status.xml");
\r
42 CondRegenTime = double.MinValue;
\r
50 var serializer = new XmlSerializer(typeof(Status));
\r
52 using (var file = File.OpenText(_statusFileName))
\r
53 status = (Status)serializer.Deserialize(file);
\r
54 foreach (var property in GetType().GetProperties())
\r
55 property.SetValue(this, property.GetValue(status, null), null);
\r
57 catch (FileNotFoundException)
\r
69 var serializer = new XmlSerializer(typeof(Status));
\r
70 using (var file = File.CreateText(_statusFileName))
\r
71 serializer.Serialize(file, this);
\r
74 public void ReadOldStatus()
\r
76 var old = Path.Combine(_baseDir, "status.json");
\r
80 json = JsonParser.Parse(File.ReadAllText(old));
\r
82 catch (FileNotFoundException)
\r
86 var ac = json.Achievement;
\r
87 Achievement = new Achievement
\r
89 Start = (int)ac.Start,
\r
90 StartOfMonth = (int)ac.StartOfMonth,
\r
91 LastReset = DateTime.Parse(ac.LastReset),
\r
92 LastResetOfMonth = DateTime.Parse(ac.LastResetOfMonth),
\r
93 ResetHours = new List<int>((int[])ac.ResetHours),
\r
95 var history = new List<MaterialCount>();
\r
96 foreach (var h in json.MatreialHistory)
\r
98 history.Add(new MaterialCount
\r
100 BegOfDay = (int)h.BegOfDay,
\r
101 BegOfWeek = (int)h.BegOfWeek,
\r
103 LastSet = DateTime.Parse(h.LastSet)
\r
106 MaterialHistory = history;
\r
107 CondRegenTime = json.CondRegenTime;
\r
108 ExMapState = new ExMapInfo.ExMapState();
\r
109 var clear = new List<ExMapInfo.ClearStatus>();
\r
110 foreach (var cs in json.ExMapState.ClearStatusList)
\r
112 clear.Add(new ExMapInfo.ClearStatus
\r
115 Cleared = cs.Cleared,
\r
116 Rate = (int)cs.Rate,
\r
119 ExMapState.ClearStatusList = clear;
\r