Option Strict Off
Option Explicit On
Imports System.Linq
Imports System.Collections.Generic
Imports System
Imports System.Windows.Forms
Imports System.Windows
Imports gmRTL.Core
Namespace ScanToolLib
   Public Class clsCOMReporter
   ' clsCOMReporter: Reports TypeLib information for COM Comnponents

   Public Class statusEventArgs : Inherits System.EventArgs
      Public msg As String
      Public Sub New(ByVal msg As String)
         Me.msg = msg
      End Sub
   End Class
   Public Delegate Sub statusEventHandler(sender as Object,e As statusEventArgs)
   Public Event status_Event As EventHandler(Of statusEventArgs)
   Protected Overridable Sub Onstatus_Event(msg As String)
      Dim e As statusEventArgs
      e = New statusEventArgs(msg)
      RaiseEvent status_Event(Me, e)
   End Sub
   Public Function header() As String
      header = "COMPATH" & vbTab & "COMNAME" & vbTab & "EXT" & vbTab & "LIBGUID" & vbTab & "LIBNAME"
   End Function
   Public Sub processFile(ByVal fil As System.IO.FileInfo,ByVal rpt As System.IO.StreamWriter)
      Const FUNC_NAME As String = "processFile"

      Dim filpath As String = ""
      filpath = fil.Directory.FullName
      Dim filname As String = ""
      filname = fil.Name

      Dim libname As String = ""
      Dim libguid As String = ""
      Dim tlinfo As gmRTL.TLI.TypeLibInfo = Nothing

      gmRTL.Core.ErrorHandling.ResumeNext(Sub()
         Dim tliApp As gmRTL.TLI.TLIApplication = Nothing
         tliApp = New gmRTL.TLI.TLIApplication
         tlinfo = tliApp.TypeLibInfoFromFile(fil.FullName)
         If (Err.Number = gmRTL.TLI.TliErrors.tliErrCantLoadLibrary) Then
            libname = "-"
            libguid = "ERR=" & Err.Number & ": " & Err.Description
            Err.Clear
         Else
            libname = tlinfo.Name
            libguid = tlinfo.GUID
         End If
      End Sub)
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         Dim filextn As String = ""
         Dim i As Integer = 0
         i = Strings.InStrRev(filname,".",-1,CompareMethod.Binary)
         If (i > 0) Then
            filextn = Mid(fil.Name,i + 1)
         Else
            filextn = "-"
         End If

         modScanToolLib.writeRpt(rpt,filpath & vbTab & filname & vbTab & filextn & vbTab & libguid & vbTab & libname & Environment.NewLine)

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)
      End Try

      tlinfo = Nothing

      If (Err.Number <> 0) Then
         Err.Raise(Err.Number,String.Empty,TypeName(Me) & "::" & FUNC_NAME & " " & Environment.NewLine & "[" & fil.FullName & "]" & Environment.NewLine & Err.Description)
      End If

   End Sub
   End Class
End Namespace
