mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
code clean up / fix complier warning
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
@@ -23,6 +22,7 @@ using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
using mRemoteNG.Tree.Root;
|
||||
using mRemoteNG.UI.Forms;
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
@@ -40,9 +40,6 @@ namespace mRemoteNG.Config.Connections
|
||||
#region Private Properties
|
||||
private XmlTextWriter _xmlTextWriter;
|
||||
private SecureString _password = Runtime.EncryptionKey;
|
||||
|
||||
private int _currentNodeIndex;
|
||||
private string _parentConstantId = Convert.ToString(0);
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
@@ -206,9 +203,21 @@ namespace mRemoteNG.Config.Connections
|
||||
var sqlQuery = new SqlCommand("DELETE FROM tblRoot", sqlDatabaseConnector.SqlConnection);
|
||||
sqlQuery.ExecuteNonQuery();
|
||||
|
||||
sqlQuery = new SqlCommand("INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" + MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," + ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")", sqlDatabaseConnector.SqlConnection);
|
||||
sqlQuery.ExecuteNonQuery();
|
||||
}
|
||||
if (rootTreeNode != null)
|
||||
{
|
||||
sqlQuery =
|
||||
new SqlCommand(
|
||||
"INSERT INTO tblRoot (Name, Export, Protected, ConfVersion) VALUES(\'" +
|
||||
MiscTools.PrepareValueForDB(rootTreeNode.Name) + "\', 0, \'" + strProtected + "\'," +
|
||||
ConnectionsFileInfo.ConnectionFileVersion.ToString(CultureInfo.InvariantCulture) + ")",
|
||||
sqlDatabaseConnector.SqlConnection);
|
||||
sqlQuery.ExecuteNonQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, $"UpdateRootNodeTable: rootTreeNode was null. Could not insert!");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateConnectionsTable(ContainerInfo rootTreeNode, SqlDatabaseConnector sqlDatabaseConnector)
|
||||
{
|
||||
@@ -295,7 +304,7 @@ namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
if (((ConnectionInfo)node.Tag).GetTreeNodeType() == TreeNodeType.Connection)
|
||||
{
|
||||
ConnectionInfo curConI = (ConnectionInfo)node.Tag;
|
||||
var curConI = (ConnectionInfo)node.Tag;
|
||||
|
||||
if (curConI.Protocol == ProtocolType.RDP)
|
||||
{
|
||||
@@ -396,7 +405,7 @@ namespace mRemoteNG.Config.Connections
|
||||
_xmlTextWriter.WriteValue("768");
|
||||
_xmlTextWriter.WriteEndElement();
|
||||
|
||||
Rectangle resolution = ProtocolRDP.GetResolutionRectangle(con.Resolution);
|
||||
var resolution = ProtocolRDP.GetResolutionRectangle(con.Resolution);
|
||||
if (resolution.Width == 0)
|
||||
{
|
||||
resolution.Width = 1024;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
|
||||
namespace mRemoteNG.Connection.Protocol
|
||||
namespace mRemoteNG.Connection
|
||||
{
|
||||
public class Converter
|
||||
public static class Converter
|
||||
{
|
||||
public static string ProtocolToString(ProtocolType protocol)
|
||||
{
|
||||
|
||||
@@ -14,36 +14,25 @@ namespace mRemoteNG.Connection.Protocol
|
||||
public class PuttyBase : ProtocolBase
|
||||
{
|
||||
private const int IDM_RECONF = 0x50; // PuTTY Settings Menu ID
|
||||
bool _isPuttyNg;
|
||||
private bool _isPuttyNg;
|
||||
|
||||
#region Public Properties
|
||||
public Putty_Protocol PuttyProtocol { get; set; }
|
||||
|
||||
public Putty_SSHVersion PuttySSHVersion { get; set; }
|
||||
protected Putty_Protocol PuttyProtocol { private get; set; }
|
||||
|
||||
public IntPtr PuttyHandle { get; set; }
|
||||
protected Putty_SSHVersion PuttySSHVersion { private get; set; }
|
||||
|
||||
public Process PuttyProcess { get; set; }
|
||||
private IntPtr PuttyHandle { get; set; }
|
||||
|
||||
private Process PuttyProcess { get; set; }
|
||||
|
||||
public static string PuttyPath { get; set; }
|
||||
|
||||
public bool Focused
|
||||
{
|
||||
get
|
||||
{
|
||||
if (NativeMethods.GetForegroundWindow() == PuttyHandle)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public bool Focused => NativeMethods.GetForegroundWindow() == PuttyHandle;
|
||||
|
||||
public PuttyBase() : base()
|
||||
{
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#region Private Events & Handlers
|
||||
#region Private Events & Handlers
|
||||
private void ProcessExited(object sender, EventArgs e)
|
||||
{
|
||||
Event_Closed(this);
|
||||
@@ -56,24 +45,28 @@ namespace mRemoteNG.Connection.Protocol
|
||||
try
|
||||
{
|
||||
_isPuttyNg = PuttyTypeDetector.GetPuttyType() == PuttyTypeDetector.PuttyType.PuttyNg;
|
||||
|
||||
PuttyProcess = new Process();
|
||||
PuttyProcess.StartInfo.UseShellExecute = false;
|
||||
PuttyProcess.StartInfo.FileName = PuttyPath;
|
||||
|
||||
CommandLineArguments arguments = new CommandLineArguments();
|
||||
arguments.EscapeForShell = false;
|
||||
|
||||
arguments.Add("-load", InterfaceControl.Info.PuttySession);
|
||||
|
||||
PuttyProcess = new Process
|
||||
{
|
||||
StartInfo =
|
||||
{
|
||||
UseShellExecute = false,
|
||||
FileName = PuttyPath
|
||||
}
|
||||
};
|
||||
|
||||
var arguments = new CommandLineArguments {EscapeForShell = false};
|
||||
|
||||
arguments.Add("-load", InterfaceControl.Info.PuttySession);
|
||||
|
||||
if (!(InterfaceControl.Info is PuttySessionInfo))
|
||||
{
|
||||
arguments.Add("-" + PuttyProtocol.ToString());
|
||||
arguments.Add("-" + PuttyProtocol);
|
||||
|
||||
if (PuttyProtocol == Putty_Protocol.ssh)
|
||||
{
|
||||
string username = "";
|
||||
string password = "";
|
||||
var username = "";
|
||||
var password = "";
|
||||
|
||||
if (!string.IsNullOrEmpty(InterfaceControl.Info.Username))
|
||||
{
|
||||
@@ -136,7 +129,7 @@ namespace mRemoteNG.Connection.Protocol
|
||||
PuttyProcess.Start();
|
||||
PuttyProcess.WaitForInputIdle(Convert.ToInt32(Settings.Default.MaxPuttyWaitTime * 1000));
|
||||
|
||||
int startTicks = Environment.TickCount;
|
||||
var startTicks = Environment.TickCount;
|
||||
while (PuttyHandle.ToInt32() == 0 & Environment.TickCount < startTicks + (Settings.Default.MaxPuttyWaitTime * 1000))
|
||||
{
|
||||
if (_isPuttyNg)
|
||||
@@ -161,9 +154,9 @@ namespace mRemoteNG.Connection.Protocol
|
||||
}
|
||||
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strPuttyStuff, true);
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strPuttyHandle, PuttyHandle.ToString()), 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.ToString()), true);
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, string.Format(Language.strPuttyParentHandle, InterfaceControl.Parent.Handle), true);
|
||||
|
||||
Resize(this, new EventArgs());
|
||||
base.Connect();
|
||||
@@ -182,7 +175,7 @@ namespace mRemoteNG.Connection.Protocol
|
||||
{
|
||||
if (ConnectionWindow.InTabDrag)
|
||||
{
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
NativeMethods.SetForegroundWindow(PuttyHandle);
|
||||
}
|
||||
@@ -198,7 +191,7 @@ namespace mRemoteNG.Connection.Protocol
|
||||
{
|
||||
if (InterfaceControl.Size == Size.Empty)
|
||||
{
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
NativeMethods.MoveWindow(PuttyHandle, Convert.ToInt32(-SystemInformation.FrameBorderSize.Width), Convert.ToInt32(-(SystemInformation.CaptionHeight + SystemInformation.FrameBorderSize.Height)), InterfaceControl.Width + (SystemInformation.FrameBorderSize.Width * 2), InterfaceControl.Height + SystemInformation.CaptionHeight + (SystemInformation.FrameBorderSize.Height * 2), true);
|
||||
}
|
||||
@@ -249,7 +242,8 @@ namespace mRemoteNG.Connection.Protocol
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
public enum Putty_Protocol
|
||||
|
||||
protected enum Putty_Protocol
|
||||
{
|
||||
ssh = 0,
|
||||
telnet = 1,
|
||||
@@ -257,8 +251,8 @@ namespace mRemoteNG.Connection.Protocol
|
||||
raw = 3,
|
||||
serial = 4
|
||||
}
|
||||
|
||||
public enum Putty_SSHVersion
|
||||
|
||||
protected enum Putty_SSHVersion
|
||||
{
|
||||
ssh1 = 1,
|
||||
ssh2 = 2
|
||||
|
||||
Reference in New Issue
Block a user