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
17 using System.Drawing;
\r
19 using Codeplex.Data;
\r
21 namespace KancolleSniffer
\r
23 public class ProxyConfig
\r
25 public const int DefaultListenPort = 8080;
\r
26 public const string AutoConfigUrl = "https://kancollesniffer.osdn.jp/proxy.pac";
\r
27 public const string AutoConfigUrlWithPort = "https://kancollesniffer.osdn.jp/proxy.php?port=";
\r
28 public bool Auto { get; set; }
\r
29 public int Listen { get; set; }
\r
30 public bool UseUpstream { get; set; }
\r
31 public int UpstreamPort { get; set; }
\r
33 public ProxyConfig()
\r
36 Listen = DefaultListenPort;
\r
37 UseUpstream = false;
\r
38 UpstreamPort = 8888;
\r
42 public class ShipListConfig
\r
44 public Point Location { get; set; }
\r
45 public Size Size { get; set; }
\r
46 public bool ShipType { get; set; }
\r
47 public List<int>[] ShipGroup { get; set; }
\r
49 public ShipListConfig()
\r
51 Location = new Point(int.MinValue, int.MinValue);
\r
52 ShipGroup = new List<int>[ShipListForm.GroupCount];
\r
53 for (var i = 0; i < ShipGroup.Length; i++)
\r
54 ShipGroup[i] = new List<int>();
\r
58 public class LogConfig
\r
60 public bool On { get; set; }
\r
61 public string OutputDir { get; set; }
\r
62 public int MaterialLogInterval { get; set; }
\r
63 public bool ServerOn { get; set; }
\r
64 public int Listen { get; set; }
\r
70 MaterialLogInterval = 10;
\r
76 public class KancolleDbConfig
\r
78 public bool On { get; set; }
\r
79 public string Token { get; set; } = "";
\r
84 private readonly string _baseDir = AppDomain.CurrentDomain.BaseDirectory;
\r
85 private readonly string _configFileName;
\r
87 public Point Location { get; set; }
\r
88 public bool TopMost { get; set; }
\r
89 public bool HideOnMinimized { get; set; }
\r
90 public bool FlashWindow { get; set; }
\r
91 public bool ShowBaloonTip { get; set; }
\r
92 public bool PlaySound { get; set; }
\r
93 public int MarginShips { get; set; }
\r
94 public int MarginEquips { get; set; }
\r
95 public List<int> NotifyConditions { get; set; }
\r
96 public List<int> ResetHours { get; set; }
\r
97 public bool AlwaysShowResultRank { get; set; }
\r
98 public bool UsePresetAkashi { get; set; }
\r
99 public int SoundVolume { get; set; }
\r
100 public string MissionSoundFile { get; set; }
\r
101 public string NDockSoundFile { get; set; }
\r
102 public string KDockSoundFile { get; set; }
\r
103 public string MaxShipsSoundFile { get; set; }
\r
104 public string MaxEquipsSoundFile { get; set; }
\r
105 public string DamagedShipSoundFile { get; set; }
\r
106 public string Akashi20MinSoundFile { get; set; }
\r
107 public string AkashiProgressSoundFile { get; set; }
\r
108 public string AkashiCompleteSoundFile { get; set; }
\r
109 public string ConditionSoundFile { get; set; }
\r
110 public bool DebugLogging { get; set; }
\r
111 public string DebugLogFile { get; set; }
\r
112 public ProxyConfig Proxy { get; set; }
\r
113 public ShipListConfig ShipList { get; set; }
\r
114 public LogConfig Log { get; set; }
\r
115 public KancolleDbConfig KancolleDb { get; set; }
\r
119 _configFileName = Path.Combine(_baseDir, "config.json");
\r
120 Location = new Point(int.MinValue, int.MinValue);
\r
121 FlashWindow = ShowBaloonTip = PlaySound = true;
\r
124 NotifyConditions = new List<int>(new[] {40, 49});
\r
125 ResetHours = new List<int>(new[] {2});
\r
126 AlwaysShowResultRank = false;
\r
128 MissionSoundFile = "ensei.mp3";
\r
129 NDockSoundFile = "nyuukyo.mp3";
\r
130 KDockSoundFile = "kenzou.mp3";
\r
131 MaxShipsSoundFile = "kanmusu.mp3";
\r
132 MaxEquipsSoundFile = "soubi.mp3";
\r
133 DamagedShipSoundFile = "taiha.mp3";
\r
134 Akashi20MinSoundFile = "20min.mp3";
\r
135 AkashiProgressSoundFile = "syuuri.mp3";
\r
136 AkashiCompleteSoundFile = "syuuri2.mp3";
\r
137 ConditionSoundFile = "hirou.mp3";
\r
138 DebugLogFile = "log.txt";
\r
139 Proxy = new ProxyConfig();
\r
140 ShipList = new ShipListConfig();
\r
141 Log = new LogConfig();
\r
142 KancolleDb = new KancolleDbConfig();
\r
143 ConvertPath(PrependBaseDir);
\r
150 var config = (Config)DynamicJson.Parse(File.ReadAllText(_configFileName));
\r
151 foreach (var property in GetType().GetProperties())
\r
152 property.SetValue(this, property.GetValue(config, null), null);
\r
153 ConvertPath(PrependBaseDir);
\r
155 catch (FileNotFoundException)
\r
162 ConvertPath(StripBaseDir);
\r
163 File.WriteAllText(_configFileName, DynamicJson.Serialize(this));
\r
166 private void ConvertPath(Func<string, string> func)
\r
168 foreach (var property in GetType().GetProperties())
\r
170 if (!property.Name.EndsWith("File"))
\r
172 property.SetValue(this, func((string)property.GetValue(this)));
\r
174 Log.OutputDir = func(Log.OutputDir);
\r
177 private string StripBaseDir(string path)
\r
179 if (!path.StartsWith(_baseDir))
\r
181 path = path.Substring(_baseDir.Length);
\r
182 return path.StartsWith(Path.DirectorySeparatorChar.ToString()) ? path.Substring(1) : path;
\r
185 private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(_baseDir, path);
\r