From 613bb71d85cbcface2ce384d6e30a3bcb0c89354 Mon Sep 17 00:00:00 2001 From: Sven Koch <39488412+SVNKoch@users.noreply.github.com> Date: Wed, 18 Oct 2023 03:01:46 +0200 Subject: [PATCH] remove duplicated code --- WireSockUI/Forms/frmMain.cs | 48 +++++++++---------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/WireSockUI/Forms/frmMain.cs b/WireSockUI/Forms/frmMain.cs index a807333..374225c 100644 --- a/WireSockUI/Forms/frmMain.cs +++ b/WireSockUI/Forms/frmMain.cs @@ -489,8 +489,7 @@ private void OnProfileClick(object sender, EventArgs e) if (e != EventArgs.Empty) { // Check if the current state is connected or connecting. - if ((_currentState == ConnectionState.Connected || _currentState == ConnectionState.Connecting) && - e != EventArgs.Empty) + if (_currentState == ConnectionState.Connected || _currentState == ConnectionState.Connecting) { var reconnect = false; @@ -505,50 +504,25 @@ private void OnProfileClick(object sender, EventArgs e) // Proceed with reconnecting if the reconnect flag is set. if (!reconnect) return; - // Set the tunnel mode based on the application settings. - _wiresock.TunnelMode = Settings.Default.UseAdapter - ? WireSockManager.Mode.VirtualAdapter - : WireSockManager.Mode.Transparent; - - // Get the selected profile. - var profile = lstProfiles.SelectedItems[0].Text; - - // Connect to the selected profile and update the state to connecting if successful. - if (_wiresock.Connect(profile)) - UpdateState(ConnectionState.Connecting); - } - else - { - // Set the tunnel mode based on the application settings. - _wiresock.TunnelMode = Settings.Default.UseAdapter - ? WireSockManager.Mode.VirtualAdapter - : WireSockManager.Mode.Transparent; - - // Get the selected profile. - var profile = lstProfiles.SelectedItems[0].Text; - - // Connect to the selected profile and update the state to connecting if successful. - if (_wiresock.Connect(profile)) - UpdateState(ConnectionState.Connecting); } } else { // Update the state to disconnected. UpdateState(ConnectionState.Disconnected); + } - // Set the tunnel mode based on the application settings. - _wiresock.TunnelMode = Settings.Default.UseAdapter - ? WireSockManager.Mode.VirtualAdapter - : WireSockManager.Mode.Transparent; + // Set the tunnel mode based on the application settings. + _wiresock.TunnelMode = Settings.Default.UseAdapter + ? WireSockManager.Mode.VirtualAdapter + : WireSockManager.Mode.Transparent; - // Get the selected profile. - var profile = lstProfiles.SelectedItems[0].Text; + // Get the selected profile. + var profile = lstProfiles.SelectedItems[0].Text; - // Connect to the selected profile and update the state to connecting if successful. - if (_wiresock.Connect(profile)) - UpdateState(ConnectionState.Connecting); - } + // Connect to the selected profile and update the state to connecting if successful. + if (_wiresock.Connect(profile)) + UpdateState(ConnectionState.Connecting); } private void OnWireSockLogMessage(WireSockManager.LogMessage logMessage)