From af7c14b2f278fe43bb0bc789ff324112e388e96c Mon Sep 17 00:00:00 2001 From: David Sparer Date: Tue, 19 Mar 2019 14:24:11 -0500 Subject: [PATCH 1/2] implemented a view only mode for RDP --- mRemoteV1/Connection/ConnectionInfo.cs | 15 +++--- .../Connection/Protocol/ISupportsViewOnly.cs | 20 ++++++++ .../Connection/Protocol/RDP/RdpProtocol.cs | 42 +++++++++++++---- .../Protocol/VNC/Connection.Protocol.VNC.cs | 6 +-- .../Resources/Language/Language.Designer.cs | 11 ++++- mRemoteV1/Resources/Language/Language.resx | 13 +++-- .../UI/Controls/ConnectionContextMenu.cs | 47 ++++++++++++++----- mRemoteV1/UI/Window/ConnectionWindow.cs | 23 ++++++--- mRemoteV1/mRemoteV1.csproj | 1 + 9 files changed, 136 insertions(+), 42 deletions(-) create mode 100644 mRemoteV1/Connection/Protocol/ISupportsViewOnly.cs diff --git a/mRemoteV1/Connection/ConnectionInfo.cs b/mRemoteV1/Connection/ConnectionInfo.cs index 53190f589..21e2906c6 100644 --- a/mRemoteV1/Connection/ConnectionInfo.cs +++ b/mRemoteV1/Connection/ConnectionInfo.cs @@ -1,4 +1,9 @@ -using mRemoteNG.App; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using mRemoteNG.App; using mRemoteNG.Connection.Protocol; using mRemoteNG.Connection.Protocol.Http; using mRemoteNG.Connection.Protocol.ICA; @@ -10,11 +15,6 @@ using mRemoteNG.Connection.Protocol.Telnet; using mRemoteNG.Connection.Protocol.VNC; using mRemoteNG.Container; using mRemoteNG.Tree; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; namespace mRemoteNG.Connection @@ -163,7 +163,8 @@ namespace mRemoteNG.Connection DoNotJump = 4, OverridePanel = 8, DontUseConsoleSession = 16, - NoCredentials = 32 + NoCredentials = 32, + ViewOnly = 64 } #endregion diff --git a/mRemoteV1/Connection/Protocol/ISupportsViewOnly.cs b/mRemoteV1/Connection/Protocol/ISupportsViewOnly.cs new file mode 100644 index 000000000..4bb70be21 --- /dev/null +++ b/mRemoteV1/Connection/Protocol/ISupportsViewOnly.cs @@ -0,0 +1,20 @@ +namespace mRemoteNG.Connection.Protocol +{ + /// + /// Signifies that a protocol supports View Only mode. When in View Only mode, + /// the control will not capture and send input events to the remote host. + /// + public interface ISupportsViewOnly + { + /// + /// Whether this control is in view only mode. + /// + bool ViewOnly { get; set; } + + /// + /// Toggles whether the control will capture and send input events to the remote host. + /// The local host will continue to receive data from the remote host regardless of this setting. + /// + void ToggleViewOnly(); + } +} \ No newline at end of file diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs index ade6e5a53..2c3bebec5 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs @@ -1,3 +1,9 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.Threading; +using System.Windows.Forms; using AxMSTSCLib; using mRemoteNG.App; using mRemoteNG.Messages; @@ -6,16 +12,10 @@ 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, ISupportsViewOnly { /* RDP v8 requires Windows 7 with: * https://support.microsoft.com/en-us/kb/2592687 @@ -24,6 +24,7 @@ namespace mRemoteNG.Connection.Protocol.RDP * * Windows 8+ support RDP v8 out of the box. */ + private AxHost _axHost; private MsRdpClient8NotSafeForScripting _rdpClient; private Version _rdpVersion; private ConnectionInfo _connectionInfo; @@ -86,6 +87,12 @@ namespace mRemoteNG.Connection.Protocol.RDP public bool LoadBalanceInfoUseUtf8 { get; set; } + public bool ViewOnly + { + get => !_axHost.Enabled; + set => _axHost.Enabled = !value; + } + #endregion #region Constructors @@ -116,7 +123,8 @@ namespace mRemoteNG.Connection.Protocol.RDP Application.DoEvents(); } - _rdpClient = (MsRdpClient8NotSafeForScripting)((AxMsRdpClient8NotSafeForScripting)Control).GetOcx(); + _axHost = (AxMsRdpClient8NotSafeForScripting)Control; + _rdpClient = (MsRdpClient8NotSafeForScripting)_axHost.GetOcx(); } catch (System.Runtime.InteropServices.COMException ex) { @@ -160,6 +168,7 @@ namespace mRemoteNG.Connection.Protocol.RDP SetAuthenticationLevel(); SetLoadBalanceInfo(); SetRdGateway(); + ViewOnly = Force.HasFlag(ConnectionInfo.Force.ViewOnly); _rdpClient.ColorDepth = (int)_connectionInfo.Colors; @@ -187,6 +196,7 @@ namespace mRemoteNG.Connection.Protocol.RDP { _rdpClient.Connect(); base.Connect(); + return true; } catch (Exception ex) @@ -234,6 +244,22 @@ namespace mRemoteNG.Connection.Protocol.RDP } } + /// + /// Toggles whether the RDP ActiveX control will capture and send input events to the remote host. + /// The local host will continue to receive data from the remote host regardless of this setting. + /// + public void ToggleViewOnly() + { + try + { + ViewOnly = !ViewOnly; + } + catch (Exception ex) + { + Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, $"Could not toggle view only mode for host {_connectionInfo.Hostname}"); + } + } + public override void Focus() { try diff --git a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs index c948ca5da..be25d5b91 100644 --- a/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs +++ b/mRemoteV1/Connection/Protocol/VNC/Connection.Protocol.VNC.cs @@ -1,15 +1,15 @@ +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, ISupportsViewOnly { #region Properties diff --git a/mRemoteV1/Resources/Language/Language.Designer.cs b/mRemoteV1/Resources/Language/Language.Designer.cs index d0431b915..cea2e48d4 100644 --- a/mRemoteV1/Resources/Language/Language.Designer.cs +++ b/mRemoteV1/Resources/Language/Language.Designer.cs @@ -105,6 +105,15 @@ namespace mRemoteNG { } } + /// + /// Looks up a localized string similar to Connect in View Only mode. + /// + internal static string ConnectInViewOnlyMode { + get { + return ResourceManager.GetString("ConnectInViewOnlyMode", resourceCulture); + } + } + /// /// Looks up a localized string similar to The connection file could not be found.. /// @@ -3984,7 +3993,7 @@ namespace mRemoteNG { } /// - /// Looks up a localized string similar to View Only (VNC). + /// Looks up a localized string similar to View Only. /// internal static string strMenuViewOnly { get { diff --git a/mRemoteV1/Resources/Language/Language.resx b/mRemoteV1/Resources/Language/Language.resx index 6cf2ec228..c492084a8 100644 --- a/mRemoteV1/Resources/Language/Language.resx +++ b/mRemoteV1/Resources/Language/Language.resx @@ -1220,7 +1220,7 @@ See the Microsoft Support article at http://support.microsoft.com/kb/811833 for &View - View Only (VNC) + View Only Website @@ -2761,11 +2761,11 @@ Development Channel includes Alphas, Betas & Release Candidates. Proxy - Multi SSH: - + Multi SSH: + - Press ENTER to send. Ctrl+C is sent immediately. - + Press ENTER to send. Ctrl+C is sent immediately. + Show this connection in the favorites menu. @@ -2775,4 +2775,7 @@ Development Channel includes Alphas, Betas & Release Candidates. Favorites + + Connect in View Only mode + \ No newline at end of file diff --git a/mRemoteV1/UI/Controls/ConnectionContextMenu.cs b/mRemoteV1/UI/Controls/ConnectionContextMenu.cs index 1a7176379..e99905fff 100644 --- a/mRemoteV1/UI/Controls/ConnectionContextMenu.cs +++ b/mRemoteV1/UI/Controls/ConnectionContextMenu.cs @@ -26,6 +26,7 @@ namespace mRemoteNG.UI.Controls private ToolStripMenuItem _cMenTreeConnectWithOptionsConnectToConsoleSession; private ToolStripMenuItem _cMenTreeConnectWithOptionsNoCredentials; private ToolStripMenuItem _cMenTreeConnectWithOptionsConnectInFullscreen; + private ToolStripMenuItem _cMenTreeConnectWithOptionsViewOnly; private ToolStripMenuItem _cMenTreeDisconnect; private ToolStripSeparator _cMenTreeSep2; private ToolStripMenuItem _cMenTreeToolsTransferFile; @@ -82,6 +83,7 @@ namespace mRemoteNG.UI.Controls _cMenTreeConnectWithOptionsConnectInFullscreen = new ToolStripMenuItem(); _cMenTreeConnectWithOptionsNoCredentials = new ToolStripMenuItem(); _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting = new ToolStripMenuItem(); + _cMenTreeConnectWithOptionsViewOnly = new ToolStripMenuItem(); _cMenTreeDisconnect = new ToolStripMenuItem(); _cMenTreeSep1 = new ToolStripSeparator(); _cMenTreeToolsExternalApps = new ToolStripMenuItem(); @@ -157,7 +159,8 @@ namespace mRemoteNG.UI.Controls _cMenTreeConnectWithOptionsDontConnectToConsoleSession, _cMenTreeConnectWithOptionsConnectInFullscreen, _cMenTreeConnectWithOptionsNoCredentials, - _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting + _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting, + _cMenTreeConnectWithOptionsViewOnly }); _cMenTreeConnectWithOptions.Name = "_cMenTreeConnectWithOptions"; _cMenTreeConnectWithOptions.Size = new System.Drawing.Size(199, 22); @@ -207,6 +210,15 @@ namespace mRemoteNG.UI.Controls _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting.Text = "Choose panel before connecting"; _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting.Click += OnChoosePanelBeforeConnectingClicked; // + // cMenTreeConnectWithOptionsViewOnly + // + _cMenTreeConnectWithOptionsViewOnly.Image = Resources.View; + _cMenTreeConnectWithOptionsViewOnly.Name = + "_cMenTreeConnectWithOptionsViewOnly"; + _cMenTreeConnectWithOptionsViewOnly.Size = new System.Drawing.Size(245, 22); + _cMenTreeConnectWithOptionsViewOnly.Text = Language.ConnectInViewOnlyMode; + _cMenTreeConnectWithOptionsViewOnly.Click += ConnectWithOptionsViewOnlyOnClick; + // // cMenTreeDisconnect // _cMenTreeDisconnect.Image = Resources.Pause; @@ -396,6 +408,7 @@ namespace mRemoteNG.UI.Controls _cMenTreeConnectWithOptionsConnectInFullscreen.Text = Language.strConnectInFullscreen; _cMenTreeConnectWithOptionsNoCredentials.Text = Language.strConnectNoCredentials; _cMenTreeConnectWithOptionsChoosePanelBeforeConnecting.Text = Language.strChoosePanelBeforeConnecting; + _cMenTreeConnectWithOptionsViewOnly.Text = Language.ConnectInViewOnlyMode; _cMenTreeDisconnect.Text = Language.strMenuDisconnect; _cMenTreeToolsExternalApps.Text = Language.strMenuExternalTools; @@ -436,13 +449,13 @@ namespace mRemoteNG.UI.Controls { ShowHideMenuItemsForRootConnectionNode(); } - else if (_connectionTree.SelectedNode is ContainerInfo) + else if (_connectionTree.SelectedNode is ContainerInfo containerInfo) { - ShowHideMenuItemsForContainer(_connectionTree.SelectedNode); + ShowHideMenuItemsForContainer(containerInfo); } - else if (_connectionTree.SelectedNode is PuttySessionInfo) + else if (_connectionTree.SelectedNode is PuttySessionInfo puttyNode) { - ShowHideMenuItemsForPuttyNode(_connectionTree.SelectedNode); + ShowHideMenuItemsForPuttyNode(puttyNode); } else { @@ -475,6 +488,7 @@ namespace mRemoteNG.UI.Controls _cMenTreeDelete.Enabled = false; _cMenTreeMoveUp.Enabled = false; _cMenTreeMoveDown.Enabled = false; + _cMenTreeConnectWithOptionsViewOnly.Enabled = false; } internal void ShowHideMenuItemsForRootConnectionNode() @@ -491,22 +505,22 @@ namespace mRemoteNG.UI.Controls _cMenTreeDelete.Enabled = false; _cMenTreeMoveUp.Enabled = false; _cMenTreeMoveDown.Enabled = false; + _cMenTreeConnectWithOptionsViewOnly.Enabled = false; } - internal void ShowHideMenuItemsForContainer(ConnectionInfo connectionInfo) + internal void ShowHideMenuItemsForContainer(ContainerInfo containerInfo) { _cMenTreeConnectWithOptionsConnectInFullscreen.Enabled = false; _cMenTreeConnectWithOptionsConnectToConsoleSession.Enabled = false; - _cMenTreeDisconnect.Enabled = false; - var openConnections = ((ContainerInfo)connectionInfo).Children.Sum(child => child.OpenConnections.Count); - if (openConnections > 0) - _cMenTreeDisconnect.Enabled = true; + var hasOpenConnections = containerInfo.Children.Any(child => child.OpenConnections.Count > 0); + _cMenTreeDisconnect.Enabled = hasOpenConnections; _cMenTreeToolsTransferFile.Enabled = false; + _cMenTreeConnectWithOptionsViewOnly.Enabled = false; } - internal void ShowHideMenuItemsForPuttyNode(ConnectionInfo connectionInfo) + internal void ShowHideMenuItemsForPuttyNode(PuttySessionInfo connectionInfo) { _cMenTreeAddConnection.Enabled = false; _cMenTreeAddFolder.Enabled = false; @@ -527,6 +541,7 @@ namespace mRemoteNG.UI.Controls _cMenTreeMoveDown.Enabled = false; _cMenTreeImport.Enabled = false; _cMenTreeExportFile.Enabled = false; + _cMenTreeConnectWithOptionsViewOnly.Enabled = false; } internal void ShowHideMenuItemsForConnectionNode(ConnectionInfo connectionInfo) @@ -545,6 +560,9 @@ namespace mRemoteNG.UI.Controls if (connectionInfo.Protocol == ProtocolType.IntApp) _cMenTreeConnectWithOptionsNoCredentials.Enabled = false; + + if (connectionInfo.Protocol != ProtocolType.RDP && connectionInfo.Protocol != ProtocolType.VNC) + _cMenTreeConnectWithOptionsViewOnly.Enabled = false; } internal void DisableShortcutKeys() @@ -691,6 +709,13 @@ namespace mRemoteNG.UI.Controls ConnectionInfo.Force.DoNotJump); } + private void ConnectWithOptionsViewOnlyOnClick(object sender, EventArgs e) + { + var connectionTarget = _connectionTree.SelectedNode as ContainerInfo + ?? _connectionTree.SelectedNode; + _connectionInitiator.OpenConnection(connectionTarget, ConnectionInfo.Force.ViewOnly); + } + private void OnDisconnectClicked(object sender, EventArgs e) { DisconnectConnection(_connectionTree.SelectedNode); diff --git a/mRemoteV1/UI/Window/ConnectionWindow.cs b/mRemoteV1/UI/Window/ConnectionWindow.cs index c0d91e8c9..f3567ca1f 100644 --- a/mRemoteV1/UI/Window/ConnectionWindow.cs +++ b/mRemoteV1/UI/Window/ConnectionWindow.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -15,9 +15,9 @@ using mRemoteNG.Themes; using mRemoteNG.Tools; using mRemoteNG.UI.Forms; using mRemoteNG.UI.Forms.Input; +using mRemoteNG.UI.Tabs; using mRemoteNG.UI.TaskDialog; using WeifenLuo.WinFormsUI.Docking; -using mRemoteNG.UI.Tabs; namespace mRemoteNG.UI.Window { @@ -363,6 +363,16 @@ namespace mRemoteNG.UI.Window var interfaceControl = GetInterfaceControl(); if (interfaceControl == null) return; + if (interfaceControl.Protocol is ISupportsViewOnly viewOnly) + { + cmenTabViewOnly.Visible = true; + cmenTabViewOnly.Checked = viewOnly.ViewOnly; + } + else + { + cmenTabViewOnly.Visible = false; + } + if (interfaceControl.Info.Protocol == ProtocolType.RDP) { var rdp = (RdpProtocol)interfaceControl.Protocol; @@ -381,18 +391,15 @@ namespace mRemoteNG.UI.Window { var vnc = (ProtocolVNC)interfaceControl.Protocol; cmenTabSendSpecialKeys.Visible = true; - cmenTabViewOnly.Visible = true; cmenTabSmartSize.Visible = true; cmenTabStartChat.Visible = true; cmenTabRefreshScreen.Visible = true; cmenTabTransferFile.Visible = false; cmenTabSmartSize.Checked = vnc.SmartSize; - cmenTabViewOnly.Checked = vnc.ViewOnly; } else { cmenTabSendSpecialKeys.Visible = false; - cmenTabViewOnly.Visible = false; cmenTabStartChat.Visible = false; cmenTabRefreshScreen.Visible = false; cmenTabTransferFile.Visible = false; @@ -500,9 +507,11 @@ namespace mRemoteNG.UI.Window try { var interfaceControl = GetInterfaceControl(); - if (!(interfaceControl?.Protocol is ProtocolVNC vnc)) return; + if (!(interfaceControl?.Protocol is ISupportsViewOnly viewOnly)) + return; + cmenTabViewOnly.Checked = !cmenTabViewOnly.Checked; - vnc.ToggleViewOnly(); + viewOnly.ToggleViewOnly(); } catch (Exception ex) { diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 7e7a1419b..d10d685fa 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -239,6 +239,7 @@ + Component From 5a317c5d3e4107c1deeb52869b1b21ff233c9245 Mon Sep 17 00:00:00 2001 From: Faryan Rezagholi Date: Tue, 19 Mar 2019 21:12:09 +0100 Subject: [PATCH 2/2] Added/unified german language resources --- mRemoteV1/Resources/Language/Language.de.resx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mRemoteV1/Resources/Language/Language.de.resx b/mRemoteV1/Resources/Language/Language.de.resx index ca3d30256..4373d8d3e 100644 --- a/mRemoteV1/Resources/Language/Language.de.resx +++ b/mRemoteV1/Resources/Language/Language.de.resx @@ -1082,7 +1082,7 @@ Starte mit neuer Datei. Text anzeigen - SmartSize (RDP/VNC) + Smart-Size-Modus (RDP/VNC) SSH-Dateiübertragung @@ -1103,7 +1103,7 @@ Starte mit neuer Datei. &Ansicht - Nur Ansicht (VNC) + View-Only-Modus Webseite @@ -1157,7 +1157,7 @@ Starte mit neuer Datei. Normal - Keine automatische Größenanpassung (SmartSize) + Keine automatische Größenanpassung (Smart-Size) Keine Updates verfügbar @@ -1467,7 +1467,7 @@ Wenn Sie Fehler feststellen, dann sollten Sie eine neue Verbindungsdatei erstell Auflösung - SmartSize-Modus + Smart-Size-Modus Verwende Konsole @@ -2660,4 +2660,7 @@ Development umfasst Alphas, Betas und Release Candidates. Favoriten + + Im View-Only-Modus verbinden + \ No newline at end of file