diff --git a/mRemoteV1/Connection/ConnectionInitiator.cs b/mRemoteV1/Connection/ConnectionInitiator.cs index 4502df26..d7556b54 100644 --- a/mRemoteV1/Connection/ConnectionInitiator.cs +++ b/mRemoteV1/Connection/ConnectionInitiator.cs @@ -288,8 +288,10 @@ namespace mRemoteNG.Connection var prot = (ProtocolBase)sender; if (prot.InterfaceControl.Info.Protocol != ProtocolType.RDP) return; - if (Convert.ToInt32(errorMessage) > -1) - Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpProtocol.FatalErrors.GetError(errorMessage))); + var errorMessageAsInt = Convert.ToInt32(errorMessage); + + if (errorMessageAsInt > -1) + Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, errorMessage, RdpErrorTranslator.Translate(errorMessageAsInt))); } catch (Exception ex) { diff --git a/mRemoteV1/Connection/Protocol/RDP/Enums/RdpVersion.cs b/mRemoteV1/Connection/Protocol/RDP/Enums/RdpVersion.cs new file mode 100644 index 00000000..9b8df163 --- /dev/null +++ b/mRemoteV1/Connection/Protocol/RDP/Enums/RdpVersion.cs @@ -0,0 +1,13 @@ +using System; + +namespace mRemoteNG.Connection.Protocol.RDP +{ + public static class RdpVersion + { + public static readonly Version RDC60 = new Version(6, 0, 6000); + public static readonly Version RDC61 = new Version(6, 0, 6001); + public static readonly Version RDC70 = new Version(6, 1, 7600); + public static readonly Version RDC80 = new Version(6, 2, 9200); + public static readonly Version RDC81 = new Version(6, 3, 9600); + } +} diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpErrorTranslator.cs b/mRemoteV1/Connection/Protocol/RDP/RdpErrorTranslator.cs new file mode 100644 index 00000000..e1320eab --- /dev/null +++ b/mRemoteV1/Connection/Protocol/RDP/RdpErrorTranslator.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using mRemoteNG.App; + +namespace mRemoteNG.Connection.Protocol.RDP +{ + public static class RdpErrorTranslator + { + private static Hashtable _description; + + private static void InitDescription() + { + _description = new Hashtable + { + {0, Language.strRdpErrorUnknown}, + {1, Language.strRdpErrorCode1}, + {2, Language.strRdpErrorOutOfMemory}, + {3, Language.strRdpErrorWindowCreation}, + {4, Language.strRdpErrorCode2}, + {5, Language.strRdpErrorCode3}, + {6, Language.strRdpErrorCode4}, + {7, Language.strRdpErrorConnection}, + {100, Language.strRdpErrorWinsock} + }; + } + + /// + /// Translates the provided RDP error ID to + /// a user-friendly error message. + /// + /// + public static string Translate(int id) + { + try + { + if (_description == null) + InitDescription(); + + return (string)_description?[id]; + } + catch (Exception ex) + { + Runtime.MessageCollector.AddExceptionStackTrace(Language.strRdpErrorGetFailure, ex); + return string.Format(Language.strRdpErrorUnknown, id); + } + } + } +} diff --git a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs index 08336785..608c4afc 100644 --- a/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs +++ b/mRemoteV1/Connection/Protocol/RDP/RdpProtocol.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Diagnostics; using System.Drawing; using System.Threading; @@ -145,7 +144,7 @@ namespace mRemoteNG.Connection.Protocol.RDP _rdpClient.AdvancedSettings2.overallConnectionTimeout = Settings.Default.ConRDPOverallConnectionTimeout; _rdpClient.AdvancedSettings2.BitmapPeristence = Convert.ToInt32(_connectionInfo.CacheBitmaps); - if (_rdpVersion >= Versions.RDC61) + if (_rdpVersion >= RdpVersion.RDC61) { _rdpClient.AdvancedSettings7.EnableCredSspSupport = _connectionInfo.UseCredSsp; _rdpClient.AdvancedSettings8.AudioQualityMode = (uint)_connectionInfo.SoundQuality; @@ -290,7 +289,7 @@ namespace mRemoteNG.Connection.Protocol.RDP private void ReconnectForResize() { - if (_rdpVersion < Versions.RDC80) + if (_rdpVersion < RdpVersion.RDC80) { return; } @@ -341,7 +340,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 >= RdpVersion.RDC61 && (Force & ConnectionInfo.Force.NoCredentials) != ConnectionInfo.Force.NoCredentials) { if (_connectionInfo.RDGatewayUseConnectionCredentials == RDGatewayUseConnectionCredentials.Yes) { @@ -388,7 +387,7 @@ namespace mRemoteNG.Connection.Protocol.RDP value = _connectionInfo.UseConsoleSession; } - if (_rdpVersion >= Versions.RDC61) + if (_rdpVersion >= RdpVersion.RDC61) { Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strRdpSetConsoleSwitch, _rdpVersion), true); _rdpClient.AdvancedSettings7.ConnectToAdministerServer = value; @@ -644,7 +643,6 @@ namespace mRemoteNG.Connection.Protocol.RDP } } - private void RDPEvent_OnFatalError(int errorCode) { Event_ErrorOccured(this, Convert.ToString(errorCode)); @@ -693,28 +691,13 @@ namespace mRemoteNG.Connection.Protocol.RDP private void RDPEvent_OnLeaveFullscreenMode() { Fullscreen = false; - _leaveFullscreenEvent?.Invoke(this, new EventArgs()); + LeaveFullscreen?.Invoke(this, new EventArgs()); } #endregion - #region Public Events & Handlers public delegate void LeaveFullscreenEventHandler(object sender, EventArgs e); - private LeaveFullscreenEventHandler _leaveFullscreenEvent; - - public event LeaveFullscreenEventHandler LeaveFullscreen - { - add - { - _leaveFullscreenEvent = (LeaveFullscreenEventHandler)Delegate.Combine(_leaveFullscreenEvent, value); - } - remove - { - _leaveFullscreenEvent = (LeaveFullscreenEventHandler)Delegate.Remove(_leaveFullscreenEvent, value); - } - } - #endregion + public event LeaveFullscreenEventHandler LeaveFullscreen; - #region Enums public enum Defaults { Colors = RdpColors.Colors16Bit, @@ -722,7 +705,6 @@ namespace mRemoteNG.Connection.Protocol.RDP Resolution = RdpResolutions.FitToWindow, Port = 3389 } - #endregion #region Resolution public static Rectangle GetResolutionRectangle(RdpResolutions resolution) @@ -736,60 +718,9 @@ namespace mRemoteNG.Connection.Protocol.RDP { return new Rectangle(0, 0, 0, 0); } - else - { - return new Rectangle(0, 0, Convert.ToInt32(resolutionParts[0]), Convert.ToInt32(resolutionParts[1])); - } + return new Rectangle(0, 0, Convert.ToInt32(resolutionParts[0]), Convert.ToInt32(resolutionParts[1])); } - #endregion - - public static class Versions - { - public static readonly Version RDC60 = new Version(6, 0, 6000); - public static readonly Version RDC61 = new Version(6, 0, 6001); - public static readonly Version RDC70 = new Version(6, 1, 7600); - public static readonly Version RDC80 = new Version(6, 2, 9200); - public static readonly Version RDC81 = new Version(6, 3, 9600); - } - - #region Fatal Errors - public static class FatalErrors - { - private static Hashtable _description; - - private static void InitDescription() - { - _description = new Hashtable - { - {"0", "Language.strRdpErrorUnknown"}, - {"1", "Language.strRdpErrorCode1"}, - {"2", "Language.strRdpErrorOutOfMemory"}, - {"3", "Language.strRdpErrorWindowCreation"}, - {"4", "Language.strRdpErrorCode2"}, - {"5", "Language.strRdpErrorCode3"}, - {"6", "Language.strRdpErrorCode4"}, - {"7", "Language.strRdpErrorConnection"}, - {"100", "Language.strRdpErrorWinsock"} - }; - } - - public static string GetError(string id) - { - try - { - if (_description == null) - InitDescription(); - - return (string)_description?[id]; - } - catch (Exception ex) - { - Runtime.MessageCollector.AddExceptionStackTrace(Language.strRdpErrorGetFailure, ex); - return string.Format(Language.strRdpErrorUnknown, id); - } - } - } - #endregion + #endregion #region Reconnect Stuff public void tmrReconnect_Elapsed(object sender, System.Timers.ElapsedEventArgs e) diff --git a/mRemoteV1/UI/Window/ComponentsCheckWindow.cs b/mRemoteV1/UI/Window/ComponentsCheckWindow.cs index 71852152..ed2306b9 100644 --- a/mRemoteV1/UI/Window/ComponentsCheckWindow.cs +++ b/mRemoteV1/UI/Window/ComponentsCheckWindow.cs @@ -470,10 +470,10 @@ namespace mRemoteNG.UI.Window System.Windows.Forms.Application.DoEvents(); } - if (!(new Version(rdpClient.Version) >= RdpProtocol.Versions.RDC80)) + if (!(new Version(rdpClient.Version) >= RdpVersion.RDC80)) { throw new Exception( - $"Found RDC Client version {rdpClient.Version} but version {RdpProtocol.Versions.RDC80} or higher is required."); + $"Found RDC Client version {rdpClient.Version} but version {RdpVersion.RDC80} or higher is required."); } pbCheck1.Image = Resources.Good_Symbol; diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 8b639679..b94d5a4a 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -236,6 +236,7 @@ + @@ -245,6 +246,7 @@ +