private void Form1_Load(object sender, EventArgs e) { KcptunClientConfig config; config = KcptunClientConfig.LoadFromFile(KcptunClientConfig.DefaultFileName); if (config != null) { this.textboxProgram.Text = config.ExecutableFile; this.textboxServer.Text = config.ServerAddress; this.textboxRemotePort.Text = config.ServerPort; this.textboxLocalPort.Text = config.LocalPort; this.textboxKey.Text = config.Key; } this.toolStripProgressBar1.Visible = false; this.RefreshGuiTextStatus(); this.monitorTimer.Interval = 3 * 1000; this.monitorTimer.Start(); if (!File.Exists(this.textboxProgram.Text)) { this.PopupDownloadKcptunDialog(); } UpdateTextBoxCommandArguments(null, null); this.textboxServer.TextChanged += UpdateTextBoxCommandArguments; this.textboxRemotePort.TextChanged += UpdateTextBoxCommandArguments; this.textboxLocalPort.TextChanged += UpdateTextBoxCommandArguments; this.textboxKey.TextChanged += UpdateTextBoxCommandArguments; }
private KcptunClientConfig LoadConfiguration() { try { return(KcptunClientConfig.LoadFromFile(KcptunClientConfig.DefaultFileName)); } catch (IOException ex) { MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(null); }
private string GenerateKcptunCommandArguments(KcptunClientConfig config) { string arguments = ""; if (config == null) { if (this.textboxLocalPort.Text.Length > 0) { arguments += string.Format(" -l :{0}", this.textboxLocalPort.Text); } if (this.textboxServer.Text.Length > 0) { if (this.textboxRemotePort.Text.Length > 0) { arguments += string.Format(" -r {0}:{1}", this.textboxServer.Text, this.textboxRemotePort.Text); } else { arguments += string.Format(" -r {0}:0", this.textboxServer.Text); } } if (this.textboxKey.Text.Length > 0) { arguments += string.Format(" --key {0}", this.textboxKey.Text); } } else { arguments = string.Format("-l :{0} -r {1}:{2} --key {3}", config.LocalPort, config.ServerAddress, config.ServerPort, config.Key); } if (this.checkboxDebug.Checked && this.checkBoxDebugWriteFile.Checked) { arguments += string.Format(" --log kcptun.log"); } return(arguments.TrimStart()); }
private void StartKcptunClient() { if (!this.CheckLocalPort(false)) { return; } if (!File.Exists(this.textboxProgram.Text)) { MessageBox.Show("Invalid KCPTUN client file."); return; } KcptunClientConfig config = this.SaveConfiguration(); if (!this.IsKcptunClientRunning) { ProcessStartInfo start = new ProcessStartInfo(); start.FileName = this.textboxProgram.Text; start.UseShellExecute = true; start.CreateNoWindow = true; start.WindowStyle = ProcessWindowStyle.Hidden; start.WorkingDirectory = Path.GetDirectoryName(start.FileName); if (this.checkboxDebug.Checked && !this.checkBoxDebugWriteFile.Checked) { start.WindowStyle = ProcessWindowStyle.Normal; } start.Arguments = this.GenerateKcptunCommandArguments(config); try { using (Process proc = Process.Start(start)) { }; this.UpdateTextBoxCommandArguments(null, null); this.RefreshGuiTextStatus(); checkboxDebug.Enabled = false; } catch (Win32Exception ex) { MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private KcptunClientConfig SaveConfiguration() { KcptunClientConfig config = new KcptunClientConfig(); config.ExecutableFile = textboxProgram.Text; config.ServerAddress = textboxServer.Text; config.ServerPort = textboxRemotePort.Text; config.LocalPort = textboxLocalPort.Text; config.Key = textboxKey.Text; try { config.Save(KcptunClientConfig.DefaultFileName); } catch (IOException ex) { MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(config); }