From 13ba0b2802624115453cf1c734e56fee72267c50 Mon Sep 17 00:00:00 2001 From: Riley McArdle Date: Mon, 6 Jun 2011 17:49:55 -0500 Subject: [PATCH] Code cleanup. --- mRemoteV1/App/App.Announcement.vb | 53 +++++++++++++++--- mRemoteV1/App/App.Runtime.vb | 54 ++++++++----------- mRemoteV1/Config/Config.Settings.Load.vb | 12 ++--- mRemoteV1/Config/Config.Settings.Save.vb | 10 ++-- .../Connection/Connection.Protocol.IntApp.vb | 2 +- mRemoteV1/Forms/frmMain.Designer.vb | 18 +++---- mRemoteV1/Forms/frmMain.vb | 42 +++++++-------- mRemoteV1/My Project/Resources.Designer.vb | 9 ++++ mRemoteV1/My Project/Resources.resx | 5 +- mRemoteV1/Tools/Tools.ExternalApp.vb | 2 +- mRemoteV1/UI/UI.Window.Connection.vb | 4 +- mRemoteV1/UI/UI.Window.ExternalApps.vb | 14 ++--- mRemoteV1/UI/UI.Window.Tree.vb | 4 +- 13 files changed, 132 insertions(+), 97 deletions(-) diff --git a/mRemoteV1/App/App.Announcement.vb b/mRemoteV1/App/App.Announcement.vb index 396421a4..d6df9750 100644 --- a/mRemoteV1/App/App.Announcement.vb +++ b/mRemoteV1/App/App.Announcement.vb @@ -3,18 +3,23 @@ Imports mRemoteNG.App.Runtime Namespace App Public Class Announcement -#Region "Private Properties" - Private wCl As WebClient - Private wPr As WebProxy + Implements IDisposable + +#Region "Private Variables" + Private webClient As WebClient + Private webProxy As WebProxy #End Region +#Region "Public Properties" Private _currentAnnouncementInfo As Info Public ReadOnly Property CurrentAnnouncementInfo() As Info Get Return _currentAnnouncementInfo End Get End Property +#End Region +#Region "Public Methods" Public Function IsAnnouncementAvailable() As Boolean Try Dim aI As Info = GetAnnouncementInfo() @@ -80,7 +85,7 @@ Namespace App Dim strTemp As String Try - strTemp = wCl.DownloadString(App.Info.General.URLAnnouncement) + strTemp = webClient.DownloadString(App.Info.General.URLAnnouncement) Catch ex As Exception strTemp = "" End Try @@ -93,21 +98,22 @@ Namespace App End Function Private Sub CreateWebClient() - wCl = New WebClient() + webClient = New WebClient() If My.Settings.UpdateUseProxy Then - wPr = New WebProxy(My.Settings.UpdateProxyAddress, My.Settings.UpdateProxyPort) + webProxy = New WebProxy(My.Settings.UpdateProxyAddress, My.Settings.UpdateProxyPort) If My.Settings.UpdateProxyUseAuthentication Then Dim cred As ICredentials cred = New NetworkCredential(My.Settings.UpdateProxyAuthUser, Security.Crypt.Decrypt(My.Settings.UpdateProxyAuthPass, App.Info.General.EncryptionKey)) - wPr.Credentials = cred + webProxy.Credentials = cred End If - wCl.Proxy = wPr + webClient.Proxy = webProxy End If End Sub +#End Region Public Class Info Private _Name As String @@ -140,5 +146,36 @@ Namespace App End Set End Property End Class + +#Region "IDisposable Support" + Private disposedValue As Boolean ' To detect redundant calls + + ' IDisposable + Protected Overridable Sub Dispose(disposing As Boolean) + If Not Me.disposedValue Then + If disposing Then + If webClient IsNot Nothing Then webClient.Dispose() + End If + + ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below. + ' TODO: set large fields to null. + End If + Me.disposedValue = True + End Sub + + ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources. + 'Protected Overrides Sub Finalize() + ' ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + ' Dispose(False) + ' MyBase.Finalize() + 'End Sub + + ' This code added by Visual Basic to correctly implement the disposable pattern. + Public Sub Dispose() Implements IDisposable.Dispose + ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(True) + GC.SuppressFinalize(Me) + End Sub +#End Region End Class End Namespace \ No newline at end of file diff --git a/mRemoteV1/App/App.Runtime.vb b/mRemoteV1/App/App.Runtime.vb index c1a099b0..1d71b329 100644 --- a/mRemoteV1/App/App.Runtime.vb +++ b/mRemoteV1/App/App.Runtime.vb @@ -19,26 +19,6 @@ Namespace App End Sub #Region "Public Properties" - 'Private Shared _settingsLoad As Config.Settings.Load - 'Public Shared Property SettingsLoad() As Load - ' Get - ' Return _settingsLoad - ' End Get - ' Set(ByVal value As Load) - ' _settingsLoad = value - ' End Set - 'End Property - - 'Private Shared _settingsSave As Config.Settings.Save - 'Public Shared Property SettingsSave() As Save - ' Get - ' Return _settingsSave - ' End Get - ' Set(ByVal value As Save) - ' _settingsSave = value - ' End Set - 'End Property - Private Shared _connectionList As Connection.List Public Shared Property ConnectionList() As List Get @@ -1512,7 +1492,7 @@ Namespace App End If If newConnectionInfo.PreExtApp <> "" Then - Dim extA As Tools.ExternalApp = App.Runtime.GetExtAppByName(newConnectionInfo.PreExtApp) + Dim extA As Tools.ExternalTool = App.Runtime.GetExtAppByName(newConnectionInfo.PreExtApp) If extA IsNot Nothing Then extA.Start(newConnectionInfo) End If @@ -1621,7 +1601,7 @@ Namespace App If newConnectionInfo.Protocol <> Connection.Protocol.Protocols.IntApp Then Tree.Node.SetNodeImage(newConnectionInfo.TreeNode, Images.Enums.TreeImage.ConnectionOpen) Else - Dim extApp As Tools.ExternalApp = GetExtAppByName(newConnectionInfo.ExtApp) + Dim extApp As Tools.ExternalTool = GetExtAppByName(newConnectionInfo.ExtApp) If extApp IsNot Nothing Then If extApp.TryIntegrate Then If newConnectionInfo.TreeNode IsNot Nothing Then @@ -1689,7 +1669,7 @@ Namespace App End If If Prot.InterfaceControl.Info.PostExtApp <> "" Then - Dim extA As Tools.ExternalApp = App.Runtime.GetExtAppByName(Prot.InterfaceControl.Info.PostExtApp) + Dim extA As Tools.ExternalTool = App.Runtime.GetExtAppByName(Prot.InterfaceControl.Info.PostExtApp) If extA IsNot Nothing Then extA.Start(Prot.InterfaceControl.Info) End If @@ -1730,7 +1710,7 @@ Namespace App Dim i As Integer = 0 - For Each extA As Tools.ExternalApp In ExternalTools + For Each extA As Tools.ExternalTool In ExternalTools Tools.ExternalAppsTypeConverter.ExternalApps(i) = extA.DisplayName i += 1 @@ -1739,8 +1719,8 @@ Namespace App Tools.ExternalAppsTypeConverter.ExternalApps(i) = "" End Sub - Public Shared Function GetExtAppByName(ByVal Name As String) As Tools.ExternalApp - For Each extA As Tools.ExternalApp In ExternalTools + Public Shared Function GetExtAppByName(ByVal Name As String) As Tools.ExternalTool + For Each extA As Tools.ExternalTool In ExternalTools If extA.DisplayName = Name Then Return extA End If @@ -1794,19 +1774,29 @@ Namespace App End Sub Public Shared Function SaveReport() As Boolean + Dim streamReader As StreamReader = Nothing + Dim streamWriter As StreamWriter = Nothing Try - Dim sRd As New StreamReader(My.Application.Info.DirectoryPath & "\Report.log") - Dim Text As String = sRd.ReadToEnd - sRd.Close() + streamReader = New StreamReader(My.Application.Info.DirectoryPath & "\Report.log") + Dim text As String = streamReader.ReadToEnd + streamReader.Close() - Dim sWr As New StreamWriter(App.Info.General.ReportingFilePath, True) - sWr.Write(Text) - sWr.Close() + streamWriter = New StreamWriter(App.Info.General.ReportingFilePath, True) + streamWriter.Write(text) Return True Catch ex As Exception MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, My.Resources.strLogWriteToFileFinalLocationFailed & vbNewLine & ex.Message, True) Return False + Finally + If streamReader IsNot Nothing Then + streamReader.Close() + streamReader.Dispose() + End If + If streamWriter IsNot Nothing Then + streamWriter.Close() + streamWriter.Dispose() + End If End Try End Function diff --git a/mRemoteV1/Config/Config.Settings.Load.vb b/mRemoteV1/Config/Config.Settings.Load.vb index f82d3bee..5fab6623 100644 --- a/mRemoteV1/Config/Config.Settings.Load.vb +++ b/mRemoteV1/Config/Config.Settings.Load.vb @@ -117,8 +117,8 @@ Namespace Config With MainForm ToolStripPanelFromString("top").Join(.tsQuickConnect, New Point(300, 0)) .tsQuickConnect.Visible = True - ToolStripPanelFromString("bottom").Join(.tsExtAppsToolbar, New Point(3, 0)) - .tsExtAppsToolbar.Visible = False + ToolStripPanelFromString("bottom").Join(.tsExternalTools, New Point(3, 0)) + .tsExternalTools.Visible = False End With End Sub @@ -143,8 +143,8 @@ Namespace Config Private Sub AddDynamicPanels() With MainForm - ToolStripPanelFromString(My.Settings.ExtAppsTBParentDock).Join(.tsExtAppsToolbar, My.Settings.ExtAppsTBLocation) - .tsExtAppsToolbar.Visible = My.Settings.ExtAppsTBVisible + ToolStripPanelFromString(My.Settings.ExtAppsTBParentDock).Join(.tsExternalTools, My.Settings.ExtAppsTBLocation) + .tsExternalTools.Visible = My.Settings.ExtAppsTBVisible End With End Sub @@ -210,7 +210,7 @@ Namespace Config End If For Each xEl As XmlElement In xDom.DocumentElement.ChildNodes - Dim extA As New Tools.ExternalApp + Dim extA As New Tools.ExternalTool extA.DisplayName = xEl.Attributes("DisplayName").Value extA.FileName = xEl.Attributes("FileName").Value extA.Arguments = xEl.Attributes("Arguments").Value @@ -230,7 +230,7 @@ Namespace Config xDom = Nothing - frmMain.AddExtAppsToToolbar() + frmMain.AddExternalToolsToToolBar() End Sub #End Region diff --git a/mRemoteV1/Config/Config.Settings.Save.vb b/mRemoteV1/Config/Config.Settings.Save.vb index 1252025e..0d3a5bfd 100644 --- a/mRemoteV1/Config/Config.Settings.Save.vb +++ b/mRemoteV1/Config/Config.Settings.Save.vb @@ -32,11 +32,11 @@ Namespace Config My.Settings.ResetToolbars = False My.Settings.NoReconnect = False - My.Settings.ExtAppsTBLocation = .tsExtAppsToolbar.Location - If .tsExtAppsToolbar.Parent IsNot Nothing Then - My.Settings.ExtAppsTBParentDock = .tsExtAppsToolbar.Parent.Dock.ToString + My.Settings.ExtAppsTBLocation = .tsExternalTools.Location + If .tsExternalTools.Parent IsNot Nothing Then + My.Settings.ExtAppsTBParentDock = .tsExternalTools.Parent.Dock.ToString End If - My.Settings.ExtAppsTBVisible = .tsExtAppsToolbar.Visible + My.Settings.ExtAppsTBVisible = .tsExternalTools.Visible My.Settings.ExtAppsTBShowText = .cMenToolbarShowText.Checked My.Settings.QuickyTBLocation = .tsQuickConnect.Location @@ -82,7 +82,7 @@ Namespace Config xmlTextWriter.WriteStartDocument() xmlTextWriter.WriteStartElement("Apps") - For Each extA As Tools.ExternalApp In ExternalTools + For Each extA As Tools.ExternalTool In ExternalTools xmlTextWriter.WriteStartElement("App") xmlTextWriter.WriteAttributeString("DisplayName", "", extA.DisplayName) xmlTextWriter.WriteAttributeString("FileName", "", extA.FileName) diff --git a/mRemoteV1/Connection/Connection.Protocol.IntApp.vb b/mRemoteV1/Connection/Connection.Protocol.IntApp.vb index f8c91aca..36ae27f7 100644 --- a/mRemoteV1/Connection/Connection.Protocol.IntApp.vb +++ b/mRemoteV1/Connection/Connection.Protocol.IntApp.vb @@ -10,7 +10,7 @@ Namespace Connection #Region "Private Properties" Private IntAppProcessStartInfo As New ProcessStartInfo() Private Arguments As String - Private ExtApp As Tools.ExternalApp + Private ExtApp As Tools.ExternalTool #End Region #Region "Public Properties" diff --git a/mRemoteV1/Forms/frmMain.Designer.vb b/mRemoteV1/Forms/frmMain.Designer.vb index ea45ff37..7ebb5f1c 100644 --- a/mRemoteV1/Forms/frmMain.Designer.vb +++ b/mRemoteV1/Forms/frmMain.Designer.vb @@ -107,7 +107,7 @@ Partial Class frmMain Me.lblQuickConnect = New System.Windows.Forms.ToolStripLabel Me.cmbQuickConnect = New System.Windows.Forms.ToolStripComboBox Me.tsContainer = New System.Windows.Forms.ToolStripContainer - Me.tsExtAppsToolbar = New System.Windows.Forms.ToolStrip + Me.tsExternalTools = New System.Windows.Forms.ToolStrip Me.cMenExtAppsToolbar = New System.Windows.Forms.ContextMenuStrip(Me.components) Me.cMenToolbarShowText = New System.Windows.Forms.ToolStripMenuItem Me.tsQuickConnect = New System.Windows.Forms.ToolStrip @@ -678,18 +678,18 @@ Partial Class frmMain ' Me.tsContainer.TopToolStripPanel.Controls.Add(Me.msMain) Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsQuickConnect) - Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsExtAppsToolbar) + Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsExternalTools) Me.tsContainer.TopToolStripPanel.Controls.Add(Me.ToolStrip1) Me.tsContainer.TopToolStripPanel.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional ' 'tsExtAppsToolbar ' - Me.tsExtAppsToolbar.ContextMenuStrip = Me.cMenExtAppsToolbar - Me.tsExtAppsToolbar.Dock = System.Windows.Forms.DockStyle.None - Me.tsExtAppsToolbar.Location = New System.Drawing.Point(39, 49) - Me.tsExtAppsToolbar.Name = "tsExtAppsToolbar" - Me.tsExtAppsToolbar.Size = New System.Drawing.Size(111, 25) - Me.tsExtAppsToolbar.TabIndex = 17 + Me.tsExternalTools.ContextMenuStrip = Me.cMenExtAppsToolbar + Me.tsExternalTools.Dock = System.Windows.Forms.DockStyle.None + Me.tsExternalTools.Location = New System.Drawing.Point(39, 49) + Me.tsExternalTools.Name = "tsExtAppsToolbar" + Me.tsExternalTools.Size = New System.Drawing.Size(111, 25) + Me.tsExternalTools.TabIndex = 17 ' 'cMenExtAppsToolbar ' @@ -860,7 +860,7 @@ Partial Class frmMain Friend WithEvents tmrShowUpdate As System.Windows.Forms.Timer Friend WithEvents mMenToolsExternalApps As System.Windows.Forms.ToolStripMenuItem Friend WithEvents tmrAutoSave As System.Windows.Forms.Timer - Friend WithEvents tsExtAppsToolbar As System.Windows.Forms.ToolStrip + Friend WithEvents tsExternalTools As System.Windows.Forms.ToolStrip Friend WithEvents mMenViewExtAppsToolbar As System.Windows.Forms.ToolStripMenuItem Friend WithEvents cMenExtAppsToolbar As System.Windows.Forms.ContextMenuStrip Friend WithEvents cMenToolbarShowText As System.Windows.Forms.ToolStripMenuItem diff --git a/mRemoteV1/Forms/frmMain.vb b/mRemoteV1/Forms/frmMain.vb index bc85952b..d28ba104 100644 --- a/mRemoteV1/Forms/frmMain.vb +++ b/mRemoteV1/Forms/frmMain.vb @@ -207,40 +207,36 @@ Public Class frmMain SwitchToolBarText(Not cMenToolbarShowText.Checked) End Sub - Public Sub AddExtAppsToToolbar() + Public Sub AddExternalToolsToToolBar() Try - 'clean up - tsExtAppsToolbar.Items.Clear() + For Each item As ToolStripItem In tsExternalTools.Items + item.Dispose() + Next + tsExternalTools.Items.Clear() - 'add ext apps - For Each extA As Tools.ExternalApp In ExternalTools - Dim nItem As New ToolStripButton - nItem.Text = extA.DisplayName - nItem.Image = extA.Image + Dim button As ToolStripButton + For Each tool As Tools.ExternalTool In ExternalTools + button = tsExternalTools.Items.Add(tool.DisplayName, tool.Image, AddressOf tsExtAppEntry_Click) If cMenToolbarShowText.Checked = True Then - nItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText + button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText Else - If nItem.Image IsNot Nothing Then - nItem.DisplayStyle = ToolStripItemDisplayStyle.Image + If button.Image IsNot Nothing Then + button.DisplayStyle = ToolStripItemDisplayStyle.Image Else - nItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText + button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText End If End If - nItem.Tag = extA - - AddHandler nItem.Click, AddressOf tsExtAppEntry_Click - - tsExtAppsToolbar.Items.Add(nItem) + button.Tag = tool Next Catch ex As Exception - MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, "AddExtAppsToToolbar failed (frmMain)" & vbNewLine & ex.Message, True) + MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, String.Format(My.Resources.strErrorAddExternalToolsToToolBarFailed, ex.Message), True) End Try End Sub Private Sub tsExtAppEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) - Dim extA As Tools.ExternalApp = sender.Tag + Dim extA As Tools.ExternalTool = sender.Tag If Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.Connection Then extA.Start(Tree.Node.SelectedNode.Tag) @@ -250,7 +246,7 @@ Public Class frmMain End Sub Public Sub SwitchToolBarText(ByVal show As Boolean) - For Each tItem As ToolStripButton In tsExtAppsToolbar.Items + For Each tItem As ToolStripButton In tsExternalTools.Items If show = True Then tItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText Else @@ -373,7 +369,7 @@ Public Class frmMain Me.mMenViewSessions.Checked = Not Windows.sessionsForm.IsHidden Me.mMenViewScreenshotManager.Checked = Not Windows.screenshotForm.IsHidden - Me.mMenViewExtAppsToolbar.Checked = tsExtAppsToolbar.Visible + Me.mMenViewExtAppsToolbar.Checked = tsExternalTools.Visible Me.mMenViewQuickConnectToolbar.Checked = tsQuickConnect.Visible Me.mMenViewConnectionPanels.DropDownItems.Clear() @@ -479,10 +475,10 @@ Public Class frmMain Private Sub mMenViewExtAppsToolbar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mMenViewExtAppsToolbar.Click If mMenViewExtAppsToolbar.Checked = False Then - tsExtAppsToolbar.Visible = True + tsExternalTools.Visible = True mMenViewExtAppsToolbar.Checked = True Else - tsExtAppsToolbar.Visible = False + tsExternalTools.Visible = False mMenViewExtAppsToolbar.Checked = False End If End Sub diff --git a/mRemoteV1/My Project/Resources.Designer.vb b/mRemoteV1/My Project/Resources.Designer.vb index af512f5a..95f0ace9 100644 --- a/mRemoteV1/My Project/Resources.Designer.vb +++ b/mRemoteV1/My Project/Resources.Designer.vb @@ -2150,6 +2150,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to AddExternalToolsToToolBar (frmMain) failed. {0}. + ''' + Friend ReadOnly Property strErrorAddExternalToolsToToolBarFailed() As String + Get + Return ResourceManager.GetString("strErrorAddExternalToolsToToolBarFailed", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to AddFolder (UI.Window.Tree) failed. {0}. ''' diff --git a/mRemoteV1/My Project/Resources.resx b/mRemoteV1/My Project/Resources.resx index 33c8d09c..73c45394 100644 --- a/mRemoteV1/My Project/Resources.resx +++ b/mRemoteV1/My Project/Resources.resx @@ -1,4 +1,4 @@ - +