FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour HB_UnzipFile()
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
HB_UnzipFile()
Posted: Sat Feb 11, 2017 04:33 PM
Hi,

HB_UnzipFile () does not work correctly if your zip file contains files and directories.

Thanks to Juan Kazmirchuk, this function fix the problem.

Code (fw): Select all Collapse
//-----------------------------------------------------------------------------
// Juan Kazmirchuk
//-----------------------------------------------------------------------------
FUNCTION my_UnZipFile( cFile, bBlock, lWithPath, cPassword, cPath )
  LOCAL lZip
  LOCAL nI
  LOCAL aFiles   := { }
  LOCAL aFolders := { }
  LOCAL nfiles := 0


  // Get files in ZIP
  aFiles := hb_GetFilesInZip( cFile )
  nFiles := len(aFiles)
  // Get folders in ZIP and create at cPath
  FOR nI := 1 TO nFiles

    IF ! HB_DirExists( HB_DirSepToOS( HB_FNameDir( aFiles[nI] ) ) )

      HB_DirCreate( HB_DirSepAdd( cPath ) + HB_DirSepToOS( HB_FNameDir( aFiles[nI] ) ) )

    ENDIF

  NEXT

  // Then UnZIP files in Path folder

  lZip := HB_UnZipFile( cFile, ;
                NIL, ;
                .T., ;
                NIL, ;
                cPath, ;
                aFiles )

RETURN lZip


Regards
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 07:02 PM

I never found problems with HB_UnzipFile() using files and directories. Can I see a little sample showing the problem?

EMG

Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 07:24 PM
Hi Enrico,

with this code

Code (fw): Select all Collapse
lZip := HB_UNZIPFILE( cFolder + "\" + cFile,,.T.,,cFolder,aFileZip,NIL )


lzip is TRUE, but files are not uncompressed.

With

Code (fw): Select all Collapse
lZip := my_UnZipFile( cFolder + "\" + cFile,,.t.,,cFolder,aFileZip )


the files and dirextories are uncompressed.

In my case HB_UnzipFile() works perfectly with zip files without directories.

Best regards,
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 09:02 PM

Sorry, I need of a real sample that can be compiled and run here. I cannot reproduce the problem.

EMG

Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 09:40 PM
Enrico,

please compress Fivewin Samples directory.

Code (fw): Select all Collapse
#include "Fivewin.ch"

Function Main()
Local nFilesInZip:= 0
Local aFilesInZip := {}
Local cFile := "samples.zip"

Local lZip
Local cPath := StrCapFirst( cFilePath( GetModuleFileName( GetInstance() ) ) )

nFilesInZIP := LEN(hb_GetFilesInZip(cFile))
aFilesInZip := hb_GetFilesInZip(cFile,.t.)
lZip := HB_UNZIPFILE( cFile,,.T.,,cpath,aFilesInZip,NIL )
if lzip 
  MsgInfo("Fichero descomprimido")
endif
/*
IF my_UnZipFile( cFile,,.t.,,".\",aFilesInZip )
  MsgInfo("Fichero descomprimido")
ENDIF  
*/  
Return NIL

FUNCTION my_UnZipFile( cFile, bBlock, lWithPath, cPassword, cPath )
LOCAL lZip
  LOCAL nI
  LOCAL aFiles   := { }
  LOCAL aFolders := { }
  LOCAL nfiles := 0


  // Get files in ZIP
  aFiles := hb_GetFilesInZip( cFile )
  nFiles := len(aFiles)
  // Get folders in ZIP and create at cPath
  FOR nI := 1 TO nFiles

    IF ! HB_DirExists( HB_DirSepToOS( HB_FNameDir( aFiles[nI] ) ) )

      HB_DirCreate( HB_DirSepAdd( cPath ) + HB_DirSepToOS( HB_FNameDir( aFiles[nI] ) ) )

    ENDIF

  NEXT

  // Then UnZIP files in Path folder

  lZip := HB_UnZipFile( cFile, ;
                NIL, ;
                .T., ;
                NIL, ;
                cPath, ;
                aFiles )

RETURN lZip


Best regards
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 10:03 PM
This sample works fine here (latest xHarbour and FWH):

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL cZip := "samples.zip"

    ? HB_UNZIPFILE( cZip, , .T., , CURDRIVE() + ":\" + CURDIR(), HB_GETFILESINZIP( cZip ) )

    RETURN NIL


EMG
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 10:21 PM

Enrico,

i use Harbour. Your sample not work in Harbour. Perhaps, the problem is in Harbour's libs.

Regards

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 10:27 PM
Baxajaun wrote:Enrico,

i use Harbour. Your sample not work in Harbour. Perhaps, the problem is in Harbour's libs.

Regards


Please try my sample using pure Harbour (no FWH) and tell me if it works.

EMG
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 10:43 PM

Enrico,

is not works.

Regards

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sat Feb 11, 2017 10:48 PM

Ok, so it's Harbour. Anybody can report this to the Harbour developers?

EMG

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: HB_UnzipFile()
Posted: Sun Feb 12, 2017 03:04 AM

Please see

viewtopic.php?f=6t=30003p=175748hilit=hb_UnzipFile#p175748

I published a revised function fixing the problems in Harbour

&&&

Regards



G. N. Rao.

Hyderabad, India
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: HB_UnzipFile()
Posted: Sun Feb 12, 2017 06:30 AM

Thanks a lot Mr. Rao !

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: HB_UnzipFile()
Posted: Sun Feb 12, 2017 09:43 AM

I think it would be better to fix the problem in Harbour.

EMG

Continue the discussion