Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Updated zlib header

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Updated zlib header

    Updated version of ZLIB.DLL headerfile.
    Added AddToZip and ExtractFromZip functions.

    Code:
    '==================================================================================================
    ' ZLIB is a compression library compatible with the zip format.
    ' It is written by Jean-Loup Gailly and Mark Adler, and is freely available.
    ' Added AddToZip and ExtractFromZip functions. Peter Lameijn.   5/2002
    ' Added UnzClose function (was missing)
    ' PBZLIB.INC    PB/Dll 6.x / PB/WIN 7.0  Zlib.dll interface include
    ' Updated Jan 24, 2003 :  Function AddToZipEx added.
    ' Updated Sep 08, 2004 :  Added relative root zipping to AddToZipEx function
    '==================================================================================================
    #Include "Win32api.inc"
     
    %Z_NO_COMPRESSION           =0
    %Z_BEST_SPEED               =1
    %Z_BEST_COMPRESSION         =9
    %Z_DEFAULT_COMPRESSION      =(-1)
    %Z_DEFLATED                 =8
     
    %ZIP_PATH                   = &h0001
    %ZIP_CLOSE                  = &h0002
    %ZIP_REL_PATH               = &h0004
    '--------------------------------------------------------------------------------------------------
    Type tm_unz_s
      tm_sec                As Dword
      tm_min                As Dword
      tm_hour               As Dword
      tm_mday               As Dword
      tm_mon                As Dword
      tm_year               As Dword
    End Type
     
    Type unz_global_info_s
      number_entry          As Dword
      size_comment          As Dword
    End Type
     
    Type unz_file_info_s
      version               As Dword
      version_needed        As Dword
      flag                  As Dword
      compression_method    As Dword
      dosDate               As Dword
      crc                   As Dword
      compressed_size       As Dword
      uncompressed_size     As Dword
      size_filename         As Dword
      size_file_extra       As Dword
      size_file_comment     As Dword
      disk_num_start        As Dword
      internal_fa           As Dword
      external_fa           As Dword
      tmu_date              As tm_unz_s
    End Type
     
    Type zip_fileinfo_s
      tm_zip            As tm_unz_s
      dosDate           As Dword
      internal_fa       As Dword
      external_fa       As Dword
    End Type
     
    '==================================================================================================
    Declare Function compress Lib "zlib.dll" Alias "compress" (ByRef dest As Any, _
            ByRef destLen As Any, ByRef src As Any, ByVal srcLen  As Long) As Long
    '==================================================================================================
    Declare Function uncompress Lib "zlib.dll" Alias "uncompress" (ByRef dest As Any, _
            ByRef destLen As Any, ByRef src As Any, ByVal srcLen  As Long) As Long
    '==================================================================================================
    Declare Function unzOpen  Lib "zlib.dll" Alias "unzOpen" (ByRef zpath As Asciiz) As Dword
    '==================================================================================================
    Declare Function unzGetGlobalInfo Lib "zlib.dll" Alias "unzGetGlobalInfo" (ByVal fh As Dword, _
                                      ByRef pGlobalInfo As unz_global_info_s) As Long
    '==================================================================================================
    Declare Function unzGetGlobalComment Lib "zlib.dll" Alias "unzGetGlobalComment" _
            (ByVal fh As Dword, ByRef szComment As Asciiz, ByVal BufSize As Dword) As Long
    '==================================================================================================
    Declare Function unzGoToFirstFile Lib "zlib.dll" Alias "unzGoToFirstFile"(ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function unzGoToNextFile Lib "zlib.dll" Alias "unzGoToNextFile" (ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function unzLocateFile Lib "zlib.dll" Alias "unzLocateFile" (ByVal fh As Dword, _
            ByRef szFileName As Asciiz, ByVal CaseSensitivity As Long) As Long
    '==================================================================================================
    Declare Function unzGetCurrentFileInfo Lib "zlib.dll" Alias "unzGetCurrentFileInfo" ( _
            ByVal fh As Dword, ByRef pFile_Info As unz_file_info_s, ByRef szFileName As Asciiz, _
            ByVal FileNameBufLen As Dword, ByRef pExtra As Any, ByVal pExtraLen As Dword, _
            ByRef szComment As Asciiz, ByVal szCommentLen As Dword) As Long
    '==================================================================================================
    Declare Function unzOpenCurrentFile Lib "zlib.dll" Alias "unzOpenCurrentFile" ( _
            ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function unzCloseCurrentFile Lib "zlib.dll" Alias "unzCloseCurrentFile" ( _
            ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function unzReadCurrentFile Lib "zlib.dll" Alias "unzReadCurrentFile" ( _
            ByVal fh As Long, ByRef buf As Any, ByVal bufLen As Dword) As Long
    '==================================================================================================
    Declare Function UnzClose Lib "zlib.dll" Alias "unzClose" ( _
            ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function zipOpen Lib "zlib.dll" Alias "zipOpen" (ByRef fPath As Asciiz, _
            ByVal DoAppend As Long) As Dword
    '==================================================================================================
    Declare Function zipOpenNewFileInZip Lib "zlib.dll" Alias "zipOpenNewFileInZip" ( _
            ByVal fh As Dword, ByRef szFileName As Asciiz, ByRef zipfi As zip_fileinfo_s, _
            ByRef Extra_local As Any, ByVal Extra_local_size As Dword, ByRef Extra_global As Any, _
            ByVal Extra_global_size As Dword, ByRef Comment As Asciiz, ByVal Method As Long, _
            ByVal level As Long) As Long
    '==================================================================================================
    Declare Function zipWriteInFileInZip Lib "zlib.dll" Alias "zipWriteInFileInZip" ( _
            ByVal fh As Dword, ByRef pBuf As Any, ByVal BufLen As Dword) As Long
    '==================================================================================================
    Declare Function zipCloseFileInZip Lib "zlib.dll" Alias "zipCloseFileInZip" ( _
            ByVal fh As Dword) As Long
    '==================================================================================================
    Declare Function zipClose Lib "zlib.dll" Alias "zipClose" ( _
            ByVal fh As Dword, ByRef global_comment As Asciiz) As Long
    '==================================================================================================
    Function CompressString (ByRef TheString As String) As Long
      Dim CmpSize As Long, TBuff As String, OrgSize As Long, Result As Long
      OrgSize = Len(TheString)                                          'Allocate stringspace buffers
      TBuff = String$(OrgSize + (OrgSize * 0.01) + 12, 0)
      CmpSize = Len(TBuff)
      'Compress string (temporary string buffer) data
      Result = compress(ByVal StrPtr(TBuff), CmpSize, ByVal StrPtr(TheString), OrgSize)
      'Crop the string and set it to the actual string.
      TheString = Left$(TBuff, CmpSize)
      'Return error code (if any)
      Function = Result
    End Function
    '==================================================================================================
    Function DecompressString (ByRef TheString As String, ByRef OriginalSize As Long) As Long
      Dim CmpSize   As Long, TBuff As String, Result As Long
      'Allocate string space
      TBuff = String$(OriginalSize + (OriginalSize * 0.01) + 12, 0)
      CmpSize = Len(TBuff)
      'Decompress
      result = uncompress(ByVal StrPtr(TBuff), CmpSize, ByVal StrPtr(TheString), Len(TheString))
      'Make string the size of the uncompressed string
      TheString = Left$(TBuff, CmpSize)
      'Return error code (if any)
      DecompressString = Result
    End Function
     
    '==================================================================================================
    ' Extracts all files from a zip archive. If present, subdir paths are extracted and recreated.
    ' Returns:
    '                   0       :   Error
    '                   1 and up:   Number of files extracted
    '
    ' On start, zipname must hold full zipfile path/name
    '==================================================================================================
    Function ExtractFromzip(ZipName As Asciiz) As Long
      Local hZip As Dword, szFilePath As Asciiz * %MAX_PATH, dwRet As Dword, fCnt As Dword
      Local szStr As Asciiz * %MAX_PATH, Extra As Asciiz * %MAX_PATH, FIS As unz_file_info_s
      Local Path As String, CreatePath As String, hFile As Long, RxBuf As String, ST As SYSTEMTIME
      Local FT As FILETIME, hWinFile As Dword, fLen As Dword
      fCnt = 0
      hZip = UnzOpen (ZipName)                                              'Open zipfile
      If hZip Then                                                          'If success, go to 1st file
        dwRet = UnzGotoFirstFile(hZip)                                      'in zip archive
        While IsFalse(dwRet)                                                '
          UnzGetCurrentFileInfo hZip, _                                     'Get info of file
                                FIS, _                                      '
                                szFilePath, _                               '
                                SizeOf(szFilePath), _                       '
                                Extra, _                                    '
                                SizeOf(Extra), _                            '
                                szStr, _                                    '
                                SizeOf(szStr)                               '
          Path = szFilePath                                                 '
    '--------------------------------------------------------------------------------------------------
          If Right$(Path,1) <> "/" Then                                     '
            While InStr (Path, Any "/")                                     'Change "/" into "\" and
              CreatePath = Extract$(Path, Any "/")                          'create Dirs if nonexistant
              dwRet = InStr(Path, Any "/")                                  '
              Mid$(Path, dwRet, 1) = "\"                                    '
              If Dir$(CreatePath, %SUBDIR) = "" Then MkDir CreatePath       '
            Wend                                                            '
    '--------------------------------------------------------------------------------------------------
            dwRet = UnzOpenCurrentFile (hZip)                               'Open the file
            If IsFalse (dwRet) Then                                         '
              RxBuf = Space$(FIS.Uncompressed_Size)                         'Allocate buffer space
              fLen = Len(RxBuf) + 10                                            '
              dwRet = UnzReadCurrentFile (hZip, ByVal StrPtr(RxBuf), fLen)  'Read zipfile
              If dwRet Then                                                 '
                hFile = FreeFile                                            'Open output file
                Path = MCase$(Path)                                         'and write to it
                Open Path For Binary As hFile                               '
                Put$ hFile, RxBuf                                           '
                hWinFile = FileAttr (hFile, 2)                              'Set new filedate
                ST.wSecond    = FIS.tmu_date.tm_sec                         'same as  stored date
                ST.wMinute    = FIS.tmu_date.tm_min                         '
                ST.wHour      = FIS.tmu_date.tm_hour                        '
                ST.wDay       = FIS.tmu_date.tm_mday                        '
                ST.wMonth     = FIS.tmu_date.tm_mon + 1                     '
                ST.wYear      = FIS.tmu_date.tm_year                        '
                SystemTimeToFileTime ST, FT                                 '
                LocalFileTimeToFileTime FT, FT                              '
                SetFileTime hWinFile, FT, FT, FT                            '
                Close hFile                                                 '
                Incr fCnt                                                   '
                UnzCloseCurrentFile hZip                                    '
              End If                                                        '
            End If                                                          '
          End If                                                            '
          dwRet = UnzGotoNextFile(hZip)                                     '
        Wend                                                                '
      UnzClose hZip                                                         '
      End If                                                                '
      Function = fCnt                                                       '
    End Function                                                            '
     
    '==================================================================================================
    ' AddToZip (SourceFileName, ZipFileName)
    '           On first call, zipfile is created.
    '           On next call, file is added to it
    '           On last call, set sourcefilename empty, and zipfile is closed
    ' Example:  If test1 and test2 must be put into testzip.zip, use:
    '           AddToZip "test1", "testzip.zip"
    '           AddToZip "test2", "testzip.zip"
    '           AddToZip "", ""
    '--------------------------------------------------------------------------------------------------
    Function AddToZip (ZipSource As String, ZipDest As String) As Long
      Local LBuff$, LRet&, LBlockSize&, LhFile&, LSource As Asciiz * 128, LDest As Asciiz * 128
      Local ZipFi As ZIP_FILEINFO_S, LSys As SYSTEMTIME, LLoFTime As FILETIME
      Local OpenBuff As OFSTRUCT, CFTime As FILETIME, LAFTime As FILETIME, LWFTime As FILETIME
      Static LhZip As Dword
      If ZipSource <> "" Then
        LSource = ZipSource
        LDest = ZipDest
        If LhZip = 0 Then LhZip = ZipOpen (LDest,0)
        If LhZip Then
          LhFile = OpenFile(LSource, OpenBuff, %OF_READWRITE)                   'Retrieve date/time
          GetFileTime LhFile, CFTime, LAFTime, LWFTime                          'from original file
          FileTimeToLocalFileTime LWFTime, LLOFTime
          FileTimeToSystemTime LLOFTime, LSys
          zipfi.tm_zip.tm_sec   =  LSys.wSecond
          zipfi.tm_zip.tm_min   =  LSys.wMinute
          zipfi.tm_zip.tm_hour  =  LSys.wHour
          zipfi.tm_zip.tm_mday  =  LSys.wDay
          zipfi.tm_zip.tm_mon   =  LSys.wMonth  -1
          zipfi.tm_zip.tm_year  =  LSys.wYear
          zipfi.DosDate         =  0
          zipfi.internal_fa     =  0
          zipfi.external_fa     =  0
          CloseHandle LhFile
          While InStr(LSource,"\") : LSource = Right$(LSource,Len(LSource)-1) : Wend
          LRet = ZipOpenNewFileInZip (LhZip, LSource, zipfi, ByVal 0,0,ByVal 0,0, ByVal 0, _
                                                      %Z_DEFLATED, %Z_DEFAULT_COMPRESSION)
        End If
        LhFile = FreeFile
        Open ZipSource For Binary As LhFile
        While Not (Eof(LhFile))
          LBlockSize =  Lof(LhFile) - Loc(LhFile)
          If LBlockSize > 32768 Then LBlockSize = 32768 Else Incr LBlockSize
          Get$ LhFile, LBlockSize, LBuff
          LRet = ZipWriteInFileInZip (LhZip, ByVal StrPtr(LBuff), Len(LBuff))
          If Seek(LhFile) => Lof(LhFile) Then Exit Loop
        Wend
        Close LhFile
        ZipCloseFileInZip LhZip
      Else
        ZipClose LhZip, ByVal 0 : LhZip = 0
      End If
    End Function
     
    '==================================================================================================
    ' FindFileInZip  (FileName, ZipName)
    '                Tests for presence of file in archive
    '                Returns 0 if found, else non zero
    '==================================================================================================
    Function FindFileInZip (FileName As String, ZipName As String) As Long
      Local hUnzip As Dword, ZSrc As Asciiz * %MAX_PATH, ZDest As Asciiz * %MAX_PATH
      Local FIS As Unz_File_Info_s, dwRet As Dword, lRet As Long, szPath As Asciiz * %MAX_PATH
      Local Extra As Asciiz * %MAX_PATH, szStr As Asciiz * %MAX_PATH
     
      If Dir$(ZipName) = "" Then Function = -2 : Exit Function
      ZSrc    = FileName
      ZDest   = ZipName
      lRet =  InStr(zSrc,":")
      If lRet > 0 Then zSrc = StrDelete$(zSrc, 1, lRet)
      While (Left$(zSrc,1) = "\")
        zsrc = StrDelete$(zSrc, 1, 1)
      Wend
      hUnzip = UnzOpen(ZDest)
      If IsFalse hUnzip Then Function = -3 : Exit Function
      dwRet = UnzGoToFirstFile(hUnzip)
      While IsFalse(dwRet)
        UnzGetCurrentFileInfo hUnzip, FIS, szPath, SizeOf(szPath), Extra, SizeOf(Extra), szStr, SizeOf(szStr)
        If UCase$(szPath) = UCase$(zSrc) Then Function = 0 : UnzClose hUnzip : Exit Function
        dwRet = UnzGoToNextFile(hUnzip)
      Wend
      Function = -1
      UnzClose hUnzip
    End Function
     
    '==================================================================================================
    ' AddToZipEx    (SourceFileName, ZipFileName, Flags)
    '               Does the same as AddToZip, with the following additions:
    '               - If Zip archive exists, file is added to it.
    '               - Possibility to in/exclude path info for added files.
    '               Added parameter Flags, which can be combination of:
    '               %ZIP_CLOSE      : Archive is closed after file is added
    '               %ZIP_PATH       : Add path to file (On unzipping path will be recreated)
    '               %ZIP_REL_PATH   : Save this as relative basepath
    '               (Relative root is taken from first call to function)
    ' Example:      If test1 and test2 must be put into testzip.zip, use:
    '               AddToZip "test1", "testzip.zip"
    '               AddToZip "test2", "testzip.zip", %ZIP_CLOSE
    '
    ' Returns:      > 0 if OK (Value is number of files in archive)
    '
    '
    '==================================================================================================
    Function AddToZipEx (ZipSource As String, ZipName As String, ByVal Flags As Dword) As Long
     
      Local LRet As Long, BlkSize As Long, zBuff As String, ZipFi As ZIP_FILEINFO_S
      Local hFile As Dword, dwRet As Dword, zLen As Dword, LSys As SYSTEMTIME, OpenBuff As OFSTRUCT
      Local ZSrc As Asciiz * %MAX_PATH, ZDest As Asciiz * %MAX_PATH, FIS As Unz_File_Info_s
      Local szFilePath As Asciiz * %MAX_PATH, Extra As Asciiz * %MAX_PATH, szStr As Asciiz * %MAX_PATH
      Local LLoFTime As FILETIME, CFTime As FILETIME, LAFTime As FILETIME, LWFTime As FILETIME
     
      Static hZip As Dword, hUnZip As Dword,ZipCnt As Long, szBasePath As Asciiz * %MAX_PATH
    '--------------------------------------------------------------------------------------------------
      ZSrc    = ZipSource
      ZDest   = ZipName
      If (Dir$(ZipSource) <> "") And (hZip = 0) Then                            'First loop?
        If Dir$("Tmp$Zip") <> "" Then Kill "Tmp$Zip"                            'Kill existing tmpzip
        hZip = ZipOpen ("Tmp$Zip", 0)                                           'and open new one
        If (Dir$(ZipName) <> "") Then hUnZip = UnzOpen (ZDest)                  'Open archive if exists
        ZipCnt = 0
        If (Flags And %ZIP_REL_PATH) Then
          szBasePath = Left$(ZipSource,InStr(-1, ZipSource, Any "\"))           'Strip filename
          lRet =  InStr(szBasePath,":")                                         'Strip driveletter
          If lRet > 0 Then szBasePath = StrDelete$(szBasePath, 1, lRet)         '
          While (Left$(szBasePath,1) = "\")                                     'Strip leading '\'
            szBasePath = StrDelete$(szBasePath, 1, 1)
          Wend
        End If
      End If                                                                    '
     
      If hUnzip Then                                                            'File existed, process
        dwRet = UnzGoToFirstFile(hUnzip)
        While IsFalse (dwRet)
          UnzGetCurrentFileInfo hUnzip, _
                                FIS, _
                                szFilePath, _
                                SizeOf(szFilePath), _
                                Extra, _
                                SizeOf(Extra), _
                                szStr, _
                                SizeOf(szStr)
          dwRet = UnzOpenCurrentFile(hUnzip)
          If IsFalse(dwRet) Then
            ZBuff  = Space$(FIS.Uncompressed_Size)
            ZLen   = Len(ZBuff) + 10
            dwRet  = UnzReadCurrentFile(hUnzip, ByVal StrPtr(ZBuff), ZLen)
            If dwRet Then
              UnzCloseCurrentFile hUnzip
              ZipFi.tm_zip        = FIS.tmu_Date
              ZipFi.DosDate       = 0
              ZipFi.internal_fa   = 0
              ZipFi.external_fa   = 0
              dwRet = ZipOpenNewFileInZip(hzip, szFilePath, ZipFi, ByVal 0, 0, ByVal 0, 0, ByVal 0,%Z_DEFLATED, %Z_DEFAULT_COMPRESSION)
              dwRet = ZipWriteInFileInZip(hZip, ByVal StrPtr(ZBuff), Len(ZBuff))
              dwRet = ZipCloseFileInZip(hZip)
              Incr ZipCnt
            End If
          End If
          dwRet = UnzGoToNextFile(hUnzip)
        Wend
        UnzClose hUnzip
        hUnzip = 0
      End If
     
      If Dir$(ZipSource) <> "" Then
        If hZip = 0 Then hZip = ZipOpen (ZDest,0)
        If hZip Then
          hFile = OpenFile(ZSrc, OpenBuff, %OF_READWRITE)                   'Retrieve date/time
          GetFileTime hFile, CFTime, LAFTime, LWFTime                          'from original file
          FileTimeToLocalFileTime LWFTime, LLOFTime
          FileTimeToSystemTime LLOFTime, LSys
          zipfi.tm_zip.tm_sec   =  LSys.wSecond
          zipfi.tm_zip.tm_min   =  LSys.wMinute
          zipfi.tm_zip.tm_hour  =  LSys.wHour
          zipfi.tm_zip.tm_mday  =  LSys.wDay
          zipfi.tm_zip.tm_mon   =  LSys.wMonth  -1
          zipfi.tm_zip.tm_year  =  LSys.wYear
          zipfi.DosDate         =  0
          zipfi.internal_fa     =  0
          zipfi.external_fa     =  0
          CloseHandle hFile
          lRet =  InStr(zSrc,":")
          If lRet > 0 Then zSrc = StrDelete$(zSrc, 1, lRet)
          While (Left$(zSrc,1) = "\")
            zsrc = StrDelete$(zSrc, 1, 1)
          Wend
          If IsFalse(Flags And (%ZIP_PATH Or %ZIP_REL_PATH)) Then
            While InStr(ZSrc,"\") : ZSrc = Right$(ZSrc,Len(ZSrc)-1) : Wend
          End If
          If (Flags And %ZIP_REL_PATH) Then
            If Remain$(ZSrc, szBasePath) <> "" Then ZSrc = Remain$(ZSrc, szBasePath)
          End If
          LRet = ZipOpenNewFileInZip (hZip, ZSrc, zipfi, ByVal 0,0,ByVal 0,0, ByVal 0, _
                                                      %Z_DEFLATED, %Z_DEFAULT_COMPRESSION)
        End If
        hFile = FreeFile
        Open ZipSource For Binary As hFile
        While Not (Eof(hFile))
          BlkSize =  Lof(hFile) - Loc(hFile)
          If BlkSize > 32768 Then BlkSize = 32768 Else Incr BlkSize
          Get$ hFile, BlkSize, zBuff
          LRet = ZipWriteInFileInZip (hZip, ByVal StrPtr(zBuff), Len(zBuff))
          If Seek(hFile) => Lof(hFile) Then Exit Loop
        Wend
          Incr ZipCnt
        Close hFile
        ZipCloseFileInZip hZip
      End If
     
      If (Flags And %ZIP_CLOSE) Then
        ZipClose hZip, ByVal 0
        Kill ZipName
        FileCopy "Tmp$Zip", ZipName
        Kill "Tmp$Zip"
        szBasePath = ""
        hZip = 0
      End If
      Function = ZipCnt
    End Function
     
    '==================================================================================================
    ------------------
    Peter.
    mailto[email protected][email protected]</A>



    [This message has been edited by Peter Lameijn (edited September 08, 2004).]
    Regards,
    Peter

  • #2
    Updated INC file: Added AddToZipEx Function for adding files to existing
    archives.

    ------------------
    Peter.
    mailto[email protected][email protected]</A>

    [This message has been edited by Peter Lameijn (edited January 24, 2003).]
    Regards,
    Peter

    Comment


    • #3
      Nice work!

      Here is the link for the library - nice to have in combination with the source above: http://www.gzip.org/zlib/index.html

      Regards

      Tonny

      ------------------

      Comment


      • #4
        Peter,

        Which version of the zlib.dll should I download to work with
        your code?

        Thanks

        ------------------
        E-Mail: [email protected]
        E-Mail:
        pt AT pursuersoft DOT com

        Comment


        • #5
          Originally posted by Phil Tippit:
          Peter,

          Which version of the zlib.dll should I download to work with
          your code?

          Here is the link to the pre-build zlib DLL v/1.14 (Win16 and Win32): http://www.winimage.com/zLibDll/zlib114dll.zip

          Downloadpage: http://www.winimage.com/zLibDll/

          Regards

          Tonny


          ------------------

          Comment


          • #6
            is there an example that will tell me how many files are in the zip

            Comment


            • #7
              Ralph,

              Had some old demo code to get you started. Only shows zip contents, doesn't unpack...

              Code:
              #Compile Exe
              #Dim All
              #Debug Error On
              #Include "WIN32API.INC"
              #Include "COMMCTRL.INC"
              #Include "COMDLG32.INC"
              #Include "PBZLIB.INC"
              
              %IDD_DIALOG1 = 101  : %IDC_SYSLISTVIEW32_1 = 1001 : %IDC_BUTTON1 = 1002
              %IDC_BUTTON2 = 1003 : %IDR_MENU1 = 102 : %IDM_FILE_OPEN = 1004 : %IDM_FILE_EXIT = 1005
              
              Global hDlg As Dword, hlView As Dword
              
              Declare Function AttachMENU1(ByVal hDlg As Dword) As Dword
              Declare CallBack Function ShowDIALOG1Proc()
              Declare Function SampleListView(ByVal hDlg As Dword, ByVal lID As Long, ByVal _
                  lColCnt As Long, ByVal lRowCnt As Long) As Long
              Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
              
              '--------------------------------------------------------------------------------
              Sub LV_SetItemText (ByVal iRow As Long, ByVal iCol As Long, ItemText As String)
                Local szStr As AsciiZ * 64, lvi As LV_ITEM
                On Error Resume Next
              
                If iCol Then lvi.iItem = 0 Else lvi.iItem = iRow -1
                lvi.iSubItem = iCol
                lvi.mask = %LVIF_TEXT  Or %LVIF_PARAM Or %LVIF_STATE
                szStr = ItemText
                lvi.pszText = VarPtr(szStr)
                lvi.iImage = 0
                If iCol Then
                  Control Send hDlg, %IDC_SYSLISTVIEW32_1, %LVM_SetItemText, iRow-1, VarPtr(LVi)
                Else
                  Control Send hDlg,  %IDC_SYSLISTVIEW32_1,%LVM_SetItem, 0, VarPtr(LVi)
                End If
                Exit Sub
              End Sub
              
              '--------------------------------------------------------------------------------
              Function GetFileNames(ZipName As AsciiZ) As Long
                Local hZip As Dword, szFilePath As AsciiZ * %Max_Path, dwRet As Dword, fCnt As Dword
                Local szStr As AsciiZ * %Max_Path, Extra As AsciiZ * %Max_Path, FIS As unz_file_info_s
                Local Path As String, CreatePath As String, hFile As Long, RxBuf As String, ST As SYSTEMTIME
                Local FT As FILETIME, hWinFile As Dword, fLen As Dword
                fCnt = 0
                hZip = UnzOpen (ZipName)                                              'Open zipfile
                If hZip Then                                                          'If success, go to 1st file
                  dwRet = UnzGotoFirstFile(hZip)                                      'in zip archive
                  While IsFalse(dwRet)                                                '
                    UnzGetCurrentFileInfo hZip, _                                     'Get info of file
                                          FIS, _                                      '
                                          szFilePath, _                               '
                                          SizeOf(szFilePath), _                       '
                                          Extra, _                                    '
                                          SizeOf(Extra), _                            '
                                          szStr, _                                    '
                                          SizeOf(szStr)                               '
                    Path = szFilePath                                                 '
                    If Right$(Path,1) <> "/" Then                                     '
                      Replace Any "/" With "\" In Path
                      ST.wSecond    = FIS.tmu_date.tm_sec                             'same as  stored date
                      ST.wMinute    = FIS.tmu_date.tm_min                             '
                      ST.wHour      = FIS.tmu_date.tm_hour                            '
                      ST.wDay       = FIS.tmu_date.tm_mday                            '
                      ST.wMonth     = FIS.tmu_date.tm_mon + 1                         '
                      ST.wYear      = FIS.tmu_date.tm_year                            '
                      SystemTimeToFileTime ST, FT                                     '
                      SetFileTime hWinFile, FT, FT, FT                                '
                      FileTimeToSystemTime FT, ST
                      Incr fCnt                                                       '
                      LV_SetItemText fCnt, 0, Path
                      LV_SetItemText fCnt, 1, Format$(ST.wMonth,"00") + "/" + Format$(ST.wDay,"00") + "/" + (Format$(ST.wYear,"0000"))
                      LV_SetItemText fCnt, 2, Format$(St.wHour,"00") + ":" + Format$(ST.wMinute,"00")+ ":" + Format$(ST.wSecond,"00")
                      LV_SetItemText fCnt, 3, Format$(FIS.Uncompressed_Size, "#,")
                      LV_SetItemText fCnt, 4, Format$(FIS.Compressed_Size, "#,")
                    End If                                                            '
                    dwRet = UnzGotoNextFile(hZip)                                     '
                  Wend                                                                '
                UnzClose hZip                                                         '
                End If                                                                '
                Function = fCnt                                                       '
              End Function                                                            '
              
              '--------------------------------------------------------------------------------
              Function PBMain()
                  ShowDIALOG1 %HWND_Desktop
              End Function
              
              '--------------------------------------------------------------------------------
              Function AttachMENU1(ByVal hDlg As Dword) As Dword
                  Local hMenu As Dword, hPopUp1 As Dword
              
                  Menu New Bar To hMenu
                  Menu New PopUp To hPopUp1
                  Menu Add PopUp, hMenu, "File", hPopUp1, %MF_Enabled
                      Menu Add String, hPopUp1, "Open", %IDM_FILE_OPEN, %MF_Enabled
                      Menu Add String, hPopUp1, "Exit", %IDM_FILE_EXIT, %MF_Enabled
                  Menu Attach hMenu, hDlg
                  Function = hMenu
              End Function
              
              '--------------------------------------------------------------------------------
              CallBack Function ShowDIALOG1Proc()
                Local Rw As Long, Cl As Long, lString As String, lzStr As AsciiZ * %Max_Path, lRet As Long
                Select Case CbMsg
                  Case %WM_Command
                    Select Case CbCtl
                      Case %IDC_SYSLISTVIEW32_1
                      Case %IDM_FILE_OPEN
                        lString = "*.zip"
                        If OpenFileDialog(hDlg, "Zip archive location:", lString, CurDir$, "Zip archives|*.zip", "", _
                                %OFN_NoValidate Or %OFN_HideReadOnly) Then
                          For Rw = 1 To 300
                            For Cl = 0 To 6
                              LV_SetItemText Rw, Cl, ""
                            Next
                          Next
                          lzStr = lString
                          lRet = GetFileNames (lzStr)
                          MsgBox Format$(lRet) & " files in zip",,"Info"
                        End If
                      Case %IDM_FILE_EXIT
                        Dialog End CbHndl
                    End Select
                End Select
              End Function
              
              '--------------------------------------------------------------------------------
              Function SampleListView(ByVal hDlg As Dword, ByVal lID As Long, ByVal lColCnt As _
                  Long, ByVal lRowCnt As Long) As Long
                  Local lStyle  As Long
                  Local tLVC    As LV_COLUMN
                  Local tLVI    As LV_ITEM
                  Local szBuf   As AsciiZ * 32
                  Local lCol    As Long
                  Local lRow    As Long
                  Local hCtl    As Dword
              
                  Control Handle hDlg, lID To hCtl
              
                  lStyle = ListView_GetExtendedListViewStyle(hCtl)
                  ListView_SetExtendedListViewStyle hCtl, _
                      lStyle Or %LVS_Ex_FullRowSelect Or %LVS_Ex_GridLines
              
                  'Load column headers.
                  tLVC.mask    = %LVCF_FMT Or %LVCF_TEXT Or %LVCF_SUBITEM
                  tLVC.fmt     = %LVCFMT_LEFT
                  tLVC.pszText = VarPtr(szBuf)
              
                  tLVC.iOrder = 0
                  szBuf = "Extracted file name and path"
                  ListView_InsertColumn hCtl, 0, tLVC
              
                  tLVC.iOrder = 1
                  szBuf = "File date"
                  ListView_InsertColumn hCtl, 1, tLVC
              
                  tLVC.iOrder = 2
                  szBuf = "File time"
                  ListView_InsertColumn hCtl, 2, tLVC
              
                  tLVC.iOrder = 3
                  szBuf = "File size"
                  ListView_InsertColumn hCtl, 3, tLVC
              
                  tLVC.iOrder = 4
                  szBuf = "Packed"
                  ListView_InsertColumn hCtl, 4, tLVC
              
                  For lRow = 0 To lRowCnt - 1
                      tLVI.stateMask   = %LVIS_FOCUSED
                      tLVI.pszText     = VarPtr(szBuf)
                      tLVI.iItem       = lRow
                      For lCol = 0 To lColCnt - 1
                          szBuf           = ""
                          tLVI.iSubItem   = lCol
                          tLVI.lParam     = lRow
                          If lCol = 0 Then
                              tLVI.mask = %LVIF_TEXT Or %LVIF_PARAM Or %LVIF_STATE
                              ListView_InsertItem hCtl, tLVI
                          Else
                              tLVI.mask = %LVIF_TEXT
                              ListView_SetItem hCtl, tLVI
                          End If
                      Next lCol
                  Next i
              
                  ListView_SetColumnWidth hCtl, 0, 250
                  ListView_SetColumnWidth hCtl, 1, 80
                  ListView_SetColumnWidth hCtl, 2, 60
                  ListView_SetColumnWidth hCtl, 3, 80
                  ListView_SetColumnWidth hCtl, 4, 80
              
              End Function
              '--------------------------------------------------------------------------------
              
              '--------------------------------------------------------------------------------
              '   ** Dialogs **
              '--------------------------------------------------------------------------------
              Function ShowDIALOG1(ByVal hParent As Dword) As Long
                  Local lRslt As Long, szPtr As AsciiZ Ptr
              
                InitCommonControls
                Local Icc As Init_Common_ControlsEx
                Icc.dwSize = SizeOf(Icc)
                Icc.dwIcc = %ICC_DATE_CLASSES Or %ICC_BAR_CLASSES Or %ICC_LISTVIEW_CLASSES
                InitCommonControlsEx Icc
              
                Dialog New hParent, "ZLib version " & ZLibVersion, , , 392, 176, To hDlg
                Control Add "SysListView32", hDlg, %IDC_SYSLISTVIEW32_1, "SysListView321", _
                    5, 5, 385, 155, %WS_Child Or %WS_Visible Or %WS_Border Or %WS_TabStop _
                    Or %LVS_Report Or %LVS_ShowSelAlways, %WS_Ex_Left Or _
                    %WS_Ex_RightScrollbar
                Control Handle hDlg, %IDC_SYSLISTVIEW32_1 To hLView
                AttachMENU1 hDlg
                SampleListView hDlg, %IDC_SYSLISTVIEW32_1, 5, 300
                Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                Function = lRslt
              End Function
              '--------------------------------------------------------------------------------
              Regards,
              Peter

              Comment

              Working...
              X