PageRenderTime 69ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Forms/frmOutputLog.vb

#
Visual Basic | 120 lines | 87 code | 27 blank | 6 comment | 0 complexity | 7d33898453334923d3978cb189656dcf MD5 | raw file
Possible License(s): GPL-2.0
  1. Imports System.IO
  2. Imports System.Text
  3. Public Class frmoutputlog
  4. Public output As String = ""
  5. Public FullViewOverride As Boolean = False
  6. Private Sub frmoutputlog_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7. 'Commented out by AnotherPhil as already done [after search for new movies] and if left causes endless processing...
  8. 'Try
  9. ' ShowLog() 'call the subroutine to actually show the log when the form is created.
  10. 'Catch ex As Exception
  11. ' ExceptionHandler.LogError(ex)
  12. 'End Try
  13. If Pref.MultiMonitoEnabled Then
  14. Me.Bounds = Screen.AllScreens(Form1.CurrentScreen).Bounds
  15. Me.Width = 861
  16. Me.Height = 580
  17. End If
  18. End Sub
  19. Public Sub New(ByVal displaystring As String, Optional ByVal forceoverride As Boolean = False, Optional ByVal FullView As Boolean = False)
  20. InitializeComponent()
  21. Try
  22. If forceoverride = False Then
  23. Me.Close()
  24. End If
  25. output = displaystring
  26. FullViewOverride = fullview
  27. Catch ex As Exception
  28. ExceptionHandler.LogError(ex)
  29. End Try
  30. End Sub
  31. Private Sub btn_savelog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_savelog.Click
  32. Try 'this is the save button, it will save the displayed text (full or brief)
  33. Dim strFileName As String
  34. With SaveFileDialog1
  35. .DefaultExt = "txt"
  36. .Filter = "Text Documents (*.txt)|*.txt|All Files(*.*)|*.*"
  37. .FilterIndex = 1
  38. .OverwritePrompt = True
  39. .Title = "Save Scraper Log Dialogue"
  40. End With
  41. If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  42. Try
  43. strFileName = SaveFileDialog1.FileName
  44. Dim file As StreamWriter
  45. file = New StreamWriter(strFileName, False)
  46. file.WriteLine(Now())
  47. file.WriteLine()
  48. file.Write(TextBox1.Text)
  49. file.WriteLine()
  50. file.Close()
  51. MsgBox(strFileName & " Saved")
  52. Catch ex As Exception
  53. MsgBox("Error" & vbCrLf & vbCrLf & ex.Message.ToString)
  54. End Try
  55. End If
  56. Catch ex As Exception
  57. ExceptionHandler.LogError(ex)
  58. End Try
  59. End Sub
  60. Private Sub TextBox1_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
  61. Try
  62. TextBox1.Select(TextBox1.Text.Length, 0) 'this removes the whole text being selected when the form is created
  63. Catch ex As Exception
  64. ExceptionHandler.LogError(ex)
  65. End Try
  66. End Sub
  67. Private Sub ComboBoxLogViewType_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxLogViewType.SelectedIndexChanged
  68. ShowLog()
  69. End Sub
  70. Private Sub ShowLog()
  71. TextBox1.Text = ""
  72. Pref.logview = ComboBoxLogViewType.SelectedIndex
  73. Dim builder As New StringBuilder
  74. For Each line In output.Split(vbCrLf)
  75. line = Strings.Replace(line, Chr(10), "")
  76. If IsNothing(line) Then Continue For
  77. If line="!!!" Then
  78. builder.AppendLine
  79. ElseIf line.Contains("!!! ") Then
  80. builder.Append(Strings.Right(line, Strings.Len(line) - 4)).AppendLine
  81. ElseIf (Pref.logview=0 OrElse FullViewOverride) Then '0 = Full log view -> Append details
  82. builder.Append(line).AppendLine
  83. End If
  84. Next
  85. TextBox1.Text = builder.ToString
  86. End Sub
  87. Private Sub frmoutputlog_Shown( sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
  88. ComboBoxLogViewType.SelectedIndex = Pref.logview 'set the combobox entry as per the preferences
  89. End Sub
  90. Private Sub frmoutputlog_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  91. If e.KeyCode = Keys.Escape Then Me.Close()
  92. End Sub
  93. End Class