1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
19 using System.Collections.Generic;
\r
20 using System.Diagnostics;
\r
24 using System.Windows.Forms;
\r
26 namespace KancolleSniffer
\r
28 public partial class ConfigDialog : Form
\r
30 private readonly Config _config;
\r
31 private readonly MainForm _main;
\r
32 private readonly Dictionary<string, string> _soundSetting = new Dictionary<string, string>();
\r
33 private const string Home = "http://kancollesniffer.osdn.jp/";
\r
35 public ConfigDialog(Config config, MainForm main)
\r
37 InitializeComponent();
\r
40 listBoxSoundFile.Items.AddRange(new object[]
\r
42 "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",
\r
43 "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復"
\r
45 numericUpDownMaterialLogInterval.Maximum = 1440;
\r
48 private void ConfigDialog_Load(object sender, EventArgs e)
\r
50 var version = string.Join(".", Application.ProductVersion.Split('.').Take(2));
\r
51 labelVersion.Text = "バージョン" + version;
\r
52 SetLatestVersion(version);
\r
54 checkBoxTopMost.Checked = _config.TopMost;
\r
55 checkBoxHideOnMinimized.Checked = _config.HideOnMinimized;
\r
56 checkBoxFlash.Checked = _config.FlashWindow;
\r
57 checkBoxBalloon.Checked = _config.ShowBaloonTip;
\r
58 checkBoxSound.Checked = _config.PlaySound;
\r
59 numericUpDownMarginShips.Value = _config.MarginShips;
\r
60 numericUpDownMarginEquips.Value = _config.MarginEquips;
\r
61 checkBoxCond40.Checked = _config.NotifyConditions.Contains(40);
\r
62 checkBoxCond49.Checked = _config.NotifyConditions.Contains(49);
\r
63 checkBoxReset02.Checked = _config.ResetHours.Contains(2);
\r
64 checkBoxReset14.Checked = _config.ResetHours.Contains(14);
\r
65 radioButtonResultRankAlways.Checked = _config.AlwaysShowResultRank;
\r
66 radioButtonResultRankWhenClick.Checked = !_config.AlwaysShowResultRank;
\r
68 numericUpDownSoundVolume.Value = _config.SoundVolume;
\r
70 _soundSetting["遠征終了"] = _config.MissionSoundFile;
\r
71 _soundSetting["入渠終了"] = _config.NDockSoundFile;
\r
72 _soundSetting["建造完了"] = _config.KDockSoundFile;
\r
73 _soundSetting["艦娘数超過"] = _config.MaxShipsSoundFile;
\r
74 _soundSetting["装備数超過"] = _config.MaxEquipsSoundFile;
\r
75 _soundSetting["大破警告"] = _config.DamagedShipSoundFile;
\r
76 _soundSetting["泊地修理20分経過"] = _config.Akashi20MinSoundFile;
\r
77 _soundSetting["泊地修理進行"] = _config.AkashiProgressSoundFile;
\r
78 _soundSetting["泊地修理完了"] = _config.AkashiCompleteSoundFile;
\r
79 _soundSetting["疲労回復"] = _config.ConditionSoundFile;
\r
81 listBoxSoundFile.SelectedIndex = -1;
\r
82 listBoxSoundFile.SelectedIndex = 0;
\r
84 LoadProxySettings();
\r
86 LoadDebugSettings();
\r
89 private void LoadProxySettings()
\r
91 // 見えていないTabPage上でPerformClickは使えない。
\r
92 radioButtonAutoConfigOn.Checked = _config.Proxy.Auto;
\r
93 radioButtonAutoConfigOff.Checked = !_config.Proxy.Auto;
\r
94 textBoxListen.Text = _config.Proxy.Listen.ToString("D");
\r
95 radioButtonUpstreamOn.Checked = _config.Proxy.UseUpstream;
\r
96 radioButtonUpstreamOff.Checked = !_config.Proxy.UseUpstream;
\r
97 textBoxPort.Text = _config.Proxy.UpstreamPort.ToString("D");
\r
100 private void LoadLogSettings()
\r
102 checkBoxOutput.Checked = _config.Log.On;
\r
103 textBoxOutput.Text = _config.Log.OutputDir;
\r
104 textBoxOutput.Select(textBoxOutput.Text.Length, 0);
\r
105 folderBrowserDialogOutputDir.SelectedPath = _config.Log.OutputDir;
\r
106 numericUpDownMaterialLogInterval.Value = _config.Log.MaterialLogInterval;
\r
107 radioButtonServerOn.Checked = _config.Log.ServerOn;
\r
108 radioButtonServerOff.Checked = !_config.Log.ServerOn;
\r
109 textBoxServer.Text = _config.Log.Listen.ToString("D");
\r
112 private void LoadDebugSettings()
\r
114 checkBoxDebugLog.Checked = _config.DebugLogging;
\r
115 textBoxDebugLog.Text = _config.DebugLogFile;
\r
118 private async void SetLatestVersion(string version)
\r
122 var req = WebRequest.Create(Home + "version");
\r
123 var response = await req.GetResponseAsync();
\r
124 var stream = response.GetResponseStream();
\r
125 if (stream == null)
\r
127 using (var reader = new StreamReader(stream))
\r
129 var str = await reader.ReadLineAsync();
\r
130 Invoke(new Action(() => { labelLatest.Text = version == str ? "最新です" : "最新は" + str + "です"; }));
\r
133 catch (WebException)
\r
138 private void buttonOk_Click(object sender, EventArgs e)
\r
140 int listen, outbound, server;
\r
141 if (!ValidatePorts(out listen, out outbound, out server))
\r
143 DialogResult = DialogResult.OK;
\r
144 if (!ApplyProxySettings(listen, outbound))
\r
145 DialogResult = DialogResult.None;
\r
146 if (!ApplyLogSettings(server))
\r
147 DialogResult = DialogResult.None;
\r
148 ApplyDebugSettings();
\r
150 _config.TopMost = checkBoxTopMost.Checked;
\r
151 _config.HideOnMinimized = checkBoxHideOnMinimized.Checked;
\r
152 _config.FlashWindow = checkBoxFlash.Checked;
\r
153 _config.ShowBaloonTip = checkBoxBalloon.Checked;
\r
154 _config.PlaySound = checkBoxSound.Checked;
\r
155 _config.MarginShips = (int)numericUpDownMarginShips.Value;
\r
156 _config.MarginEquips = (int)numericUpDownMarginEquips.Value;
\r
158 _config.NotifyConditions.Clear();
\r
159 if (checkBoxCond40.Checked)
\r
160 _config.NotifyConditions.Add(40);
\r
161 if (checkBoxCond49.Checked)
\r
162 _config.NotifyConditions.Add(49);
\r
164 _config.ResetHours.Clear();
\r
165 if (checkBoxReset02.Checked)
\r
166 _config.ResetHours.Add(2);
\r
167 if (checkBoxReset14.Checked)
\r
168 _config.ResetHours.Add(14);
\r
170 _config.AlwaysShowResultRank = radioButtonResultRankAlways.Checked;
\r
171 _main.UpdateFighterPower();
\r
173 _config.SoundVolume = (int)numericUpDownSoundVolume.Value;
\r
175 _config.MissionSoundFile = _soundSetting["遠征終了"];
\r
176 _config.NDockSoundFile = _soundSetting["入渠終了"];
\r
177 _config.KDockSoundFile = _soundSetting["建造完了"];
\r
178 _config.MaxShipsSoundFile = _soundSetting["艦娘数超過"];
\r
179 _config.MaxEquipsSoundFile = _soundSetting["装備数超過"];
\r
180 _config.DamagedShipSoundFile = _soundSetting["大破警告"];
\r
181 _config.Akashi20MinSoundFile = _soundSetting["泊地修理20分経過"];
\r
182 _config.AkashiProgressSoundFile = _soundSetting["泊地修理進行"];
\r
183 _config.AkashiCompleteSoundFile = _soundSetting["泊地修理完了"];
\r
184 _config.ConditionSoundFile = _soundSetting["疲労回復"];
\r
187 private bool ValidatePorts(out int listen, out int outbound, out int server)
\r
191 if (!ValidatePortNumber(textBoxListen, out listen))
\r
193 if (radioButtonUpstreamOn.Checked && !ValidatePortNumber(textBoxPort, out outbound))
\r
195 if (radioButtonServerOn.Checked && !ValidatePortNumber(textBoxServer, out server))
\r
197 if (radioButtonUpstreamOn.Checked && listen == outbound)
\r
199 ShowToolTip("受信と送信に同じポートは使えません。", textBoxPort);
\r
202 if (radioButtonServerOn.Checked && server == listen)
\r
204 ShowToolTip("プロキシの受信ポートと同じポートは使えません。", textBoxServer);
\r
210 private bool ApplyProxySettings(int listen, int port)
\r
212 _config.Proxy.Auto = radioButtonAutoConfigOn.Checked;
\r
213 _config.Proxy.Listen = listen;
\r
214 _config.Proxy.UseUpstream = radioButtonUpstreamOn.Checked;
\r
215 if (_config.Proxy.UseUpstream)
\r
216 _config.Proxy.UpstreamPort = port;
\r
217 if (!_main.ApplyProxySetting())
\r
219 textBoxListen.Text = _config.Proxy.Listen.ToString();
\r
223 private bool ApplyLogSettings(int server)
\r
225 _config.Log.On = checkBoxOutput.Checked;
\r
226 _config.Log.MaterialLogInterval = (int)numericUpDownMaterialLogInterval.Value;
\r
227 _config.Log.OutputDir = textBoxOutput.Text;
\r
228 _config.Log.ServerOn = radioButtonServerOn.Checked;
\r
229 _config.Log.Listen = server;
\r
230 if (!_main.ApplyLogSetting())
\r
232 textBoxServer.Text = _config.Log.Listen.ToString();
\r
236 private void ApplyDebugSettings()
\r
238 _config.DebugLogging = checkBoxDebugLog.Checked;
\r
239 _config.DebugLogFile = textBoxDebugLog.Text;
\r
240 _main.ApplyDebugLogSetting();
\r
243 private void textBoxSoundFile_TextChanged(object sender, EventArgs e)
\r
245 _soundSetting[(string)listBoxSoundFile.SelectedItem] = textBoxSoundFile.Text;
\r
248 private void listBoxSoundFile_SelectedIndexChanged(object sender, EventArgs e)
\r
250 if (listBoxSoundFile.SelectedItem == null)
\r
252 textBoxSoundFile.Text = _soundSetting[(string)listBoxSoundFile.SelectedItem];
\r
253 textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);
\r
256 private void buttonOpenFile_Click(object sender, EventArgs e)
\r
258 openSoundFileDialog.FileName = textBoxSoundFile.Text;
\r
259 openSoundFileDialog.InitialDirectory = Path.GetDirectoryName(textBoxSoundFile.Text) ?? "";
\r
260 if (openSoundFileDialog.ShowDialog() != DialogResult.OK)
\r
262 textBoxSoundFile.Text = openSoundFileDialog.FileName;
\r
263 textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);
\r
266 private void buttonPlay_Click(object sender, EventArgs e)
\r
268 _main.PlaySound(_soundSetting[(string)listBoxSoundFile.SelectedItem], (int)numericUpDownSoundVolume.Value);
\r
271 private void buttonResetAchievement_Click(object sender, EventArgs e)
\r
273 _main.ResetAchievemnt();
\r
276 private void linkLabelProductName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
278 linkLabelProductName.LinkVisited = true;
\r
279 Process.Start(Home);
\r
282 private void radioButtonUpstreamOff_CheckedChanged(object sender, EventArgs e)
\r
284 var off = ((RadioButton)sender).Checked;
\r
285 textBoxPort.Enabled = !off;
\r
288 private void radioButtonServerOff_CheckedChanged(object sender, EventArgs e)
\r
290 var off = ((RadioButton)sender).Checked;
\r
291 textBoxServer.Enabled = !off;
\r
294 private void buttonOutputDir_Click(object sender, EventArgs e)
\r
296 if (folderBrowserDialogOutputDir.ShowDialog(this) == DialogResult.OK)
\r
297 textBoxOutput.Text = folderBrowserDialogOutputDir.SelectedPath;
\r
298 textBoxOutput.Select(textBoxOutput.Text.Length, 0);
\r
301 private bool ValidatePortNumber(TextBox textBox, out int result)
\r
303 var s = textBox.Text;
\r
304 if (!int.TryParse(s, out result))
\r
306 ShowToolTip("数字を入力してください。", textBox);
\r
311 ShowToolTip("0より大きい数字を入力してください。", textBox);
\r
317 private void ShowToolTip(string message, Control control)
\r
319 tabControl.SelectedTab = (TabPage)control.Parent.Parent;
\r
320 toolTipError.Show(message, control, 0, control.Height, 3000);
\r
323 private void textBox_Enter(object sender, EventArgs e)
\r
325 toolTipError.Hide((Control)sender);
\r
328 private void buttonDebugLogOpenFile_Click(object sender, EventArgs e)
\r
330 openDebugLogDialog.FileName = textBoxDebugLog.Text;
\r
331 openDebugLogDialog.InitialDirectory = Path.GetDirectoryName(textBoxDebugLog.Text);
\r
332 if (openDebugLogDialog.ShowDialog(this) == DialogResult.OK)
\r
333 textBoxDebugLog.Text = openDebugLogDialog.FileName;
\r
334 textBoxDebugLog.Select(textBoxDebugLog.Text.Length, 0);
\r
337 private void buttonPlayDebugLog_Click(object sender, EventArgs e)
\r
339 _main.SetPlayLog(textBoxDebugLog.Text);
\r
340 DialogResult = DialogResult.Cancel;
\r