[INCLUDE]
ctPackage

[CODE]
Public Function ctPackage_GetFileList(ByVal ctPackagePointer As Long, ByRef FileArray() As String, ByVal FileArraySize As Long, Optional ByRef UncompressedSize As Long, Optional ByVal IndexStep As Long = 1&, Optional ByVal IndexStart As Long = 0&) As Long
  Dim xLong1 As Long
  Dim xLong2 As Long
  Dim xChar1 As String
  Dim xChar2 As String
  'Dim IndexStart As Long
  Dim xDataPos As Long
  Dim ctPIType As ctPackage_InfoType

  ctPackage_GetFileList = -1&
  
  If ctPackage_GetInfoEx(ctPackagePointer, ctPIType) Then
    xChar1 = String(ctPackageConst_HeaderSize, vbNullChar)
      
    'Get ctPIType.FileHandle, ctPIType.FileHeader + 1&, xChar1
    If Not SetFilePointer(ctPIType.FileHandle, ctPIType.FileHeader, 0&, 0&) = -1& Then
      If Not ReadFile(ctPIType.FileHandle, ByVal xChar1, ctPackageConst_HeaderSize, 0&, ByVal 0&) = 0& Then

        xLong2 = ctPackage_LenCharToLong(xChar1, ctPackageConst_HeaderPosFileCount + 1&)
        xLong1 = ctPackage_LenCharToLong(xChar1, ctPackageConst_HeaderPosFileNames)
        xChar1 = String(xLong2 * ctPackageConst_TOCWidth, vbNullChar)
        xChar2 = String(xLong1, vbNullChar)

        'Get ctPIType.FileHandle, ctPIType.FileHeader + ctPackageConst_HeaderSize + 1&, xChar1
        If Not SetFilePointer(ctPIType.FileHandle, ctPIType.FileHeader + ctPackageConst_HeaderSize, 0&, 0&) = -1& Then
          If Not ReadFile(ctPIType.FileHandle, ByVal xChar1, xLong2 * ctPackageConst_TOCWidth, 0&, ByVal 0&) = 0& Then
          
            xDataPos = ctPIType.FileHeader + ctPackageConst_HeaderSize + xLong2 * ctPackageConst_TOCWidth + xLong1
            'Get ctPIType.FileHandle, , xChar2
            'If Not SetFilePointer(ctPIType.FileHandle, ctPIType.FileHeader, 0&, 0&) = -1& Then
              If Not ReadFile(ctPIType.FileHandle, ByVal xChar2, xLong1, 0&, ByVal 0&) = 0& Then
              
                If xLong2 > FileArraySize Then
                  ctPackage_GetFileList = FileArraySize
                  Else
                  ctPackage_GetFileList = xLong2
                  End If
                  
                'UncompressedSize = 0&
                For xLong1 = 0& To ctPackage_GetFileList - 1&
                  xLong2 = ctPackage_LenCharToLong(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosFileNameSize)
          '        FileArray(IndexStart) = Mid(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosFlags, ctPackageConst_TOCPWFlags) & _
                                          ctPackage_LenLongToChar(xDataPos) & FileArray(IndexStart) & _
                                          Mid(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosIntSize, 4& + 4&) & _
                                          Left(xChar2, xLong2)
                    
                  FileArray(IndexStart) = Mid(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosFlags, ctPackageConst_TOCPWFlags) & _
                                          ctPackage_LenLongToChar(xDataPos) & _
                                          Mid(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosIntSize, 4& + 4&) & _
                                          Left(xChar2, xLong2)
                  xDataPos = xDataPos + ctPackage_LenCharToLong(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosIntSize)
                  UncompressedSize = UncompressedSize + ctPackage_LenCharToLong(xChar1, xLong1 * ctPackageConst_TOCWidth + ctPackageConst_TOCPosExtSize)
                    
                  xChar2 = Mid(xChar2, xLong2 + 1&)
                  IndexStart = IndexStart + IndexStep
                  Next
                End If
              'End If
            End If
          End If
        End If
      End If
    End If
  End Function
