diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index afeed4d7..9d743869 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -104,6 +104,7 @@ Reg All=注册全部热键 Shadowsocks Error: {0}=Shadowsocks 错误: {0} Port already in use=端口已被占用 Illegal port number format=非法端口格式 +Illegal timeout format=非法超时格式 Please add at least one server=请添加至少一个服务器 Server IP can not be blank=服务器 IP 不能为空 Password can not be blank=密码不能为空 diff --git a/shadowsocks-csharp/Data/zh_tw.txt b/shadowsocks-csharp/Data/zh_tw.txt index 4c32e7b3..ea62de87 100644 --- a/shadowsocks-csharp/Data/zh_tw.txt +++ b/shadowsocks-csharp/Data/zh_tw.txt @@ -104,6 +104,7 @@ Reg All=註冊全部捷徑鍵 Shadowsocks Error: {0}=Shadowsocks 錯誤: {0} Port already in use=連接埠號碼已被占用 Illegal port number format=非法連接埠號碼格式 +Illegal timeout format=非法超時格式 Please add at least one server=請新增至少一個伺服器 Server IP can not be blank=伺服器 IP 不能為空 Password can not be blank=密碼不能為空 diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 3e32cb4a..f3f7d591 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -79,16 +79,32 @@ namespace Shadowsocks.View { return true; } - Server server = new Server + Server server = new Server(); + server.server = IPTextBox.Text.Trim(); + try { - server = IPTextBox.Text.Trim(), - server_port = int.Parse(ServerPortTextBox.Text), - password = PasswordTextBox.Text, - method = EncryptionSelect.Text, - remarks = RemarksTextBox.Text, - timeout = int.Parse(TimeoutTextBox.Text), - auth = OneTimeAuth.Checked - }; + server.server_port = int.Parse(ServerPortTextBox.Text); + } + catch (FormatException) + { + MessageBox.Show(I18N.GetString("Illegal port number format")); + ServerPortTextBox.Clear(); + return false; + } + server.password = PasswordTextBox.Text; + server.method = EncryptionSelect.Text; + server.remarks = RemarksTextBox.Text; + try + { + server.timeout = int.Parse(TimeoutTextBox.Text); + } + catch (FormatException) + { + MessageBox.Show(I18N.GetString("Illegal timeout format")); + TimeoutTextBox.Clear(); + return false; + } + server.auth = OneTimeAuth.Checked; int localPort = int.Parse(ProxyPortTextBox.Text); Configuration.CheckServer(server); Configuration.CheckLocalPort(localPort); @@ -97,10 +113,6 @@ namespace Shadowsocks.View return true; } - catch (FormatException) - { - MessageBox.Show(I18N.GetString("Illegal port number format")); - } catch (Exception ex) { MessageBox.Show(ex.Message); diff --git a/shadowsocks-csharp/View/ProxyForm.cs b/shadowsocks-csharp/View/ProxyForm.cs index 3b351f4b..81e92aa5 100644 --- a/shadowsocks-csharp/View/ProxyForm.cs +++ b/shadowsocks-csharp/View/ProxyForm.cs @@ -58,30 +58,48 @@ 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 { - var type = ProxyTypeComboBox.SelectedIndex; - var proxy = ProxyServerTextBox.Text; - var port = int.Parse(ProxyPortTextBox.Text); - var timeout = int.Parse(ProxyTimeoutTextBox.Text); - Configuration.CheckServer(proxy); - Configuration.CheckPort(port); - Configuration.CheckTimeout(timeout, ProxyConfig.MaxProxyTimeoutSec); - - controller.EnableProxy(type, proxy, port); + port = int.Parse(ProxyPortTextBox.Text); } catch (FormatException) { MessageBox.Show(I18N.GetString("Illegal port number format")); + ProxyPortTextBox.Clear(); return; } + + try + { + timeout = int.Parse(ProxyTimeoutTextBox.Text); + } + catch (FormatException) + { + MessageBox.Show(I18N.GetString("Illegal timeout format")); + ProxyTimeoutTextBox.Clear(); + return; + } + + try + { + Configuration.CheckServer(proxy); + Configuration.CheckPort(port); + Configuration.CheckTimeout(timeout, ProxyConfig.MaxProxyTimeoutSec); + } catch (Exception ex) { MessageBox.Show(ex.Message); return; } + + controller.EnableProxy(type, proxy, port); } else { @@ -89,14 +107,10 @@ namespace Shadowsocks.View } _modifiedConfiguration.useProxy = UseProxyCheckBox.Checked; - _modifiedConfiguration.proxyType = ProxyTypeComboBox.SelectedIndex; - _modifiedConfiguration.proxyServer = ProxyServerTextBox.Text; - var tmpProxyPort = 0; - int.TryParse(ProxyPortTextBox.Text, out tmpProxyPort); - _modifiedConfiguration.proxyPort = tmpProxyPort; - var tmpProxyTimeout = 0; - int.TryParse(ProxyTimeoutTextBox.Text, out tmpProxyTimeout); - _modifiedConfiguration.proxyTimeout = tmpProxyTimeout; + _modifiedConfiguration.proxyType = type; + _modifiedConfiguration.proxyServer = proxy; + _modifiedConfiguration.proxyPort = port; + _modifiedConfiguration.proxyTimeout = timeout; controller.SaveProxyConfig(_modifiedConfiguration); this.Close();