From 2f218b4a46bf1ce35abe8be71e4f1fc2614081e3 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Sun, 28 Sep 2014 10:27:57 +0900 Subject: [PATCH] =?utf8?q?=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7=E8=A8=AD?= =?utf8?q?=E5=AE=9A=E3=83=80=E3=82=A4=E3=82=A2=E3=83=AD=E3=82=B0=E3=82=92?= =?utf8?q?=E5=AE=9F=E8=A3=85=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer/Config.cs | 18 +++ KancolleSniffer/ConfigDialog.Designer.cs | 38 ++++-- KancolleSniffer/ConfigDialog.cs | 13 +- KancolleSniffer/KancolleSniffer.csproj | 9 ++ KancolleSniffer/MainForm.cs | 2 +- KancolleSniffer/ProxyDialog.Designer.cs | 224 +++++++++++++++++++++++++++++++ KancolleSniffer/ProxyDialog.cs | 87 ++++++++++++ KancolleSniffer/ProxyDialog.resx | 123 +++++++++++++++++ 8 files changed, 497 insertions(+), 17 deletions(-) create mode 100644 KancolleSniffer/ProxyDialog.Designer.cs create mode 100644 KancolleSniffer/ProxyDialog.cs create mode 100644 KancolleSniffer/ProxyDialog.resx diff --git a/KancolleSniffer/Config.cs b/KancolleSniffer/Config.cs index b99a852..ca8a0a8 100644 --- a/KancolleSniffer/Config.cs +++ b/KancolleSniffer/Config.cs @@ -23,6 +23,22 @@ using Codeplex.Data; namespace KancolleSniffer { + public class ProxyConfig + { + public bool Auto { get; set; } + public int Listen { get; set; } + public bool UseUpstream { get; set; } + public int UpstreamPort { get; set; } + + public ProxyConfig() + { + Auto = true; + Listen = 8080; + UseUpstream = false; + UpstreamPort = 8888; + } + } + public class Config { private readonly string _configFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "config.json"); @@ -42,6 +58,7 @@ namespace KancolleSniffer public string DamagedShipSoundFile { get; set; } public bool Logging { get; set; } public string LogFile { get; set; } + public ProxyConfig Proxy { get; set; } public Config() { @@ -59,6 +76,7 @@ namespace KancolleSniffer DamagedShipSoundFile = Path.Combine(dir, "taiha.mp3"); LogFile = Path.Combine(dir, "log.txt"); // ReSharper restore AssignNullToNotNullAttribute + Proxy = new ProxyConfig(); } public void Load() diff --git a/KancolleSniffer/ConfigDialog.Designer.cs b/KancolleSniffer/ConfigDialog.Designer.cs index d760076..3803662 100644 --- a/KancolleSniffer/ConfigDialog.Designer.cs +++ b/KancolleSniffer/ConfigDialog.Designer.cs @@ -77,12 +77,13 @@ namespace KancolleSniffer this.groupBoxShow = new System.Windows.Forms.GroupBox(); this.checkBoxTopMost = new System.Windows.Forms.CheckBox(); this.groupBoxAchievement = new System.Windows.Forms.GroupBox(); + this.buttonResetAchievement = new System.Windows.Forms.Button(); this.label8 = new System.Windows.Forms.Label(); this.checkBoxReset14 = new System.Windows.Forms.CheckBox(); this.checkBoxReset02 = new System.Windows.Forms.CheckBox(); this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.ProxyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DebugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.buttonResetAchievement = new System.Windows.Forms.Button(); this.groupBoxNotification.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMarginShips)).BeginInit(); this.groupBoxSound.SuspendLayout(); @@ -408,6 +409,16 @@ namespace KancolleSniffer this.groupBoxAchievement.TabStop = false; this.groupBoxAchievement.Text = "戦果"; // + // buttonResetAchievement + // + this.buttonResetAchievement.Location = new System.Drawing.Point(179, 14); + this.buttonResetAchievement.Name = "buttonResetAchievement"; + this.buttonResetAchievement.Size = new System.Drawing.Size(44, 22); + this.buttonResetAchievement.TabIndex = 4; + this.buttonResetAchievement.Text = "今すぐ"; + this.buttonResetAchievement.UseVisualStyleBackColor = true; + this.buttonResetAchievement.Click += new System.EventHandler(this.buttonResetAchievement_Click); + // // label8 // this.label8.AutoSize = true; @@ -440,27 +451,25 @@ namespace KancolleSniffer // contextMenuStrip // this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ProxyToolStripMenuItem, this.DebugToolStripMenuItem}); this.contextMenuStrip.Name = "contextMenuStrip"; - this.contextMenuStrip.Size = new System.Drawing.Size(149, 26); + this.contextMenuStrip.Size = new System.Drawing.Size(168, 70); + // + // ProxyToolStripMenuItem + // + this.ProxyToolStripMenuItem.Name = "ProxyToolStripMenuItem"; + this.ProxyToolStripMenuItem.Size = new System.Drawing.Size(165, 22); + this.ProxyToolStripMenuItem.Text = "プロキシ設定(&P)"; + this.ProxyToolStripMenuItem.Click += new System.EventHandler(this.ProxyToolStripMenuItem_Click); // // DebugToolStripMenuItem // this.DebugToolStripMenuItem.Name = "DebugToolStripMenuItem"; - this.DebugToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.DebugToolStripMenuItem.Text = "デバッグ設定"; + this.DebugToolStripMenuItem.Size = new System.Drawing.Size(167, 22); + this.DebugToolStripMenuItem.Text = "デバッグ設定(&D)"; this.DebugToolStripMenuItem.Click += new System.EventHandler(this.DebugToolStripMenuItem_Click); // - // buttonResetAchievement - // - this.buttonResetAchievement.Location = new System.Drawing.Point(179, 14); - this.buttonResetAchievement.Name = "buttonResetAchievement"; - this.buttonResetAchievement.Size = new System.Drawing.Size(44, 22); - this.buttonResetAchievement.TabIndex = 4; - this.buttonResetAchievement.Text = "今すぐ"; - this.buttonResetAchievement.UseVisualStyleBackColor = true; - this.buttonResetAchievement.Click += new System.EventHandler(this.buttonResetAchievement_Click); - // // ConfigDialog // this.AcceptButton = this.buttonOk; @@ -536,5 +545,6 @@ namespace KancolleSniffer private System.Windows.Forms.ContextMenuStrip contextMenuStrip; private System.Windows.Forms.ToolStripMenuItem DebugToolStripMenuItem; private System.Windows.Forms.Button buttonResetAchievement; + private System.Windows.Forms.ToolStripMenuItem ProxyToolStripMenuItem; } } \ No newline at end of file diff --git a/KancolleSniffer/ConfigDialog.cs b/KancolleSniffer/ConfigDialog.cs index a8ef443..20831d4 100644 --- a/KancolleSniffer/ConfigDialog.cs +++ b/KancolleSniffer/ConfigDialog.cs @@ -24,16 +24,16 @@ namespace KancolleSniffer { public partial class ConfigDialog : Form { - private readonly DebugDialog _debugDialog; private readonly Config _config; private readonly MainForm _main; + private DebugDialog _debugDialog; + private ProxyDialog _proxyDialog; public ConfigDialog(Config config, MainForm main) { InitializeComponent(); _config = config; _main = main; - _debugDialog = new DebugDialog(config, main); } private void ConfigDialog_Load(object sender, EventArgs e) @@ -117,6 +117,8 @@ namespace KancolleSniffer private void DebugToolStripMenuItem_Click(object sender, EventArgs e) { + if (_debugDialog == null) + _debugDialog = new DebugDialog(_config, _main); _debugDialog.ShowDialog(this); } @@ -124,5 +126,12 @@ namespace KancolleSniffer { _main.ResetAchievemnt(); } + + private void ProxyToolStripMenuItem_Click(object sender, EventArgs e) + { + if (_proxyDialog == null) + _proxyDialog = new ProxyDialog(_config.Proxy, _main); + _proxyDialog.ShowDialog(this); + } } } \ No newline at end of file diff --git a/KancolleSniffer/KancolleSniffer.csproj b/KancolleSniffer/KancolleSniffer.csproj index 0a93ce5..2e81d2d 100644 --- a/KancolleSniffer/KancolleSniffer.csproj +++ b/KancolleSniffer/KancolleSniffer.csproj @@ -84,6 +84,12 @@ + + Form + + + ProxyDialog.cs + @@ -111,6 +117,9 @@ Resources.resx True + + ProxyDialog.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index 3658b3c..6f82549 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -533,7 +533,7 @@ namespace KancolleSniffer if (num == 0) { parent.Size = new Size(width, 19); - var labels =_damagedShipList[0]; + var labels = _damagedShipList[0]; labels[fleet].Text = ""; SetShipName(labels[name], "なし"); labels[time].Text = ""; diff --git a/KancolleSniffer/ProxyDialog.Designer.cs b/KancolleSniffer/ProxyDialog.Designer.cs new file mode 100644 index 0000000..2a1562f --- /dev/null +++ b/KancolleSniffer/ProxyDialog.Designer.cs @@ -0,0 +1,224 @@ +namespace KancolleSniffer +{ + partial class ProxyDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.labelListen = new System.Windows.Forms.Label(); + this.textBoxListen = new System.Windows.Forms.TextBox(); + this.groupBoxAutoConfig = new System.Windows.Forms.GroupBox(); + this.radioButtonAutoConfigOff = new System.Windows.Forms.RadioButton(); + this.radioButtonAutoConfigOn = new System.Windows.Forms.RadioButton(); + this.groupBoxUpstream = new System.Windows.Forms.GroupBox(); + this.radioButtonUpstreamOff = new System.Windows.Forms.RadioButton(); + this.radioButtonUpstreamOn = new System.Windows.Forms.RadioButton(); + this.textBoxPort = new System.Windows.Forms.TextBox(); + this.labelPort = new System.Windows.Forms.Label(); + this.buttonOk = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.toolTipError = new System.Windows.Forms.ToolTip(this.components); + this.groupBoxAutoConfig.SuspendLayout(); + this.groupBoxUpstream.SuspendLayout(); + this.SuspendLayout(); + // + // labelListen + // + this.labelListen.AutoSize = true; + this.labelListen.Location = new System.Drawing.Point(114, 21); + this.labelListen.Name = "labelListen"; + this.labelListen.Size = new System.Drawing.Size(59, 12); + this.labelListen.TabIndex = 2; + this.labelListen.Text = "受信ポート:"; + // + // textBoxListen + // + this.textBoxListen.Location = new System.Drawing.Point(175, 18); + this.textBoxListen.Name = "textBoxListen"; + this.textBoxListen.Size = new System.Drawing.Size(36, 19); + this.textBoxListen.TabIndex = 3; + this.textBoxListen.Enter += new System.EventHandler(this.textBox_Enter); + // + // groupBoxAutoConfig + // + this.groupBoxAutoConfig.Controls.Add(this.radioButtonAutoConfigOff); + this.groupBoxAutoConfig.Controls.Add(this.radioButtonAutoConfigOn); + this.groupBoxAutoConfig.Controls.Add(this.textBoxListen); + this.groupBoxAutoConfig.Controls.Add(this.labelListen); + this.groupBoxAutoConfig.Location = new System.Drawing.Point(6, 6); + this.groupBoxAutoConfig.Name = "groupBoxAutoConfig"; + this.groupBoxAutoConfig.Size = new System.Drawing.Size(218, 48); + this.groupBoxAutoConfig.TabIndex = 0; + this.groupBoxAutoConfig.TabStop = false; + this.groupBoxAutoConfig.Text = "自動設定"; + // + // radioButtonAutoConfigOff + // + this.radioButtonAutoConfigOff.AutoSize = true; + this.radioButtonAutoConfigOff.Location = new System.Drawing.Point(59, 19); + this.radioButtonAutoConfigOff.Name = "radioButtonAutoConfigOff"; + this.radioButtonAutoConfigOff.Size = new System.Drawing.Size(47, 16); + this.radioButtonAutoConfigOff.TabIndex = 1; + this.radioButtonAutoConfigOff.TabStop = true; + this.radioButtonAutoConfigOff.Text = "無効"; + this.radioButtonAutoConfigOff.UseVisualStyleBackColor = true; + // + // radioButtonAutoConfigOn + // + this.radioButtonAutoConfigOn.AutoSize = true; + this.radioButtonAutoConfigOn.Location = new System.Drawing.Point(6, 19); + this.radioButtonAutoConfigOn.Name = "radioButtonAutoConfigOn"; + this.radioButtonAutoConfigOn.Size = new System.Drawing.Size(47, 16); + this.radioButtonAutoConfigOn.TabIndex = 0; + this.radioButtonAutoConfigOn.TabStop = true; + this.radioButtonAutoConfigOn.Text = "有効"; + this.radioButtonAutoConfigOn.UseVisualStyleBackColor = true; + this.radioButtonAutoConfigOn.CheckedChanged += new System.EventHandler(this.radioButtonAutoConfigOn_CheckedChanged); + // + // groupBoxUpstream + // + this.groupBoxUpstream.Controls.Add(this.radioButtonUpstreamOff); + this.groupBoxUpstream.Controls.Add(this.radioButtonUpstreamOn); + this.groupBoxUpstream.Controls.Add(this.textBoxPort); + this.groupBoxUpstream.Controls.Add(this.labelPort); + this.groupBoxUpstream.Location = new System.Drawing.Point(6, 60); + this.groupBoxUpstream.Name = "groupBoxUpstream"; + this.groupBoxUpstream.Size = new System.Drawing.Size(218, 48); + this.groupBoxUpstream.TabIndex = 1; + this.groupBoxUpstream.TabStop = false; + this.groupBoxUpstream.Text = "ツール連携"; + // + // radioButtonUpstreamOff + // + this.radioButtonUpstreamOff.AutoSize = true; + this.radioButtonUpstreamOff.Location = new System.Drawing.Point(59, 18); + this.radioButtonUpstreamOff.Name = "radioButtonUpstreamOff"; + this.radioButtonUpstreamOff.Size = new System.Drawing.Size(47, 16); + this.radioButtonUpstreamOff.TabIndex = 1; + this.radioButtonUpstreamOff.Text = "無効"; + this.radioButtonUpstreamOff.UseVisualStyleBackColor = true; + this.radioButtonUpstreamOff.CheckedChanged += new System.EventHandler(this.radioButtonUpstreamOff_CheckedChanged); + // + // radioButtonUpstreamOn + // + this.radioButtonUpstreamOn.AutoSize = true; + this.radioButtonUpstreamOn.Location = new System.Drawing.Point(6, 18); + this.radioButtonUpstreamOn.Name = "radioButtonUpstreamOn"; + this.radioButtonUpstreamOn.Size = new System.Drawing.Size(47, 16); + this.radioButtonUpstreamOn.TabIndex = 0; + this.radioButtonUpstreamOn.TabStop = true; + this.radioButtonUpstreamOn.Text = "有効"; + this.radioButtonUpstreamOn.UseVisualStyleBackColor = true; + // + // textBoxPort + // + this.textBoxPort.Location = new System.Drawing.Point(175, 17); + this.textBoxPort.Name = "textBoxPort"; + this.textBoxPort.Size = new System.Drawing.Size(36, 19); + this.textBoxPort.TabIndex = 3; + this.textBoxPort.Enter += new System.EventHandler(this.textBox_Enter); + // + // labelPort + // + this.labelPort.AutoSize = true; + this.labelPort.Location = new System.Drawing.Point(114, 20); + this.labelPort.Name = "labelPort"; + this.labelPort.Size = new System.Drawing.Size(59, 12); + this.labelPort.TabIndex = 2; + this.labelPort.Text = "送信ポート:"; + // + // buttonOk + // + this.buttonOk.Location = new System.Drawing.Point(68, 114); + this.buttonOk.Name = "buttonOk"; + this.buttonOk.Size = new System.Drawing.Size(75, 23); + this.buttonOk.TabIndex = 2; + this.buttonOk.Text = "OK"; + this.buttonOk.UseVisualStyleBackColor = true; + this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); + // + // buttonCancel + // + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Location = new System.Drawing.Point(149, 114); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "キャンセル"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // toolTipError + // + this.toolTipError.AutomaticDelay = 0; + this.toolTipError.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Error; + this.toolTipError.ToolTipTitle = "入力エラー"; + // + // ProxyDialog + // + this.AcceptButton = this.buttonOk; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.buttonCancel; + this.ClientSize = new System.Drawing.Size(230, 146); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOk); + this.Controls.Add(this.groupBoxUpstream); + this.Controls.Add(this.groupBoxAutoConfig); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ProxyDialog"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "プロキシ設定"; + this.Load += new System.EventHandler(this.ProxyDialog_Load); + this.groupBoxAutoConfig.ResumeLayout(false); + this.groupBoxAutoConfig.PerformLayout(); + this.groupBoxUpstream.ResumeLayout(false); + this.groupBoxUpstream.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label labelListen; + private System.Windows.Forms.TextBox textBoxListen; + private System.Windows.Forms.GroupBox groupBoxAutoConfig; + private System.Windows.Forms.RadioButton radioButtonAutoConfigOff; + private System.Windows.Forms.RadioButton radioButtonAutoConfigOn; + private System.Windows.Forms.GroupBox groupBoxUpstream; + private System.Windows.Forms.TextBox textBoxPort; + private System.Windows.Forms.Label labelPort; + private System.Windows.Forms.Button buttonOk; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.ToolTip toolTipError; + private System.Windows.Forms.RadioButton radioButtonUpstreamOff; + private System.Windows.Forms.RadioButton radioButtonUpstreamOn; + + + } +} \ No newline at end of file diff --git a/KancolleSniffer/ProxyDialog.cs b/KancolleSniffer/ProxyDialog.cs new file mode 100644 index 0000000..112ffa3 --- /dev/null +++ b/KancolleSniffer/ProxyDialog.cs @@ -0,0 +1,87 @@ +using System; +using System.Windows.Forms; + +namespace KancolleSniffer +{ + public partial class ProxyDialog : Form + { + private readonly ProxyConfig _config; + private MainForm _main; + + public ProxyDialog(ProxyConfig config, MainForm main) + { + InitializeComponent(); + _config = config; + _main = main; + } + + private void ProxyDialog_Load(object sender, EventArgs e) + { + (_config.Auto ? radioButtonAutoConfigOn : radioButtonAutoConfigOff).PerformClick(); + textBoxListen.Text = _config.Listen.ToString("D"); + (_config.UseUpstream ? radioButtonUpstreamOn : radioButtonUpstreamOff).PerformClick(); + textBoxPort.Text = _config.UpstreamPort.ToString("D"); + } + + private void radioButtonAutoConfigOn_CheckedChanged(object sender, EventArgs e) + { + var on = ((RadioButton)sender).Checked; + textBoxListen.Enabled = !on; + labelListen.Enabled = !on; + } + + private void radioButtonUpstreamOff_CheckedChanged(object sender, EventArgs e) + { + var off = ((RadioButton)sender).Checked; + textBoxPort.Enabled = !off; + } + + private void buttonOk_Click(object sender, EventArgs e) + { + var listen = -1; + var port = -1; + if (radioButtonAutoConfigOff.Checked && !ValidatePortNumber(textBoxListen, out listen)) + return; + if (radioButtonUpstreamOn.Checked && !ValidatePortNumber(textBoxPort, out port)) + return; + if (radioButtonAutoConfigOff.Checked && radioButtonUpstreamOn.Checked && listen == port) + { + ShowToolTip("受信と送信に同じポートは使えません。", textBoxPort); + return; + } + _config.Auto = radioButtonAutoConfigOn.Checked; + if (!_config.Auto) + _config.Listen = listen; + _config.UseUpstream = radioButtonUpstreamOn.Checked; + if (_config.UseUpstream) + _config.UpstreamPort = port; + DialogResult = DialogResult.OK; + } + + private bool ValidatePortNumber(TextBox textBox, out int result) + { + var s = textBox.Text; + if (!int.TryParse(s, out result)) + { + ShowToolTip("数字を入力してください。", textBox); + return false; + } + if (result <= 0) + { + ShowToolTip("0より大きい数字を入力してください。", textBox); + return false; + } + return true; + } + + private void ShowToolTip(string message, Control control) + { + toolTipError.Show(message, control, 0, control.Height, 3000); + } + + private void textBox_Enter(object sender, EventArgs e) + { + toolTipError.Hide((Control)sender); + } + } +} \ No newline at end of file diff --git a/KancolleSniffer/ProxyDialog.resx b/KancolleSniffer/ProxyDialog.resx new file mode 100644 index 0000000..e9a8c85 --- /dev/null +++ b/KancolleSniffer/ProxyDialog.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file -- 2.11.0