Permalink
Browse files

Add feature MR-351 - Import connections from PuTTY

  • Loading branch information...
1 parent 167344b commit 7b831c6ab848f06e98c9f854ae8d20f74be1e079 @rmcardle rmcardle committed Mar 17, 2013
View
@@ -1,5 +1,6 @@
Added feature MR-345 - Two separate options for confirming closure of Tabs and Connection Panels
Added feature MR-346 - Option to show/hide the description box at the bottom of the Config panel
+ Added feature MR-351 - Import connections from PuTTY
Fixed issue MR-354 - Re-ordering tabs doesn't give good, reliable visual feedback
Fixed issue MR-375 - Changing a connection's icon using the picture button should immediately update Icon field
Fixed issue MR-377 - Several redundant panels can be opened
@@ -464,10 +464,6 @@ Namespace App
Next
End Sub
- Public Shared Sub GetPuttySessions()
- Connection.PuttySession.PuttySessions = Connection.Protocol.PuttyBase.GetSessions()
- End Sub
-
Public Shared Sub CreateLogger()
log4net.Config.XmlConfigurator.Configure()
@@ -1568,11 +1564,13 @@ Namespace App
Exit Sub
End If
- If Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.Connection Then
+ If Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.Connection Or _
+ Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.PuttySession Then
OpenConnection(Windows.treeForm.tvConnections.SelectedNode.Tag, Force)
ElseIf Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.Container Then
For Each tNode As TreeNode In Tree.Node.SelectedNode.Nodes
- If Tree.Node.GetNodeType(tNode) = Tree.Node.Type.Connection Then
+ If Tree.Node.GetNodeType(tNode) = Tree.Node.Type.Connection Or _
+ Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.PuttySession Then
If tNode.Tag IsNot Nothing Then
OpenConnection(tNode.Tag, Force)
End If
@@ -0,0 +1,142 @@
+Imports System.ComponentModel
+Imports Microsoft.Win32
+Imports mRemoteNG.Connection.Protocol
+Imports mRemoteNG.Tree
+Imports mRemoteNG.My
+
+Namespace Config
+ Public Class PuttySessions
+ Private Const PuttySessionsKey As String = "Software\SimonTatham\PuTTY\Sessions"
+
+ Public Shared Sub AddSessionsToTree(ByVal treeView As TreeView)
+ Dim savedSessions() As Connection.Info = LoadSessions()
+ If savedSessions Is Nothing OrElse savedSessions.Length = 0 Then Return
+
+ Dim puttyRootInfo As New Root.PuttySessions.Info()
+ If String.IsNullOrEmpty(My.Settings.PuttySavedSessionsName) Then
+ puttyRootInfo.Name = Language.strPuttySavedSessionsRootName
+ Else
+ puttyRootInfo.Name = My.Settings.PuttySavedSessionsName
+ End If
+ If String.IsNullOrEmpty(My.Settings.PuttySavedSessionsPanel) Then
+ puttyRootInfo.Panel = Language.strGeneral
+ Else
+ puttyRootInfo.Panel = My.Settings.PuttySavedSessionsPanel
+ End If
+
+ Dim puttyRootNode As TreeNode = New TreeNode
+ puttyRootNode.Text = puttyRootInfo.Name
+ puttyRootNode.Tag = puttyRootInfo
+ puttyRootNode.ImageIndex = Images.Enums.TreeImage.PuttySessions
+ puttyRootNode.SelectedImageIndex = Images.Enums.TreeImage.PuttySessions
+
+ puttyRootInfo.TreeNode = puttyRootNode
+
+ treeView.BeginUpdate()
+ treeView.Nodes.Add(puttyRootNode)
+
+ Dim newTreeNode As TreeNode
+ For Each sessionInfo As Connection.PuttySession.Info In savedSessions
+ newTreeNode = Node.AddNode(Node.Type.PuttySession, sessionInfo.Name)
+ If newTreeNode Is Nothing Then Continue For
+
+ sessionInfo.RootPuttySessionsInfo = puttyRootInfo
+ sessionInfo.TreeNode = newTreeNode
+ sessionInfo.Inherit.TurnOffInheritanceCompletely()
+
+ newTreeNode.Tag = sessionInfo
+ newTreeNode.ImageIndex = Images.Enums.TreeImage.ConnectionClosed
+ newTreeNode.SelectedImageIndex = Images.Enums.TreeImage.ConnectionClosed
+
+ puttyRootNode.Nodes.Add(newTreeNode)
+ Next
+
+ puttyRootNode.Expand()
+ treeView.EndUpdate()
+ End Sub
+
+ Protected Shared Function GetSessionNames(Optional ByVal addDefaultSettings As Boolean = False) As String()
+ Dim sessionsKey As RegistryKey = Registry.CurrentUser.OpenSubKey(PuttySessionsKey)
+ If sessionsKey Is Nothing Then Return Nothing
+
+ Dim sessionNames As New List(Of String)
+ If addDefaultSettings Then sessionNames.Add("Default Settings")
+ For Each sessionName As String In sessionsKey.GetSubKeyNames()
+ sessionNames.Add(Web.HttpUtility.UrlDecode(sessionName))
+ Next
+ Return sessionNames.ToArray()
+ End Function
+
+ Protected Shared Function LoadSessions() As Connection.PuttySession.Info()
+ Dim sessionList As New List(Of Connection.PuttySession.Info)
+ Dim sessionInfo As Connection.Info
+ For Each sessionName As String In GetSessionNames()
+ sessionInfo = SessionToConnectionInfo(sessionName)
+ If sessionInfo Is Nothing Then Continue For
+ sessionList.Add(sessionInfo)
+ Next
+ Return sessionList.ToArray()
+ End Function
+
+ Protected Shared Function SessionToConnectionInfo(ByVal sessionName As String) As Connection.PuttySession.Info
+ Dim sessionsKey As RegistryKey = Registry.CurrentUser.OpenSubKey(PuttySessionsKey)
+ If sessionsKey Is Nothing Then Return Nothing
+
+ Dim sessionKey As RegistryKey = sessionsKey.OpenSubKey(sessionName)
+ If sessionKey Is Nothing Then Return Nothing
+
+ Dim sessionInfo As New Connection.PuttySession.Info
+ With sessionInfo
+ .PuttySession = sessionName
+ .Name = sessionName
+ .Hostname = sessionKey.GetValue("HostName")
+ .Username = sessionKey.GetValue("UserName")
+ Dim protocol As String = sessionKey.GetValue("Protocol")
+ Select Case protocol.ToLowerInvariant()
+ Case "raw"
+ .Protocol = Protocols.RAW
+ Case "rlogin"
+ .Protocol = Protocols.Rlogin
+ Case "serial"
+ Return Nothing
+ Case "ssh"
+ Dim sshVersion As Integer = sessionKey.GetValue("SshProt")
+ If sshVersion >= 2 Then
+ .Protocol = Protocols.SSH2
+ Else
+ .Protocol = Protocols.SSH1
+ End If
+ Case "telnet"
+ .Protocol = Protocols.Telnet
+ Case Else
+ Return Nothing
+ End Select
+ .Port = sessionKey.GetValue("PortNumber")
+ End With
+
+ Return sessionInfo
+ End Function
+
+ Public Class SessionList
+ Inherits StringConverter
+
+ Public Shared ReadOnly Property Names() As String()
+ Get
+ Return GetSessionNames(True)
+ End Get
+ End Property
+
+ Public Overloads Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
+ Return New StandardValuesCollection(Names)
+ End Function
+
+ Public Overloads Overrides Function GetStandardValuesExclusive(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
+ Return True
+ End Function
+
+ Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As ITypeDescriptorContext) As Boolean
+ Return True
+ End Function
+ End Class
+ End Class
+End Namespace
@@ -13,7 +13,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameName"), _
LocalizedDescription("strPropertyDescriptionName")> _
- Public Property Name() As String
+ Public Overridable Property Name() As String
Get
Return Me._Name
End Get
@@ -27,7 +27,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameDescription"), _
LocalizedDescription("strPropertyDescriptionDescription")> _
- Public Property Description() As String
+ Public Overridable Property Description() As String
Get
If Me._Inherit.Description And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -54,7 +54,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameIcon"), _
LocalizedDescription("strPropertyDescriptionIcon")> _
- Public Property Icon() As String
+ Public Overridable Property Icon() As String
Get
If Me._Inherit.Icon And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -80,7 +80,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNamePanel"), _
LocalizedDescription("strPropertyDescriptionPanel")> _
- Public Property Panel() As String
+ Public Overridable Property Panel() As String
Get
If Me._Inherit.Panel And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -107,7 +107,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameAddress"), _
LocalizedDescription("strPropertyDescriptionAddress")> _
- Public Property Hostname() As String
+ Public Overridable Property Hostname() As String
Get
Return Me._Hostname.Trim()
End Get
@@ -121,7 +121,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameUsername"), _
LocalizedDescription("strPropertyDescriptionUsername")> _
- Public Property Username() As String
+ Public Overridable Property Username() As String
Get
If Me._Inherit.Username And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -148,7 +148,7 @@ Namespace Connection
LocalizedDisplayName("strPropertyNamePassword"), _
LocalizedDescription("strPropertyDescriptionPassword"), _
PasswordPropertyText(True)> _
- Public Property Password() As String
+ Public Overridable Property Password() As String
Get
If Me._Inherit.Password And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -202,7 +202,7 @@ Namespace Connection
LocalizedDisplayName("strPropertyNameProtocol"), _
LocalizedDescription("strPropertyDescriptionProtocol"), _
TypeConverter(GetType(Tools.Misc.EnumTypeConverter))> _
- Public Property Protocol() As Connection.Protocol.Protocols
+ Public Overridable Property Protocol() As Connection.Protocol.Protocols
Get
If Me._Inherit.Protocol And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -255,7 +255,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNamePort"), _
LocalizedDescription("strPropertyDescriptionPort")> _
- Public Property Port() As Integer
+ Public Overridable Property Port() As Integer
Get
If Me._Inherit.Port And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -281,8 +281,8 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNamePuttySession"), _
LocalizedDescription("strPropertyDescriptionPuttySession"), _
- TypeConverter(GetType(mRemoteNG.Connection.PuttySession))> _
- Public Property PuttySession() As String
+ TypeConverter(GetType(Config.PuttySessions.SessionList))> _
+ Public Overridable Property PuttySession() As String
Get
If Me._Inherit.PuttySession And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -958,7 +958,7 @@ Namespace Connection
LocalizedDisplayName("strPropertyNameExternalToolBefore"), _
LocalizedDescription("strPropertyDescriptionExternalToolBefore"), _
TypeConverter(GetType(Tools.ExternalAppsTypeConverter))> _
- Public Property PreExtApp() As String
+ Public Overridable Property PreExtApp() As String
Get
If Me._Inherit.PreExtApp And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -985,7 +985,7 @@ Namespace Connection
LocalizedDisplayName("strPropertyNameExternalToolAfter"), _
LocalizedDescription("strPropertyDescriptionExternalToolAfter"), _
TypeConverter(GetType(Tools.ExternalAppsTypeConverter))> _
- Public Property PostExtApp() As String
+ Public Overridable Property PostExtApp() As String
Get
If Me._Inherit.PostExtApp And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -1011,7 +1011,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameMACAddress"), _
LocalizedDescription("strPropertyDescriptionMACAddress")> _
- Public Property MacAddress() As String
+ Public Overridable Property MacAddress() As String
Get
If Me._Inherit.MacAddress And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -1037,7 +1037,7 @@ Namespace Connection
Browsable(True), _
LocalizedDisplayName("strPropertyNameUser1"), _
LocalizedDescription("strPropertyDescriptionUser1")> _
- Public Property UserField() As String
+ Public Overridable Property UserField() As String
Get
If Me._Inherit.UserField And Me._Parent IsNot Nothing Then
Dim parCon As Connection.Info = TryCast(Me._Parent, Container.Info).ConnectionInfo
@@ -243,27 +243,6 @@ Namespace Connection
#End Region
#Region "Public Shared Methods"
- Public Shared Function GetSessions() As Array
- Try
- Dim regKey As RegistryKey
- regKey = Registry.CurrentUser.OpenSubKey("Software\SimonTatham\PuTTY\Sessions")
-
- Dim arrKeys() As String
- arrKeys = regKey.GetSubKeyNames()
- Array.Resize(arrKeys, arrKeys.Length + 1)
- arrKeys(arrKeys.Length - 1) = "Default Settings"
-
- For i As Integer = 0 To arrKeys.Length - 1
- arrKeys(i) = System.Web.HttpUtility.UrlDecode(arrKeys(i))
- Next
-
- Return arrKeys
- Catch ex As Exception
- App.Runtime.MessageCollector.AddMessage(Messages.MessageClass.WarningMsg, My.Language.strPuttyGetSessionsFailed & vbNewLine & ex.Message, True)
- Return Nothing
- End Try
- End Function
-
Public Shared Function IsFilePuttyNg(file As String) As Boolean
Dim isPuttyNg As Boolean
Try
@@ -282,8 +261,6 @@ Namespace Connection
p = Process.Start(pSI)
p.WaitForExit()
-
- mRemoteNG.Connection.PuttySession.PuttySessions = GetSessions()
Catch ex As Exception
MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, My.Language.strPuttyStartFailed & vbNewLine & ex.Message, True)
End Try
@@ -1,21 +0,0 @@
-Imports System.ComponentModel
-
-Namespace Connection
- Public Class PuttySession
- Inherits StringConverter
-
- Public Shared PuttySessions As String() = New String() {}
-
- Public Overloads Overrides Function GetStandardValues(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.ComponentModel.TypeConverter.StandardValuesCollection
- Return New StandardValuesCollection(PuttySessions)
- End Function
-
- Public Overloads Overrides Function GetStandardValuesExclusive(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
- Return True
- End Function
-
- Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As ITypeDescriptorContext) As Boolean
- Return True
- End Function
- End Class
-End Namespace
Oops, something went wrong.

0 comments on commit 7b831c6

Please sign in to comment.