From ac4748d6bfb02e41b1fbbc30163295b622a3e0c5 Mon Sep 17 00:00:00 2001 From: wzxjohn Date: Sun, 9 Nov 2014 04:39:57 +0800 Subject: [PATCH] lint code --- shadowsocks-csharp/Controller/Local.cs | 28 +++---- .../Controller/ShadowsocksController.cs | 4 +- shadowsocks-csharp/Program.cs | 1 - .../Properties/Resources.Designer.cs | 12 +-- .../View/ConfigForm.Designer.cs | 1 + shadowsocks-csharp/View/ConfigForm.cs | 73 ++++++++++--------- 6 files changed, 60 insertions(+), 59 deletions(-) diff --git a/shadowsocks-csharp/Controller/Local.cs b/shadowsocks-csharp/Controller/Local.cs index 924cfbad..8eb2384b 100755 --- a/shadowsocks-csharp/Controller/Local.cs +++ b/shadowsocks-csharp/Controller/Local.cs @@ -224,7 +224,7 @@ namespace Shadowsocks.Controller // reject socks 4 response = new byte[]{ 0, 91 }; } - connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(handshakeSendCallback), null); + connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(HandshakeSendCallback), null); } else { @@ -238,7 +238,7 @@ namespace Shadowsocks.Controller } } - private void handshakeSendCallback(IAsyncResult ar) + private void HandshakeSendCallback(IAsyncResult ar) { try { @@ -270,7 +270,7 @@ namespace Shadowsocks.Controller if (bytesRead > 0) { byte[] response = { 5, 0, 0, 1, 0, 0, 0, 0, 0, 0 }; - connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(startPipe), null); + connection.BeginSend(response, 0, response.Length, 0, new AsyncCallback(StartPipe), null); } else { @@ -285,15 +285,15 @@ namespace Shadowsocks.Controller } - private void startPipe(IAsyncResult ar) + private void StartPipe(IAsyncResult ar) { try { connection.EndReceive(ar); remote.BeginReceive(remoteRecvBuffer, 0, RecvSize, 0, - new AsyncCallback(pipeRemoteReceiveCallback), null); + new AsyncCallback(PipeRemoteReceiveCallback), null); connection.BeginReceive(connetionRecvBuffer, 0, RecvSize, 0, - new AsyncCallback(pipeConnectionReceiveCallback), null); + new AsyncCallback(PipeConnectionReceiveCallback), null); } catch (Exception e) { @@ -302,7 +302,7 @@ namespace Shadowsocks.Controller } } - private void pipeRemoteReceiveCallback(IAsyncResult ar) + private void PipeRemoteReceiveCallback(IAsyncResult ar) { try @@ -313,7 +313,7 @@ namespace Shadowsocks.Controller { int bytesToSend; encryptor.Decrypt(remoteRecvBuffer, bytesRead, remoteSendBuffer, out bytesToSend); - connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(pipeConnectionSendCallback), null); + connection.BeginSend(remoteSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeConnectionSendCallback), null); } else { @@ -328,7 +328,7 @@ namespace Shadowsocks.Controller } } - private void pipeConnectionReceiveCallback(IAsyncResult ar) + private void PipeConnectionReceiveCallback(IAsyncResult ar) { try @@ -339,7 +339,7 @@ namespace Shadowsocks.Controller { int bytesToSend; encryptor.Encrypt(connetionRecvBuffer, bytesRead, connetionSendBuffer, out bytesToSend); - remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(pipeRemoteSendCallback), null); + remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null); } else { @@ -353,13 +353,13 @@ namespace Shadowsocks.Controller } } - private void pipeRemoteSendCallback(IAsyncResult ar) + private void PipeRemoteSendCallback(IAsyncResult ar) { try { remote.EndSend(ar); connection.BeginReceive(this.connetionRecvBuffer, 0, RecvSize, 0, - new AsyncCallback(pipeConnectionReceiveCallback), null); + new AsyncCallback(PipeConnectionReceiveCallback), null); } catch (Exception e) { @@ -368,13 +368,13 @@ namespace Shadowsocks.Controller } } - private void pipeConnectionSendCallback(IAsyncResult ar) + private void PipeConnectionSendCallback(IAsyncResult ar) { try { connection.EndSend(ar); remote.BeginReceive(this.remoteRecvBuffer, 0, RecvSize, 0, - new AsyncCallback(pipeRemoteReceiveCallback), null); + new AsyncCallback(PipeRemoteReceiveCallback), null); } catch (Exception e) { diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index e6e80d05..b28e2105 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -1,4 +1,5 @@ -using Shadowsocks.Model; +using System.IO; +using Shadowsocks.Model; using System; using System.Collections.Generic; using System.Text; @@ -172,6 +173,5 @@ namespace Shadowsocks.Controller { UpdateSystemProxy(); } - } } diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index a42a97ae..c90f089b 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -54,7 +54,6 @@ namespace Shadowsocks // TODO run without a main form to save RAM Application.Run(new ConfigForm(controller)); - } } } diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index d292578d..45ab16d9 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -71,12 +71,12 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__" - /// - ///socksParentProxy = "127.0.0.1:__SOCKS_PORT__" - ///socksProxyType = socks5 - ///diskCacheRoot = "" - ///localDocumentRoot = "" + /// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__" + /// + ///socksParentProxy = "127.0.0.1:__SOCKS_PORT__" + ///socksProxyType = socks5 + ///diskCacheRoot = "" + ///localDocumentRoot = "" ///. /// internal static string polipo_config { diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index cf874286..c1187c04 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -434,6 +434,7 @@ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; + this.MinimizeBox = false; this.Name = "ConfigForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Edit Servers"; diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 8bd980b8..e4cfda2b 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -16,9 +16,9 @@ namespace Shadowsocks.View private UpdateChecker updateChecker; // this is a copy of configuration that we are working on - private Configuration modifiedConfiguration; - private int oldSelectedIndex = -1; - private bool isFirstRun; + private Configuration _modifiedConfiguration; + private int _oldSelectedIndex = -1; + private bool _isFirstRun; public ConfigForm(ShadowsocksController controller) { @@ -66,7 +66,7 @@ namespace Shadowsocks.View notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; notifyIcon1.BalloonTipClicked += notifyIcon1_BalloonTipClicked; notifyIcon1.ShowBalloonTip(5000); - isFirstRun = false; + _isFirstRun = false; } void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) @@ -86,7 +86,7 @@ namespace Shadowsocks.View { try { - if (oldSelectedIndex == -1 || oldSelectedIndex >= modifiedConfiguration.configs.Count) + if (_oldSelectedIndex == -1 || _oldSelectedIndex >= _modifiedConfiguration.configs.Count) { return true; } @@ -100,7 +100,8 @@ namespace Shadowsocks.View remarks = RemarksTextBox.Text }; Configuration.CheckServer(server); - modifiedConfiguration.configs[oldSelectedIndex] = server; + _modifiedConfiguration.configs[_oldSelectedIndex] = server; + return true; } catch (FormatException) @@ -116,15 +117,15 @@ namespace Shadowsocks.View private void LoadSelectedServer() { - if (ServersListBox.SelectedIndex >= 0 && ServersListBox.SelectedIndex < modifiedConfiguration.configs.Count) + if (ServersListBox.SelectedIndex >= 0 && ServersListBox.SelectedIndex < _modifiedConfiguration.configs.Count) { - Server server = modifiedConfiguration.configs[ServersListBox.SelectedIndex]; + Server server = _modifiedConfiguration.configs[ServersListBox.SelectedIndex]; IPTextBox.Text = server.server; ServerPortTextBox.Text = server.server_port.ToString(); PasswordTextBox.Text = server.password; ProxyPortTextBox.Text = server.local_port.ToString(); - EncryptionSelect.Text = server.method == null ? "aes-256-cfb" : server.method; + EncryptionSelect.Text = server.method ?? "aes-256-cfb"; RemarksTextBox.Text = server.remarks; ServerGroupBox.Visible = true; //IPTextBox.Focus(); @@ -138,7 +139,7 @@ namespace Shadowsocks.View private void LoadConfiguration(Configuration configuration) { ServersListBox.Items.Clear(); - foreach (Server server in modifiedConfiguration.configs) + foreach (Server server in _modifiedConfiguration.configs) { ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : string.IsNullOrEmpty(server.remarks)? server.server + ":" + server.server_port : server.server + ":" + server.server_port + " (" + server.remarks + ")"); } @@ -146,15 +147,15 @@ namespace Shadowsocks.View private void LoadCurrentConfiguration() { - modifiedConfiguration = controller.GetConfiguration(); - LoadConfiguration(modifiedConfiguration); - oldSelectedIndex = modifiedConfiguration.index; - ServersListBox.SelectedIndex = modifiedConfiguration.index; + _modifiedConfiguration = controller.GetConfiguration(); + LoadConfiguration(_modifiedConfiguration); + _oldSelectedIndex = _modifiedConfiguration.index; + ServersListBox.SelectedIndex = _modifiedConfiguration.index; LoadSelectedServer(); UpdateServersMenu(); - enableItem.Checked = modifiedConfiguration.enabled; - ShareOverLANItem.Checked = modifiedConfiguration.shareOverLan; + enableItem.Checked = _modifiedConfiguration.enabled; + ShareOverLANItem.Checked = _modifiedConfiguration.shareOverLan; } private void UpdateServersMenu() @@ -193,14 +194,14 @@ namespace Shadowsocks.View } else { - isFirstRun = true; + _isFirstRun = true; } updateChecker.CheckUpdate(); } private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e) { - if (oldSelectedIndex == ServersListBox.SelectedIndex) + if (_oldSelectedIndex == ServersListBox.SelectedIndex) { // we are moving back to oldSelectedIndex or doing a force move return; @@ -208,11 +209,11 @@ namespace Shadowsocks.View if (!SaveOldSelectedServer()) { // why this won't cause stack overflow? - ServersListBox.SelectedIndex = oldSelectedIndex; + ServersListBox.SelectedIndex = _oldSelectedIndex; return; } LoadSelectedServer(); - oldSelectedIndex = ServersListBox.SelectedIndex; + _oldSelectedIndex = ServersListBox.SelectedIndex; } private void AddButton_Click(object sender, EventArgs e) @@ -222,27 +223,27 @@ namespace Shadowsocks.View return; } Server server = Configuration.GetDefaultServer(); - modifiedConfiguration.configs.Add(server); - LoadConfiguration(modifiedConfiguration); - ServersListBox.SelectedIndex = modifiedConfiguration.configs.Count - 1; - oldSelectedIndex = ServersListBox.SelectedIndex; + _modifiedConfiguration.configs.Add(server); + LoadConfiguration(_modifiedConfiguration); + ServersListBox.SelectedIndex = _modifiedConfiguration.configs.Count - 1; + _oldSelectedIndex = ServersListBox.SelectedIndex; } private void DeleteButton_Click(object sender, EventArgs e) { - oldSelectedIndex = ServersListBox.SelectedIndex; - if (oldSelectedIndex >= 0 && oldSelectedIndex < modifiedConfiguration.configs.Count) + _oldSelectedIndex = ServersListBox.SelectedIndex; + if (_oldSelectedIndex >= 0 && _oldSelectedIndex < _modifiedConfiguration.configs.Count) { - modifiedConfiguration.configs.RemoveAt(oldSelectedIndex); + _modifiedConfiguration.configs.RemoveAt(_oldSelectedIndex); } - if (oldSelectedIndex >= modifiedConfiguration.configs.Count) + if (_oldSelectedIndex >= _modifiedConfiguration.configs.Count) { // can be -1 - oldSelectedIndex = modifiedConfiguration.configs.Count - 1; + _oldSelectedIndex = _modifiedConfiguration.configs.Count - 1; } - ServersListBox.SelectedIndex = oldSelectedIndex; - LoadConfiguration(modifiedConfiguration); - ServersListBox.SelectedIndex = oldSelectedIndex; + ServersListBox.SelectedIndex = _oldSelectedIndex; + LoadConfiguration(_modifiedConfiguration); + ServersListBox.SelectedIndex = _oldSelectedIndex; LoadSelectedServer(); } @@ -258,13 +259,13 @@ namespace Shadowsocks.View private void ShowFirstTimeBalloon() { - if (isFirstRun) + if (_isFirstRun) { notifyIcon1.BalloonTipTitle = "Shadowsocks is here"; notifyIcon1.BalloonTipText = "You can turn on/off Shadowsocks in the context menu"; notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; notifyIcon1.ShowBalloonTip(0); - isFirstRun = false; + _isFirstRun = false; } } @@ -274,12 +275,12 @@ namespace Shadowsocks.View { return; } - if (modifiedConfiguration.configs.Count == 0) + if (_modifiedConfiguration.configs.Count == 0) { MessageBox.Show("Please add at least one server"); return; } - controller.SaveServers(modifiedConfiguration.configs); + controller.SaveServers(_modifiedConfiguration.configs); this.Hide(); ShowFirstTimeBalloon(); }