Page 1 of 1

Posted: Sun Dec 01, 2002 10:58 am
by BackupUser
Restored from previous forum. Originally posted by freak.

Hi all,

I'm trying to implement Zip support in one of my programs, but
it doesn't work.

i'm trying to use the Info-Zip dll, as it is the only free one i've found. Get it from here:

ftp://ftp.info-zip.org/pub/infozip/WIN32/unz550dN.zip

I only need to use these two functions of it:

Wiz_SingleEntryUnzip()
Wiz_UnzipToMemory()

But those C examples only confused me. Please can anyone who knows some C post a short example?

For getting the names of the zipped Files, I wrote my own Procedure,
but the compression stuff was to complicated for me.

Any Help would be nice, since I am around this problem for some time now.

Thanks,

Timo

************ Here's my code for getting the names: ****************

Code: Select all

; ***** Show entrys of a Zip-File ******
; by Timo Harter
 
#LocalHeader   = $04034B50
#CentralHeader = $02014B50

#ZipMemoryBank = 999
#ZipFileNumber = 999

#ZipFileError  = -1

Structure ZipFileEntrys
  Filename.s
  Filename_Path.s
  Size_Comp.l
  Size_Uncomp.l
EndStructure

NewList ZipFile.ZipFileEntrys()

Declare.l ReadZipFile(Filename.s)

;***********************************************************************
  
  
  
Filename.s = OpenFileRequester("Choose Zip file...", "c:\temp2\*.zip", "Zip-Files|*.zip", 0) 
If Filename = "": End: EndIf
  
If ReadZipFile(Filename) = #ZipFileError
  MessageRequester("Zip","Error!",0)
Else
  OpenConsole()
  ConsoleTitle("ZIP")
  ResetList(ZipFile())
  While NextElement(ZipFile())
    PrintN(ZipFile()\Filename_Path)
  Wend
  Input()
  CloseConsole()
EndIf
  
End

  
  
  
;***********************************************************************

Procedure.l ReadZipFile(Filename.s)
  Protected ZipID.l, ZipSize.l, Offset.l, FilesFound.l, Temp.l, Size.l
    
  If ReadFile(#ZipFileNumber, Filename)
    If ReadLong() = #LocalHeader
      FileSeek(0)
      ZipSize = Lof()
      ZipID = AllocateMemory(#ZipMemoryBank, ZipSize)
      If ZipID
        ReadData(ZipID, ZipSize)
        CloseFile(#ZipFileNumber)
      Else
        CloseFile(#ZipFileNumber)
        ProcedureReturn #ZipFileError
      EndIf
    Else
      CloseFile(#ZipFileNumber)
      ProcedureReturn #ZipFileError
    EndIf
  Else
    ProcedureReturn #ZipFileError
  EndIf
   
  ClearList(ZipFile())
  For Offset = ZipID To ZipID+ZipSize-4
    Temp = PeekL(Offset)
    If Temp = #LocalHeader
      FilesFound+1
      AddElement(ZipFile())
      ZipFile()\Size_Comp = PeekL(Offset+18)
      ZipFile()\Size_Uncomp = PeekL(Offset+22)
      Size = PeekW(Offset+26)   
      ZipFile()\Filename_Path = PeekS(Offset+30, Size)
      ZipFile()\Filename = ZipFile()\Filename_Path
      For Temp = Len(ZipFile()\Filename_Path) To 1 Step -1
        If Mid(ZipFile()\Filename_Path, Temp, 1) = "/"
          ZipFile()\Filename = Right(ZipFile()\Filename_Path, Len(ZipFile()\Filename_Path)-Temp)
          Temp = 1
        EndIf
      Next Temp
      Size + PeekW(Offset+28) + ZipFile()\Size_Comp + 29
      Offset+Size
    ElseIf Temp = #CentralHeader
      Offset = ZipID+ZipSize-4
    EndIf
  Next Offset
    
  FreeMemory(#ZipMemoryBank)
  ProcedureReturn FilesFound
EndProcedure