private Server GetServerDetailsFromUI() { Server server = new Server(); if (Uri.CheckHostName(server.server = IPTextBox.Text.Trim()) == UriHostNameType.Unknown) { MessageBox.Show(I18N.GetString("Invalid server address")); IPTextBox.Focus(); return(null); } if (!int.TryParse(ServerPortTextBox.Text, out server.server_port)) { MessageBox.Show(I18N.GetString("Illegal port number format")); ServerPortTextBox.Focus(); return(null); } server.password = PasswordTextBox.Text; server.method = EncryptionSelect.Text; server.plugin = PluginTextBox.Text; server.plugin_opts = PluginOptionsTextBox.Text; server.plugin_args = PluginArgumentsTextBox.Text; server.remarks = RemarksTextBox.Text; if (!int.TryParse(TimeoutTextBox.Text, out server.timeout)) { MessageBox.Show(I18N.GetString("Illegal timeout format")); TimeoutTextBox.Focus(); return(null); } return(server); }
private bool SaveOldSelectedServer() { try { if (_lastSelectedIndex == -1 || _lastSelectedIndex >= _modifiedConfiguration.configs.Count) { return(true); } Server server = new Server(); if (Uri.CheckHostName(server.server = IPTextBox.Text.Trim()) == UriHostNameType.Unknown) { MessageBox.Show(I18N.GetString("Invalid server address")); IPTextBox.Focus(); return(false); } if (!int.TryParse(ServerPortTextBox.Text, out server.server_port)) { MessageBox.Show(I18N.GetString("Illegal port number format")); ServerPortTextBox.Focus(); return(false); } server.password = PasswordTextBox.Text; server.method = EncryptionSelect.Text; server.use_kcp = UseKcpCheckBox.Checked; server.kcp_argument = KcpArgumentTextBox.Text; if (!int.TryParse(KcpRemotePortTextBox.Text, out server.kcp_remote_port)) { MessageBox.Show(I18N.GetString("Illegal kcp remote port number format")); ServerPortTextBox.Focus(); return(false); } server.remarks = RemarksTextBox.Text; if (!int.TryParse(TimeoutTextBox.Text, out server.timeout)) { MessageBox.Show(I18N.GetString("Illegal timeout format")); TimeoutTextBox.Focus(); return(false); } int localPort = int.Parse(ProxyPortTextBox.Text); Configuration.CheckServer(server); Configuration.CheckLocalPort(localPort); _modifiedConfiguration.configs[_lastSelectedIndex] = server; _modifiedConfiguration.localPort = localPort; return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(false); }
private bool?CheckServerPortTextBox(out int?addressPort, bool isSave, bool isCopy) { addressPort = null; if (!int.TryParse(ServerPortTextBox.Text, out int outaddressPort)) { if (!isSave && !isCopy && ServersListBox.Items.Count > 1 && I18N.GetString("New server").Equals(ServersListBox.Items[_lastSelectedIndex].ToString())) { DialogResult result = MessageBox.Show(I18N.GetString("Whether to discard unconfigured servers"), I18N.GetString("Operation failure"), MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { return(null); } } else if (isChange && !isSave && !isCopy) { var result = MessageBox.Show(I18N.GetString("Illegal port number format, Cannot automatically save or discard changes"), I18N.GetString("Auto save failed"), MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return(false); } else { addressPort = _modifiedConfiguration.configs[_lastSelectedIndex].server_port; return(true); } } else { MessageBox.Show(I18N.GetString("Illegal port number format"), I18N.GetString("Operation failure")); ServerPortTextBox.Focus(); } return(false); } else { addressPort = outaddressPort; } return(true); }