diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 3ad0e7bc..2dc33cf2 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -220,12 +220,13 @@ namespace Shadowsocks.Controller SaveConfig(_config); } - public void EnableProxy(int type, string proxy, int port) + public void EnableProxy(int type, string proxy, int port, int timeout) { _config.proxy.useProxy = true; _config.proxy.proxyType = type; _config.proxy.proxyServer = proxy; _config.proxy.proxyPort = port; + _config.proxy.proxyTimeout = timeout; SaveConfig(_config); } @@ -388,16 +389,6 @@ namespace Shadowsocks.Controller } } - public void SaveProxyConfig(ProxyConfig newConfig) - { - _config.proxy = newConfig; - Configuration.Save(_config); - if (ConfigChanged != null) - { - ConfigChanged(this, new EventArgs()); - } - } - public void SaveHotkeyConfig(HotkeyConfig newConfig) { _config.hotkey = newConfig; diff --git a/shadowsocks-csharp/View/ProxyForm.cs b/shadowsocks-csharp/View/ProxyForm.cs index 81e92aa5..c178900a 100644 --- a/shadowsocks-csharp/View/ProxyForm.cs +++ b/shadowsocks-csharp/View/ProxyForm.cs @@ -58,35 +58,25 @@ namespace Shadowsocks.View private void OKButton_Click(object sender, EventArgs e) { - var type = ProxyTypeComboBox.SelectedIndex; - var proxy = ProxyServerTextBox.Text; - var port = 0; - var timeout = 3; if (UseProxyCheckBox.Checked) { - try - { - port = int.Parse(ProxyPortTextBox.Text); - } - catch (FormatException) + int port; + int timeout; + if (!int.TryParse(ProxyPortTextBox.Text, out port)) { MessageBox.Show(I18N.GetString("Illegal port number format")); - ProxyPortTextBox.Clear(); return; } - try - { - timeout = int.Parse(ProxyTimeoutTextBox.Text); - } - catch (FormatException) + if (!int.TryParse(ProxyTimeoutTextBox.Text, out timeout)) { MessageBox.Show(I18N.GetString("Illegal timeout format")); - ProxyTimeoutTextBox.Clear(); return; } + var type = ProxyTypeComboBox.SelectedIndex; + var proxy = ProxyServerTextBox.Text; try { Configuration.CheckServer(proxy); @@ -99,20 +89,13 @@ namespace Shadowsocks.View return; } - controller.EnableProxy(type, proxy, port); + controller.EnableProxy(type, proxy, port, timeout); } else { controller.DisableProxy(); } - _modifiedConfiguration.useProxy = UseProxyCheckBox.Checked; - _modifiedConfiguration.proxyType = type; - _modifiedConfiguration.proxyServer = proxy; - _modifiedConfiguration.proxyPort = port; - _modifiedConfiguration.proxyTimeout = timeout; - controller.SaveProxyConfig(_modifiedConfiguration); - this.Close(); } @@ -142,9 +125,6 @@ namespace Shadowsocks.View } else { - ProxyServerTextBox.Clear(); - ProxyPortTextBox.Clear(); - ProxyTimeoutTextBox.Clear(); ProxyServerTextBox.Enabled = false; ProxyPortTextBox.Enabled = false; ProxyTimeoutTextBox.Enabled = false;