border fix for puttyng 0.70.0.1+ -- backported from develop

This commit is contained in:
Sean Kaim
2019-03-20 10:21:56 -04:00
parent bdeb4b4dcc
commit 2d175fd575

View File

@@ -13,7 +13,7 @@ using mRemoteNG.Tools.Cmdline;
namespace mRemoteNG.Connection.Protocol
{
public class PuttyBase : ProtocolBase
{
{
private const int IDM_RECONF = 0x50; // PuTTY Settings Menu ID
private bool _isPuttyNg;
@@ -42,7 +42,7 @@ namespace mRemoteNG.Connection.Protocol
Event_Closed(this);
}
#endregion
#region Public Methods
public override bool Connect()
{
@@ -62,11 +62,11 @@ namespace mRemoteNG.Connection.Protocol
var arguments = new CommandLineArguments {EscapeForShell = false};
arguments.Add("-load", InterfaceControl.Info.PuttySession);
if (!(InterfaceControl.Info is PuttySessionInfo))
{
arguments.Add("-" + PuttyProtocol);
if (PuttyProtocol == Putty_Protocol.ssh)
{
var username = "";
@@ -89,7 +89,7 @@ namespace mRemoteNG.Connection.Protocol
break;
}
}
if (!string.IsNullOrEmpty(InterfaceControl.Info?.Password))
{
password = InterfaceControl.Info.Password;
@@ -102,9 +102,9 @@ namespace mRemoteNG.Connection.Protocol
password = cryptographyProvider.Decrypt(Settings.Default.DefaultPassword, Runtime.EncryptionKey);
}
}
arguments.Add("-" + (int)PuttySSHVersion);
if (((int)Force & (int)ConnectionInfo.Force.NoCredentials) != (int)ConnectionInfo.Force.NoCredentials)
{
if (!string.IsNullOrEmpty(username))
@@ -117,24 +117,24 @@ namespace mRemoteNG.Connection.Protocol
}
}
}
arguments.Add("-P", InterfaceControl.Info.Port.ToString());
arguments.Add(InterfaceControl.Info.Hostname);
}
if (_isPuttyNg)
{
arguments.Add("-hwndparent", InterfaceControl.Handle.ToString());
}
PuttyProcess.StartInfo.Arguments = arguments.ToString();
PuttyProcess.EnableRaisingEvents = true;
PuttyProcess.Exited += ProcessExited;
PuttyProcess.Start();
PuttyProcess.WaitForInputIdle(Settings.Default.MaxPuttyWaitTime * 1000);
var startTicks = Environment.TickCount;
while (PuttyHandle.ToInt32() == 0 & Environment.TickCount < startTicks + Settings.Default.MaxPuttyWaitTime * 1000)
{
@@ -153,17 +153,17 @@ namespace mRemoteNG.Connection.Protocol
Thread.Sleep(0);
}
}
if (!_isPuttyNg)
{
NativeMethods.SetParent(PuttyHandle, InterfaceControl.Handle);
}
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strPuttyStuff, true);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strPuttyHandle, PuttyHandle), true);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strPuttyTitle, PuttyProcess.MainWindowTitle), true);
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strPuttyParentHandle, InterfaceControl.Parent.Handle), true);
Resize(this, new EventArgs());
base.Connect();
return true;
@@ -174,7 +174,7 @@ namespace mRemoteNG.Connection.Protocol
return false;
}
}
public override void Focus()
{
try
@@ -190,7 +190,7 @@ namespace mRemoteNG.Connection.Protocol
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strPuttyFocusFailed + Environment.NewLine + ex.Message, true);
}
}
public override void Resize(object sender, EventArgs e)
{
try
@@ -200,20 +200,28 @@ namespace mRemoteNG.Connection.Protocol
return;
}
var left = -(SystemInformation.FrameBorderSize.Width + SystemInformation.HorizontalResizeBorderThickness);
var top = -(SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height + SystemInformation.VerticalResizeBorderThickness);
var width = InterfaceControl.Width + (SystemInformation.FrameBorderSize.Width + SystemInformation.HorizontalResizeBorderThickness) * 2;
var height = InterfaceControl.Height + SystemInformation.CaptionHeight +
(SystemInformation.FrameBorderSize.Height + SystemInformation.VerticalResizeBorderThickness) * 2;
if (_isPuttyNg)
{
// PuTTYNG 0.70.0.1 and later doesn't have any window borders
NativeMethods.MoveWindow(PuttyHandle, 0, 0, InterfaceControl.Width, InterfaceControl.Height, true);
}
else
{
var left = -(SystemInformation.FrameBorderSize.Width + SystemInformation.HorizontalResizeBorderThickness);
var top = -(SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height + SystemInformation.VerticalResizeBorderThickness);
var width = InterfaceControl.Width + (SystemInformation.FrameBorderSize.Width + SystemInformation.HorizontalResizeBorderThickness) * 2;
var height = InterfaceControl.Height + SystemInformation.CaptionHeight + (SystemInformation.FrameBorderSize.Height +
SystemInformation.VerticalResizeBorderThickness) * 2;
NativeMethods.MoveWindow(PuttyHandle, left, top, width, height, true);
}
NativeMethods.MoveWindow(PuttyHandle, left, top, width, height, true);
}
}
catch (Exception ex)
{
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strPuttyResizeFailed + Environment.NewLine + ex.Message, true);
}
}
public override void Close()
{
try
@@ -227,7 +235,7 @@ namespace mRemoteNG.Connection.Protocol
{
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strPuttyKillFailed + Environment.NewLine + ex.Message, true);
}
try
{
PuttyProcess.Dispose();
@@ -236,10 +244,10 @@ namespace mRemoteNG.Connection.Protocol
{
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strPuttyDisposeFailed + Environment.NewLine + ex.Message, true);
}
base.Close();
}
public void ShowSettingsDialog()
{
try
@@ -253,7 +261,7 @@ namespace mRemoteNG.Connection.Protocol
}
}
#endregion
#region Enums
protected enum Putty_Protocol