catch (FileNotFoundException)\r
{\r
InitializeValues();\r
- ReadOldConfig();\r
Save();\r
}\r
ConvertPath(PrependBaseDir);\r
}\r
\r
private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(_baseDir, path);\r
-\r
- private void ReadOldConfig()\r
- {\r
- var old = Path.Combine(_baseDir, "config.json");\r
- dynamic json;\r
- try\r
- {\r
- json = JsonParser.Parse(File.ReadAllText(old));\r
- }\r
- catch (FileNotFoundException)\r
- {\r
- return;\r
- }\r
- Location = new Point((int)json.Location.X, (int)json.Location.Y);\r
- foreach (var property in (from prop in GetType().GetProperties()\r
- let type = prop.PropertyType\r
- where type == typeof(bool) || type == typeof(int) || type == typeof(string)\r
- select prop))\r
- {\r
- if (!json.IsDefined(property.Name))\r
- continue;\r
- var v = json[property.Name];\r
- property.SetValue(this, property.PropertyType == typeof(int) ? (int)v : v);\r
- }\r
- NotifyConditions = new List<int>((int[])json.NotifyConditions);\r
- ResetHours = new List<int>((int[])json.ResetHours);\r
- Sounds.Volume = (int)json.SoundVolume;\r
- var idx = 0;\r
- foreach (var name in new[]\r
- {\r
- "Mission", "NDock", "KDock", "MaxShips", "MaxEquips",\r
- "DamagedShip", "Akashi20Min", "AkashiProgress", "AkashiComplete", "Condition"\r
- })\r
- {\r
- if (json.IsDefined(name + "SoundFile"))\r
- Sounds.Files[idx] = json[name + "SoundFile"];\r
- idx++;\r
- }\r
- Proxy.Auto = json.Proxy.Auto;\r
- Proxy.Listen = (int)json.Proxy.Listen;\r
- Proxy.UseUpstream = json.Proxy.UseUpstream;\r
- Proxy.UpstreamPort = (int)json.Proxy.UpstreamPort;\r
- var sl = json.ShipList;\r
- ShipList.Location = new Point((int)sl.Location.X, (int)sl.Location.Y);\r
- ShipList.Size = new Size((int)sl.Size.Width, (int)sl.Size.Height);\r
- ShipList.ShipType = sl.ShipType;\r
- var sg = (int[][])sl.ShipGroup;\r
- ShipList.ShipGroup = new List<List<int>>();\r
- foreach (var g in sg)\r
- ShipList.ShipGroup.Add(new List<int>(g));\r
- Log.On = json.Log.On;\r
- Log.OutputDir = json.Log.OutputDir;\r
- Log.MaterialLogInterval = (int)json.Log.MaterialLogInterval;\r
- }\r
}\r
}
\ No newline at end of file
}\r
catch (FileNotFoundException)\r
{\r
- ReadOldStatus();\r
}\r
finally\r
{\r
using (var file = File.CreateText(_statusFileName))\r
serializer.Serialize(file, this);\r
}\r
-\r
- public void ReadOldStatus()\r
- {\r
- var old = Path.Combine(_baseDir, "status.json");\r
- dynamic json;\r
- try\r
- {\r
- json = JsonParser.Parse(File.ReadAllText(old));\r
- }\r
- catch (FileNotFoundException)\r
- {\r
- return;\r
- }\r
- var ac = json.Achievement;\r
- Achievement = new Achievement\r
- {\r
- Start = (int)ac.Start,\r
- StartOfMonth = (int)ac.StartOfMonth,\r
- LastReset = DateTime.Parse(ac.LastReset),\r
- LastResetOfMonth = DateTime.Parse(ac.LastResetOfMonth),\r
- ResetHours = new List<int>((int[])ac.ResetHours),\r
- };\r
- var history = new List<MaterialCount>();\r
- foreach (var h in json.MatreialHistory)\r
- {\r
- history.Add(new MaterialCount\r
- {\r
- BegOfDay = (int)h.BegOfDay,\r
- BegOfWeek = (int)h.BegOfWeek,\r
- Now = (int)h.Now,\r
- LastSet = DateTime.Parse(h.LastSet)\r
- });\r
- }\r
- MaterialHistory = history;\r
- CondRegenTime = json.CondRegenTime;\r
- ExMapState = new ExMapInfo.ExMapState();\r
- var clear = new List<ExMapInfo.ClearStatus>();\r
- foreach (var cs in json.ExMapState.ClearStatusList)\r
- {\r
- clear.Add(new ExMapInfo.ClearStatus\r
- {\r
- Map = (int)cs.Map,\r
- Cleared = cs.Cleared,\r
- Rate = (int)cs.Rate,\r
- });\r
- }\r
- ExMapState.ClearStatusList = clear;\r
- Save();\r
- }\r
}\r
}
\ No newline at end of file