diff --git a/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs b/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs index d7e9108c..a881f3c5 100644 --- a/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs +++ b/mRemoteNGTests/Tree/SelectedConnectionDeletionConfirmerTests.cs @@ -1,7 +1,7 @@ -using System.Windows.Forms; -using mRemoteNG.Connection; +using mRemoteNG.Connection; using mRemoteNG.Tree; using NUnit.Framework; +using System.Windows.Forms; namespace mRemoteNGTests.Tree @@ -30,12 +30,12 @@ namespace mRemoteNGTests.Tree Assert.That(deletionConfirmer.Confirm(_testConnectionInfo), Is.False); } - private DialogResult MockClickYes(string promptMessage, string title, MessageBoxButtons buttons, MessageBoxIcon icon) + private DialogResult MockClickYes(string promptMessage) { return DialogResult.Yes; } - private DialogResult MockClickNo(string promptMessage, string title, MessageBoxButtons buttons, MessageBoxIcon icon) + private DialogResult MockClickNo(string promptMessage) { return DialogResult.No; } diff --git a/mRemoteV1/Connection/ConnectionInitiator.cs b/mRemoteV1/Connection/ConnectionInitiator.cs index 713d6b67..86ae3243 100644 --- a/mRemoteV1/Connection/ConnectionInitiator.cs +++ b/mRemoteV1/Connection/ConnectionInitiator.cs @@ -63,7 +63,7 @@ namespace mRemoteNG.Connection StartPreConnectionExternalApp(connectionInfo); - if ((force & ConnectionInfo.Force.DoNotJump) != ConnectionInfo.Force.DoNotJump) + if (!force.HasFlag(ConnectionInfo.Force.DoNotJump)) { if (SwitchToOpenConnection(connectionInfo)) return; @@ -136,7 +136,7 @@ namespace mRemoteNG.Connection private static string SetConnectionPanel(ConnectionInfo connectionInfo, ConnectionInfo.Force force) { var connectionPanel = ""; - if (connectionInfo.Panel == "" || (force & ConnectionInfo.Force.OverridePanel) == ConnectionInfo.Force.OverridePanel | Settings.Default.AlwaysShowPanelSelectionDlg) + if (connectionInfo.Panel == "" || force.HasFlag(ConnectionInfo.Force.OverridePanel) || Settings.Default.AlwaysShowPanelSelectionDlg) { var frmPnl = new frmChoosePanel(); if (frmPnl.ShowDialog() == DialogResult.OK) diff --git a/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs b/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs index 3d277fe8..e28c2114 100644 --- a/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs +++ b/mRemoteV1/Connection/Protocol/ICA/IcaProtocol.cs @@ -1,7 +1,3 @@ -using System; -using System.Threading; -using System.Timers; -using System.Windows.Forms; using AxWFICALib; using mRemoteNG.App; using mRemoteNG.Connection.Protocol.RDP; @@ -9,11 +5,15 @@ using mRemoteNG.Messages; using mRemoteNG.Security.SymmetricEncryption; using mRemoteNG.Tools; using mRemoteNG.UI.Forms; +using System; +using System.Threading; +using System.Timers; +using System.Windows.Forms; namespace mRemoteNG.Connection.Protocol.ICA { - public class IcaProtocol : ProtocolBase + public class IcaProtocol : ProtocolBase { private AxICAClient _icaClient; private ConnectionInfo _info; @@ -112,7 +112,7 @@ namespace mRemoteNG.Connection.Protocol.ICA { try { - if (((int)Force & (int)ConnectionInfo.Force.NoCredentials) == (int)ConnectionInfo.Force.NoCredentials) + if (Force.HasFlag(ConnectionInfo.Force.NoCredentials)) { return; } @@ -179,7 +179,7 @@ namespace mRemoteNG.Connection.Protocol.ICA { try { - if ((Force & ConnectionInfo.Force.Fullscreen) == ConnectionInfo.Force.Fullscreen) + if (Force.HasFlag(ConnectionInfo.Force.Fullscreen)) { _icaClient.SetWindowSize(WFICALib.ICAWindowType.WindowTypeClient, Screen.FromControl(_frmMain).Bounds.Width, Screen.FromControl(_frmMain).Bounds.Height, 0); _icaClient.FullScreenWindow(); diff --git a/mRemoteV1/Connection/Protocol/PuttyBase.cs b/mRemoteV1/Connection/Protocol/PuttyBase.cs index 67f788d6..665d7517 100644 --- a/mRemoteV1/Connection/Protocol/PuttyBase.cs +++ b/mRemoteV1/Connection/Protocol/PuttyBase.cs @@ -1,20 +1,20 @@ -using System; -using System.Diagnostics; -using System.Drawing; -using System.Threading; -using System.Windows.Forms; using mRemoteNG.App; using mRemoteNG.Messages; using mRemoteNG.Security.SymmetricEncryption; using mRemoteNG.Tools; using mRemoteNG.Tools.Cmdline; using mRemoteNG.UI; +using System; +using System.Diagnostics; +using System.Drawing; +using System.Threading; +using System.Windows.Forms; // ReSharper disable ArrangeAccessorOwnerBody namespace mRemoteNG.Connection.Protocol { - public class PuttyBase : ProtocolBase + public class PuttyBase : ProtocolBase { private const int IDM_RECONF = 0x50; // PuTTY Settings Menu ID private bool _isPuttyNg; @@ -108,7 +108,7 @@ namespace mRemoteNG.Connection.Protocol arguments.Add("-" + (int)PuttySSHVersion); - if (((int)Force & (int)ConnectionInfo.Force.NoCredentials) != (int)ConnectionInfo.Force.NoCredentials) + if (!Force.HasFlag(ConnectionInfo.Force.NoCredentials)) { if (!string.IsNullOrEmpty(username)) { diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs index 703e2b38..0feb886c 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs @@ -1,11 +1,3 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Drawing; -using System.Runtime.InteropServices; -using System.Threading; -using System.Windows.Forms; using AxMSTSCLib; using mRemoteNG.App; using mRemoteNG.Messages; @@ -14,10 +6,16 @@ using mRemoteNG.Tools; using mRemoteNG.UI; using mRemoteNG.UI.Forms; using MSTSCLib; +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.Threading; +using System.Windows.Forms; namespace mRemoteNG.Connection.Protocol.RDP { - public class RdpProtocol : ProtocolBase + public class RdpProtocol : ProtocolBase { /* RDP v8 requires Windows 7 with: * https://support.microsoft.com/en-us/kb/2592687 @@ -355,7 +353,7 @@ namespace mRemoteNG.Connection.Protocol.RDP { _rdpClient.TransportSettings.GatewayCredsSource = 1; // TSC_PROXY_CREDS_MODE_SMARTCARD } - if (_rdpVersion >= Versions.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials) + if (_rdpVersion >= Versions.RDC61 && !Force.HasFlag(ConnectionInfo.Force.NoCredentials)) { if (_connectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.Yes) { @@ -389,11 +387,11 @@ namespace mRemoteNG.Connection.Protocol.RDP { bool value; - if ((Force & ConnectionInfo.Force.UseConsoleSession) == ConnectionInfo.Force.UseConsoleSession) + if (Force.HasFlag(ConnectionInfo.Force.UseConsoleSession)) { value = true; } - else if ((Force & ConnectionInfo.Force.DontUseConsoleSession) == ConnectionInfo.Force.DontUseConsoleSession) + else if (Force.HasFlag(ConnectionInfo.Force.DontUseConsoleSession)) { value = false; } @@ -454,7 +452,7 @@ namespace mRemoteNG.Connection.Protocol.RDP { try { - if ((Force & ConnectionInfo.Force.NoCredentials) == ConnectionInfo.Force.NoCredentials) + if (Force.HasFlag(ConnectionInfo.Force.NoCredentials)) { return; } @@ -525,7 +523,7 @@ namespace mRemoteNG.Connection.Protocol.RDP SetExtendedProperty("DesktopScaleFactor", scaleFactor); SetExtendedProperty("DeviceScaleFactor", (uint)100); - if ((Force & ConnectionInfo.Force.Fullscreen) == ConnectionInfo.Force.Fullscreen) + if (Force.HasFlag(ConnectionInfo.Force.Fullscreen)) { _rdpClient.FullScreen = true; _rdpClient.DesktopWidth = Screen.FromControl(_frmMain).Bounds.Width; diff --git a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs index fbe95b50..a405a576 100644 --- a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs +++ b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs @@ -1,14 +1,14 @@ -using System; -using System.ComponentModel; using mRemoteNG.App; using mRemoteNG.Tools; using mRemoteNG.UI.Forms; +using System; +using System.ComponentModel; // ReSharper disable ArrangeAccessorOwnerBody namespace mRemoteNG.Connection.Protocol.VNC { - public class ProtocolVNC : ProtocolBase + public class ProtocolVNC : ProtocolBase { #region Properties public bool SmartSize @@ -164,8 +164,7 @@ namespace mRemoteNG.Connection.Protocol.VNC _VNC.ConnectComplete += VNCEvent_Connected; _VNC.ConnectionLost += VNCEvent_Disconnected; FrmMain.ClipboardChanged += VNCEvent_ClipboardChanged; - if (((int)Force & (int)ConnectionInfo.Force.NoCredentials) != (int)ConnectionInfo.Force.NoCredentials - && Info?.Password?.Length > 0) + if (!Force.HasFlag(ConnectionInfo.Force.NoCredentials) && Info?.Password?.Length > 0) { _VNC.GetPassword = VNCEvent_Authenticate; } diff --git a/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs b/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs index aeba0909..2f76679f 100644 --- a/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs +++ b/mRemoteV1/Tree/SelectedConnectionDeletionConfirmer.cs @@ -1,17 +1,16 @@ -using System; -using System.Windows.Forms; -using mRemoteNG.Connection; +using mRemoteNG.Connection; using mRemoteNG.Container; -using mRemoteNG.UI.TaskDialog; +using System; +using System.Windows.Forms; namespace mRemoteNG.Tree { - public class SelectedConnectionDeletionConfirmer : IConfirm + public class SelectedConnectionDeletionConfirmer : IConfirm { - private readonly Func _confirmationFunc; + private readonly Func _confirmationFunc; - public SelectedConnectionDeletionConfirmer(Func confirmationFunc) + public SelectedConnectionDeletionConfirmer(Func confirmationFunc) { _confirmationFunc = confirmationFunc; } @@ -49,7 +48,7 @@ namespace mRemoteNG.Tree private bool PromptUser(string promptMessage) { - var msgBoxResponse = CTaskDialog.MessageBox(Application.ProductName, promptMessage, "", ETaskDialogButtons.YesNo, ESysIcons.Question); + var msgBoxResponse = _confirmationFunc(promptMessage); return msgBoxResponse == DialogResult.Yes; } } diff --git a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs index e5976d13..cc8b6be6 100644 --- a/mRemoteV1/UI/Window/ConnectionTreeWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionTreeWindow.cs @@ -5,6 +5,7 @@ using mRemoteNG.Themes; using mRemoteNG.Tree; using mRemoteNG.Tree.Root; using mRemoteNG.UI.Controls; +using mRemoteNG.UI.TaskDialog; using System; using System.Collections.Generic; using System.ComponentModel; @@ -104,7 +105,8 @@ namespace mRemoteNG.UI.Window #region ConnectionTree private void SetConnectionTreeEventHandlers() { - olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(MessageBox.Show); + olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(prompt => + CTaskDialog.MessageBox(Application.ProductName, prompt, "", ETaskDialogButtons.YesNo, ESysIcons.Question)); olvConnections.KeyDown += tvConnections_KeyDown; olvConnections.KeyPress += tvConnections_KeyPress; SetTreePostSetupActions();