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 clsVBPModReporter
   ' clsVBPRefReporter: Report COM references for VBP file

   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 = "VBPPATH" & vbTab & "VBPNAME" & vbTab & "MODTYPE" & vbTab & "MODNAME"
   End Function
   Public Sub processFile(ByVal fil As System.IO.FileInfo,ByVal rpt As System.IO.StreamWriter)

      Const FUNC_NAME As String = "processFile"
      Dim txtfil As System.IO.StreamReader = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

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


         txtfil = modScanToolLib.openInputText(fil.FullName)

         Dim s As String = ""
         s = txtfil.ReadToEnd()

         Dim arr As String() = Array.Empty(Of String)()
         arr = Strings.Split(s,Environment.NewLine,-1,CompareMethod.Binary)

         For Each v As String In arr

            modtype = ""
            Dim sLine As String = ""
            sLine = Strings.LCase(v)

            If (sLine Like "form=*.frm" Or sLine Like "class=*.cls" Or sLine Like "module=*.bas" Or sLine Like "usercontrol=*.ctl" Or sLine Like "propertypage=*.pag") Then

               sLine = v

               Dim j As Integer = 0
               Dim i As Integer = 0

               i = Strings.InStr(1,sLine,"=",CompareMethod.Binary) + 1

               modtype = Strings.Left(sLine,i - 2)

               sLine = Strings.Trim(Mid(sLine,i)) ' object name; path

               j = Strings.InStrRev(sLine,";",-1,CompareMethod.Binary)

               If (j = 0) Then
                  j = 1
               Else
                  j = j + 1
               End If

               sLine = Strings.Trim(Mid(sLine,j)) ' object path

               j = Strings.InStrRev(sLine,"\",-1,CompareMethod.Binary)

               If (j = 0) Then
                  j = 1
               Else
                  j = j + 1
               End If

               modname = Strings.Trim(Mid(sLine,j)) ' file name

               modScanToolLib.writeRpt(rpt,filpath & vbTab & filname & vbTab & modname & vbTab & modtype & Environment.NewLine)


            End If

         Next

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

      If (Not (txtfil Is Nothing)) Then
         txtfil.Close()
      End If
      txtfil = 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
