Advertisement
PiToLoKo

mp3gain helper

Nov 25th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 21.21 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <SnippetTypes>
  6.         <SnippetType>Module</SnippetType>
  7.       </SnippetTypes>
  8.       <Title>
  9.          [mp3gain] Helper
  10.       </Title>
  11.       <Author>Elektro H@cker</Author>
  12.       <Description>
  13.          Ejemplos de uso de la aplicación mp3gain.
  14.       </Description>
  15.       <HelpUrl>
  16.       </HelpUrl>
  17.       <Shortcut>
  18.       </Shortcut>
  19.     </Header>
  20.     <Snippet>
  21.       <Declarations>
  22.         <Literal Editable="true">
  23.           <ID>aaaaaaaaa</ID>
  24.           <ToolTip>sfsdf</ToolTip>
  25.           <Default>
  26.           </Default>
  27.           <Function>sdfsdf</Function>
  28.         </Literal>
  29.       </Declarations>
  30.       <Code Language="vb"><![CDATA[
  31.  
  32. ' [ mp3gain Helper ]
  33. '
  34. ' // By Elektro H@cker
  35. '
  36. ' Instructions:
  37. ' 1. Add the "mp3gain.exe" into the project.
  38.  
  39. #Region " mp3gain Helper "
  40.  
  41. #Region " Usage Examples "
  42.  
  43. ' Public Class Form1
  44. '
  45. '     Private WithEvents _mp3gain As New mp3gain _
  46. '             With {.mp3gain_location = "C:\windows\system32\mp3gain.exe",
  47. '                   .CheckFileExist = True}
  48. '
  49. '     Private Sub Test() Handles MyBase.Shown
  50. '
  51. '         ' Checks if mp3gain executable is avaliable.
  52. '         MsgBox(_mp3gain.Is_Avaliable())
  53. '
  54. '         ' Checks if file contains APEv2 mp3gain tag
  55. '         MsgBox(_mp3gain.File_Has_MP3Gain_Tag("C:\File.mp3"))
  56. '
  57. '         ' Set the global volume Gain of file to "89" db (In a scale of "0-100"),
  58. '         ' and preserve the datetime of file.
  59. '         _mp3gain.Set_Gain("C:\File.mp3", 89, True)
  60. '
  61. '         ' Apply a volume change of +5 db,
  62. '         ' in the curent global volume gain of file.
  63. '         _mp3gain.Apply_Gain("C:\File.mp3", +5)
  64. '
  65. '         ' Apply a volume change of -5 db,
  66. '         ' in the curent global volume gain of file.
  67. '         _mp3gain.Apply_Gain("C:\File.mp3", -5)
  68. '
  69. '         ' Apply a volume change of +10 db,
  70. '         ' in the curent volume gain of the Left channel of an Stereo file.
  71. '         _mp3gain.Apply_Channel_Gain("C:\File.mp3", mp3gain.Channel.Left, +10)
  72. '
  73. '         ' Apply a volume change of -10 db,
  74. '         ' in the curent volume gain of the Right channel of an Stereo file.
  75. '         _mp3gain.Apply_Channel_Gain("C:\File.mp3", mp3gain.Channel.Right, -10)
  76. '
  77. '         ' Undos all volume gain changes made in file.
  78. '         _mp3gain.Undo_Gain("C:\File.mp3")
  79. '
  80. '     End Sub
  81. '
  82. '     ' mp3gain [Started]
  83. '     Private Sub mp3gain_Started(ByVal sender As Process, ByVal e As mp3gain.StartedEventArgs) _
  84. '     Handles _mp3gain.Started
  85. '
  86. '         ProgressBar1.Value = ProgressBar1.Minimum
  87. '
  88. '         Dim sb As New System.Text.StringBuilder
  89. '
  90. '         sb.AppendLine(String.Format("Started an ""{0}"" operation", e.Operation.ToString))
  91. '         sb.AppendLine(String.Format("Input file is: ""{0}""", e.File))
  92. '         sb.AppendLine(String.Format("mp3gain process PID is: ""{0}""", CStr(sender.Id)))
  93. '
  94. '         MessageBox.Show(sb.ToString, "mp3gain", MessageBoxButtons.OK, MessageBoxIcon.Information)
  95. '
  96. '     End Sub
  97. '
  98. '     ' mp3gain [Exited]
  99. '     Private Sub mp3gain_Exited(ByVal sender As Process, ByVal e As mp3gain.ExitedEventArgs) _
  100. '     Handles _mp3gain.Exited
  101. '
  102. '         Dim sb As New System.Text.StringBuilder
  103. '
  104. '         If e.Operation <> mp3gain.Operation.Check_Tag Then
  105. '
  106. '             sb.AppendLine(String.Format("Finished an ""{0}"" operation", e.Operation.ToString))
  107. '             sb.AppendLine(String.Format("Input file is: ""{0}""", e.File))
  108. '             sb.AppendLine(String.Format("mp3gain process PID is: {0}", CStr(sender.Id)))
  109. '
  110. '             If Not String.IsNullOrEmpty(e.InfoMessage) Then
  111. '                 sb.AppendLine(String.Format("Operation Information: {0}", e.InfoMessage))
  112. '             End If
  113. '
  114. '             If Not String.IsNullOrEmpty(e.ErrorMessage) Then
  115. '                 sb.AppendLine(String.Format("Error Information: {0}", e.ErrorMessage))
  116. '             End If
  117. '
  118. '             If e.db <> 0 Then
  119. '                 sb.AppendLine(String.Format("Volume gain change: {0}", CStr(e.db)))
  120. '             End If
  121. '
  122. '             MessageBox.Show(sb.ToString, "mp3gain", MessageBoxButtons.OK, MessageBoxIcon.Information)
  123. '
  124. '         End If
  125. '
  126. '     End Sub
  127. '
  128. '     ' mp3gain [Progress]
  129. '     Sub mp3gain_Progress(sender As Process, e As mp3gain.ProgressEventArgs) _
  130. '     Handles _mp3gain.Progress
  131. '
  132. '         ProgressBar1.Value = e.Percent
  133. '
  134. '     End Sub
  135. '
  136. ' End Class
  137.  
  138. #End Region
  139.  
  140. Public Class mp3gain : Implements IDisposable
  141.  
  142. #Region " CommandLine parametter legend "
  143.  
  144.     ' /c   - Ignore clipping warning when applying gain.
  145.     ' /d   - Set global gain.
  146.     ' /e   - Skip Album analysis, even if multiple files listed.
  147.     ' /g   - apply gain
  148.     ' /p   - Preserve original file timestamp.
  149.     ' /r   - apply Track gain automatically (all files set to equal loudness)
  150.     ' /t   - Writes modified data to temp file, then deletes original instead of modifying bytes in original file.
  151.     ' /u   - Undo changes made (based on stored APEv2 mp3gain tag info).
  152.     ' /s c - Check stored APEv2 mp3gain tag info.
  153.  
  154. #End Region
  155.  
  156. #Region " Variables, Properties, Enumerations "
  157.  
  158.     ''' <summary>
  159.     ''' Gets or sets the mp3gain.exe executable path.
  160.     ''' </summary>
  161.     Public Property mp3gain_location As String = ".\mp3gain.exe"
  162.  
  163.     ''' <summary>
  164.     ''' Indicates if should check that the file exist before realize an operation.
  165.     ''' If True, an exception would be launched if file does not exist.
  166.     ''' </summary>
  167.     Public Property CheckFileExist As Boolean = False
  168.  
  169.     ''' <summary>
  170.     ''' Sets a Flag to indicate if file has APEv2 mp3gain tag or not.
  171.     ''' </summary>
  172.     Private HasTag As Boolean = False
  173.  
  174.     ''' <summary>
  175.     ''' Stores the StandardOutput.
  176.     ''' </summary>
  177.     Private Output As String() = Nothing
  178.  
  179.     ''' <summary>
  180.     ''' Stores an information message of the realized operation (if any).
  181.     ''' </summary>
  182.     Private InfoMessage As String = String.Empty
  183.  
  184.     ''' <summary>
  185.     ''' Stores an error message of the realized operation (if any).
  186.     ''' </summary>
  187.     Private ErrorMessage As String = String.Empty
  188.  
  189.     ''' <summary>
  190.     ''' Stores the volume gain level change applied to file (if any).
  191.     ''' </summary>
  192.     Private db As Integer = 0
  193.  
  194.     ''' <summary>
  195.     ''' Gets some information about the file.
  196.     ''' </summary>
  197.     Private db_RegEx As New System.Text.RegularExpressions.Regex("Applying.+change of (.*) to",
  198.                             System.Text.RegularExpressions.RegexOptions.None)
  199.  
  200.     ''' <summary>
  201.     ''' Process to realize an operation,
  202.     ''' for files that already contains APEv2 mp3gain tag.
  203.     ''' Also is used to realize a single TagCheck operation.
  204.     ''' </summary>
  205.     Private Process_For_Tag As Process =
  206.         New Process With {.StartInfo =
  207.             New ProcessStartInfo With {
  208.                 .CreateNoWindow = True,
  209.                 .UseShellExecute = False,
  210.                 .RedirectStandardError = False,
  211.                 .RedirectStandardOutput = True
  212.            }
  213.         }
  214.  
  215.     ''' <summary>
  216.     ''' Process to realize an operation,
  217.     ''' for files that does not contains mp3gain Tag.
  218.     ''' </summary>
  219.     Private Process_For_NonTag As Process =
  220.         New Process With {.StartInfo =
  221.             New ProcessStartInfo With {
  222.                 .CreateNoWindow = True,
  223.                 .UseShellExecute = False,
  224.                 .RedirectStandardError = True,
  225.                 .RedirectStandardOutput = True
  226.            }
  227.         }
  228.  
  229.     ''' <summary>
  230.     ''' Stores the StartedEventArgs Arguments.
  231.     ''' </summary>
  232.     Private StartedArgs As New StartedEventArgs
  233.  
  234.     ''' <summary>
  235.     ''' Stores the ExitedEventArgs Arguments.
  236.     ''' </summary>
  237.     Private ExitedArgs As New ExitedEventArgs
  238.  
  239.     ''' <summary>
  240.     ''' Stores the ProgressEventArgs Arguments.
  241.     ''' </summary>
  242.     Private ProgressArgs As New ProgressEventArgs
  243.  
  244.     ''' <summary>
  245.     ''' File Stereo Channel.
  246.     ''' </summary>
  247.     Public Enum Channel As Short
  248.         Left = 0  ' /l 0
  249.         Right = 1 ' /l 1
  250.     End Enum
  251.  
  252.     ''' <summary>
  253.     ''' MP3Gain Type Of Operation.
  254.     ''' </summary>
  255.     Public Enum Operation
  256.         Check_Tag = 0
  257.         Apply_Gain = 1
  258.         Apply_Channel_Gain = 2
  259.         Set_Gain = 3
  260.         Undo_Gain = 4
  261.     End Enum
  262.  
  263. #End Region
  264.  
  265. #Region " Events "
  266.  
  267.     ''' <summary>
  268.     ''' Event raised when the process has started.
  269.     ''' </summary>
  270.     Public Event Started As EventHandler(Of StartedEventArgs)
  271.     Public Class StartedEventArgs : Inherits EventArgs
  272.         ''' <summary>
  273.         ''' Gets the file that was passed as argument to the process.
  274.         ''' </summary>
  275.         Public Property File As String
  276.         ''' <summary>
  277.         ''' Gets the type of operation to realize.
  278.         ''' </summary>
  279.         Public Property Operation As Operation
  280.     End Class
  281.  
  282.     ''' <summary>
  283.     ''' Event raised when the process has exited.
  284.     ''' </summary>
  285.     Public Event Exited As EventHandler(Of ExitedEventArgs)
  286.     Public Class ExitedEventArgs : Inherits EventArgs
  287.         ''' <summary>
  288.         ''' Gets the file that was passed as argument to the process.
  289.         ''' </summary>
  290.         Public Property File As String
  291.         ''' <summary>
  292.         ''' Gets the type of operation to realize.
  293.         ''' </summary>
  294.         Public Property Operation As Operation
  295.         ''' <summary>
  296.         ''' Gets the information message of the realized operation (if any).
  297.         ''' </summary>
  298.         Public Property InfoMessage As String
  299.         ''' <summary>
  300.         ''' Gets the error message of the realized operation (if any).
  301.         ''' </summary>
  302.         Public Property ErrorMessage As String
  303.         ''' <summary>
  304.         ''' Gets the volume gain level change applied to file (if any).
  305.         ''' </summary>
  306.         Public Property db As Integer
  307.     End Class
  308.  
  309.     ''' <summary>
  310.     ''' Event raised when the process progress changes.
  311.     ''' </summary>
  312.     Public Event Progress As EventHandler(Of ProgressEventArgs)
  313.     Public Class ProgressEventArgs : Inherits EventArgs
  314.         ''' <summary>
  315.         ''' Gets the process operation percent done.
  316.         ''' </summary>
  317.         Public Property Percent As Integer
  318.     End Class
  319.  
  320. #End Region
  321.  
  322. #Region " MP3Gain Procedures "
  323.  
  324.     ''' <summary>
  325.     ''' Checks if mp3gain.exe process is avaliable.
  326.     ''' </summary>
  327.     Public Function Is_Avaliable() As Boolean
  328.         Return IO.File.Exists(Me.mp3gain_location)
  329.     End Function
  330.  
  331.     ''' <summary>
  332.     ''' Checks if APEv2 mp3gain tag exists in file.
  333.     ''' </summary>
  334.     Public Function File_Has_MP3Gain_Tag(ByVal MP3_File As String) As Boolean
  335.  
  336.         DisposedCheck()
  337.        
  338.         Run_MP3Gain(MP3_File,
  339.                     Operation.Check_Tag,
  340.                     String.Format("/s c ""{0}""", MP3_File),
  341.                     True)
  342.  
  343.         Return HasTag
  344.  
  345.     End Function
  346.  
  347.     ''' <summary>
  348.     ''' Set the global volume gain of file.
  349.     ''' </summary>
  350.     Public Sub Set_Gain(ByVal MP3_File As String,
  351.                         ByVal Gain As Integer,
  352.                         Optional ByVal Preserve_Datestamp As Boolean = True)
  353.  
  354.         DisposedCheck()
  355.        
  356.         File_Has_MP3Gain_Tag(MP3_File)
  357.  
  358.         Run_MP3Gain(MP3_File,
  359.                     Operation.Set_Gain,
  360.                     String.Format("/c /e /r /t {1} /d {2} ""{0}""",
  361.                                   MP3_File,
  362.                                   If(Preserve_Datestamp, "/p", ""),
  363.                                   If(Gain < 0, Gain + 89.0, Gain - 89.0)),
  364.                     False)
  365.  
  366.     End Sub
  367.  
  368.     ''' <summary>
  369.     ''' Apply a volume gain change to file.
  370.     ''' </summary>
  371.     Public Sub Apply_Gain(ByVal MP3_File As String,
  372.                           ByVal Gain As Integer,
  373.                           Optional ByVal Preserve_Datestamp As Boolean = True)
  374.  
  375.         DisposedCheck()
  376.        
  377.         File_Has_MP3Gain_Tag(MP3_File)
  378.  
  379.         Run_MP3Gain(MP3_File,
  380.                     Operation.Apply_Gain,
  381.                     String.Format("/c /e /r /t {1} /g {2} ""{0}""",
  382.                                   MP3_File,
  383.                                   If(Preserve_Datestamp, "/p", ""),
  384.                                   Gain),
  385.                     False)
  386.  
  387.     End Sub
  388.  
  389.     ''' <summary>
  390.     ''' Apply a volume gain change to file only in left or right channel.
  391.     ''' Only works for Stereo MP3 files.
  392.     ''' </summary>
  393.     Public Sub Apply_Channel_Gain(ByVal MP3_File As String,
  394.                                   ByVal Channel As Channel,
  395.                                   ByVal Gain As Integer,
  396.                                   Optional ByVal Preserve_Datestamp As Boolean = True)
  397.  
  398.         DisposedCheck()
  399.        
  400.         File_Has_MP3Gain_Tag(MP3_File)
  401.  
  402.         Run_MP3Gain(MP3_File,
  403.                     Operation.Apply_Channel_Gain,
  404.                     String.Format("/c /e /r {1} /l {2} {3} ""{0}""",
  405.                                   MP3_File,
  406.                                   If(Preserve_Datestamp, "/p", ""),
  407.                                   If(Channel = Channel.Left, 0, 1),
  408.                                   Gain),
  409.                     False)
  410.  
  411.     End Sub
  412.  
  413.     ''' <summary>
  414.     ''' Undos all mp3gain volume changes made in a file,
  415.     ''' based on stored APEv2 mp3gain tag info.
  416.     ''' </summary>
  417.     Public Sub Undo_Gain(ByVal MP3_File As String,
  418.                          Optional ByVal Preserve_Datestamp As Boolean = True)
  419.  
  420.         DisposedCheck()
  421.        
  422.         File_Has_MP3Gain_Tag(MP3_File)
  423.  
  424.         Run_MP3Gain(MP3_File,
  425.                     Operation.Undo_Gain,
  426.                     String.Format("/c /t {1} /u ""{0}""",
  427.                                   MP3_File,
  428.                                   If(Preserve_Datestamp, "/p", "")),
  429.                     False)
  430.  
  431.     End Sub
  432.  
  433. #End Region
  434.  
  435. #Region " Run Procedures "
  436.  
  437.     ''' <summary>
  438.     ''' Run MP3Gain process.
  439.     ''' </summary>
  440.     Private Sub Run_MP3Gain(ByVal MP3_File As String,
  441.                             ByVal operation As Operation,
  442.                             ByVal Parametters As String,
  443.                             ByVal IsCheckTagOperation As Boolean)
  444.  
  445.         If Me.CheckFileExist Then
  446.             FileExist(MP3_File)
  447.         End If
  448.  
  449.         With Process_For_Tag.StartInfo
  450.             .FileName = Me.mp3gain_location
  451.             .Arguments = Parametters
  452.         End With
  453.  
  454.         With Process_For_NonTag.StartInfo
  455.             .FileName = Me.mp3gain_location
  456.             .Arguments = Parametters
  457.         End With
  458.  
  459.         ' Reset Variables before relaize the operation.
  460.         InfoMessage = Nothing
  461.         ErrorMessage = Nothing
  462.         db = 0
  463.  
  464.         ' Check if file has APEv2 mp3gain tag or not,
  465.         ' before doing any other operation.
  466.         If IsCheckTagOperation Then
  467.  
  468.             Run_MP3Gain_For_Tag(Process_For_Tag, MP3_File, operation.Check_Tag, True)
  469.             Exit Sub ' If only would to check the tag then exit from this sub.
  470.  
  471.         Else ' Else, continue with the operation (Modify volume gain)...
  472.  
  473.             Select Case HasTag
  474.  
  475.                 Case True
  476.                     Run_MP3Gain_For_Tag(Process_For_Tag, MP3_File, operation, False)
  477.  
  478.                 Case False
  479.                     Run_MP3Gain_For_NonTag(Process_For_NonTag, MP3_File, operation)
  480.  
  481.             End Select ' HasTag
  482.  
  483.         End If ' IsCheckTagOperation
  484.  
  485.     End Sub
  486.  
  487.     ''' <summary>
  488.     ''' Runs mp3gain for files that already contains APEv2 mp3gain tag.
  489.     ''' </summary>
  490.     Private Sub Run_MP3Gain_For_Tag(ByVal p As Process,
  491.                                     ByVal MP3_File As String,
  492.                                     ByVal operation As Operation,
  493.                                     ByVal IsTagCheckOperation As Boolean)
  494.  
  495.         p.Start()
  496.         RaiseEvent_Started(p, MP3_File, operation)
  497.         p.WaitForExit()
  498.  
  499.         If IsTagCheckOperation Then
  500.             HasTag = CBool(p.StandardOutput.ReadToEnd.Trim.Split(Environment.NewLine).Count - 1)
  501.         End If
  502.  
  503.         ProgressArgs.Percent = 100
  504.         RaiseEvent Progress(p, ProgressArgs)
  505.  
  506.         SetMessages(p.StandardOutput.ReadToEnd())
  507.  
  508.         RaiseEvent_Exited(p,
  509.                           MP3_File,
  510.                           operation,
  511.                           If(IsTagCheckOperation, "File Has Tag?: " & CStr(HasTag), InfoMessage),
  512.                           ErrorMessage,
  513.                           db)
  514.  
  515.         ' p.Close()
  516.  
  517.     End Sub
  518.  
  519.     ''' <summary>
  520.     ''' Runs mp3gain for files that doesn't contains APEv2 mp3gain tag.
  521.     ''' </summary>
  522.     Private Sub Run_MP3Gain_For_NonTag(ByVal p As Process,
  523.                                        ByVal MP3_File As String,
  524.                                        ByVal operation As Operation)
  525.  
  526.         p.Start()
  527.         RaiseEvent_Started(p, MP3_File, operation)
  528.  
  529.         Do Until p.HasExited
  530.  
  531.             Try
  532.  
  533.                 ProgressArgs.Percent = CInt(p.StandardError.ReadLine.Split("%").First.Trim)
  534.  
  535.                 If ProgressArgs.Percent < 101 Then
  536.                     RaiseEvent Progress(p, ProgressArgs)
  537.                 End If
  538.  
  539.             Catch
  540.             End Try
  541.  
  542.         Loop
  543.  
  544.         ProgressArgs.Percent = 100
  545.         RaiseEvent Progress(p, ProgressArgs)
  546.  
  547.         SetMessages(p.StandardOutput.ReadToEnd())
  548.  
  549.         RaiseEvent_Exited(p,
  550.                           MP3_File,
  551.                           operation,
  552.                           InfoMessage,
  553.                           ErrorMessage,
  554.                           db)
  555.  
  556.         ' p.Close()
  557.  
  558.     End Sub
  559.  
  560. #End Region
  561.  
  562. #Region " Miscellaneous Procedures "
  563.  
  564.     ''' <summary>
  565.     ''' Checks if a file exists.
  566.     ''' </summary>
  567.     Private Sub FileExist(ByVal File As String)
  568.  
  569.         If Not IO.File.Exists(File) Then
  570.             Throw New Exception(String.Format("File doesn't exist: ""{0}""", File))
  571.             ' MessageBox.Show(String.Format("File doesn't exist: ""{0}""", File), "mp3gain", MessageBoxButtons.OK, MessageBoxIcon.Error)
  572.         End If
  573.  
  574.     End Sub
  575.  
  576.     ''' <summary>
  577.     ''' Raises the Event Started
  578.     ''' </summary>
  579.     Private Sub RaiseEvent_Started(ByVal p As Process,
  580.                                    ByVal file As String,
  581.                                    ByVal operation As Operation)
  582.  
  583.         With StartedArgs
  584.             .File = file
  585.             .Operation = operation
  586.         End With
  587.  
  588.         RaiseEvent Started(p, StartedArgs)
  589.  
  590.     End Sub
  591.  
  592.     ''' <summary>
  593.     ''' Raises the Event Exited
  594.     ''' </summary>
  595.     Private Sub RaiseEvent_Exited(ByVal p As Process,
  596.                                   ByVal file As String,
  597.                                   ByVal operation As Operation,
  598.                                   ByVal InfoMessage As String,
  599.                                   ByVal ErrorMessage As String,
  600.                                   ByVal db As Integer)
  601.  
  602.         With ExitedArgs
  603.             .File = file
  604.             .Operation = operation
  605.             .InfoMessage = InfoMessage
  606.             .ErrorMessage = ErrorMessage
  607.             .db = db
  608.         End With
  609.  
  610.         RaiseEvent Exited(p, ExitedArgs)
  611.  
  612.     End Sub
  613.  
  614.     ''' <summary>
  615.     ''' Sets the InfoMessage, ErrorMessage and db variables.
  616.     ''' </summary>
  617.     Private Sub SetMessages(ByVal StandardOutput As String)
  618.  
  619.         Output = StandardOutput.
  620.                  Split(Environment.NewLine).
  621.                  Select(Function(line) line.Replace(Environment.NewLine, "").Trim).
  622.                  Where(Function(null) Not String.IsNullOrEmpty(null)).ToArray
  623.  
  624.         For Each line In Output
  625.  
  626.             Select Case True
  627.  
  628.                 Case line.StartsWith("No changes")
  629.                     InfoMessage = "No volume gain changes are necessary."
  630.  
  631.                 Case line.StartsWith("Applying")
  632.                     db = db_RegEx.Match(line).Groups(1).Value
  633.                     If String.IsNullOrEmpty(InfoMessage) Then
  634.                         InfoMessage = line
  635.                     End If
  636.  
  637.                 Case line.StartsWith("Can't")
  638.                     ErrorMessage = line
  639.  
  640.             End Select
  641.  
  642.         Next line
  643.  
  644.     End Sub
  645.  
  646. #End Region
  647.  
  648. #Region " IDisposable "
  649.  
  650.     ''' <summary>
  651.     ''' To detect redundant calls when disposing.
  652.     ''' </summary>
  653.     Private IsDisposed As Boolean = False
  654.  
  655.     ''' <summary>
  656.     ''' Prevents calls to methods after disposing.
  657.     ''' </summary>
  658.     Private Sub DisposedCheck()
  659.         If Me.IsDisposed Then
  660.             Throw New ObjectDisposedException(Me.GetType().FullName)
  661.         End If
  662.     End Sub
  663.    
  664.     ''' <summary>
  665.     ''' Disposes the objects generated by this instance.
  666.     ''' </summary>
  667.     Public Sub Dispose() Implements IDisposable.Dispose
  668.         Dispose(True)
  669.         GC.SuppressFinalize(Me)
  670.     End Sub
  671.  
  672.     ' IDisposable
  673.     Protected Overridable Sub Dispose(IsDisposing As Boolean)
  674.  
  675.         If Not Me.IsDisposed Then
  676.  
  677.             If IsDisposing Then
  678.              Process_For_Tag.Dispose()
  679.              Process_For_NonTag.Dispose()
  680.             End If
  681.  
  682.         End If
  683.  
  684.         Me.IsDisposed = True
  685.  
  686.     End Sub
  687.  
  688. #End Region
  689.  
  690. End Class
  691.  
  692. #End Region
  693.  
  694. ]]></Code>
  695.     </Snippet>
  696.   </CodeSnippet>
  697. </CodeSnippets>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement