ZIP / UNZIP under Fivewin

ZIP / UNZIP under Fivewin

Postby Jimmy » Tue Mar 21, 2023 1:33 am

hi,

i want to ZIP / UNZIP Files using Fivewin

in TWindows i found Codeblock Slot bZip and bUnZip
Code: Select all  Expand view
  METHOD Zip( nZipInfo ) INLINE ;
                      If( ::bZip != nil, Eval( ::bZip, nZipInfo ),)

   METHOD UnZip( nPercent ) INLINE ;
                      If( ::bUnZip != nil, Eval( ::bUnZip, nPercent ),)

---

there is a Sample c:\fwh\samples\testuzip.prg which use Codeblock bUnZip
Sample c:\fwh\samples\testzip.prg use Hb_ZIPFILE() but not Codeblock bZip

so how to use Codeblock bZip :?:

both Sample use METER and Parameter nPercent / nZipInfo seem to belong to METER
can i use a "green" Windows Progressbar instead of METER :?:

---

"why" are bZip / bUnZip and Method Zip / UnZip implement in CLASS TWindow :?:

if Argument is that Window have Zip / Unzip since XP than Method should use "same" Way as Explorer and not "external"

this i use under harbour / HMG

Code: Select all  Expand view
FUNCTION Unzip( cZipFile, cDestFolder )
LOCAL oShell, oZIP, oNameDest

   oShell := CreateObject( "Shell.Application" )
   oZIP := oShell:NameSpace( cZipFile )
   oNameDest := oShell:NameSpace( cDestFolder )
   oNameDest:CopyHere( oZIP:items(), 0x10 )

   oShell := NIL

RETURN NIL


Code: Select all  Expand view
FUNCTION ZIPFILE( cZipFile, aFiles, hGrid, aSourceNum )
LOCAL aHead   := { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
LOCAL nHandle
LOCAL i, imax
LOCAL oShell
LOCAL oZIP
LOCAL oSource
LOCAL cPath
LOCAL nCount  := 0
LOCAL xCount  := 0
LOCAL nFiles  := 0
LOCAL nPosi   := 0
LOCAL oItems
LOCAL xFlag
LOCAL cFile
LOCAL cTemp

   xFlag := FOF_NOCONFIRMATION + ;
            FOF_NOCONFIRMMKDIR + ;
            FOF_RENAMEONCOLLISION + ;
            FOF_SIMPLEPROGRESS

   // delete old ZIP file
   IF FILE( cZipFile )
      FERASE( cZipFile )
   ENDIF

   // create ZIP and write Header
   nHandle := FCREATE( cZipFile, FC_NORMAL )
   iMax := LEN( aHead )
   FOR i := 1 TO iMax
      FWRITE( nHandle, CHR( aHead[ i ] ) )
   NEXT
   FCLOSE( nHandle )

   // create COM Object
   oShell := CreateObject( "Shell.Application" )
   oZIP := oShell:NameSpace( cZipFile )

   // now add files
   nFiles := LEN( aFiles )
   IF nFiles > 1
      xFlag += FOF_MULTIDESTFILES
   ENDIF

   FOR i := 1 TO nFiles
      cFile := aFiles[ i ]
      IF FILE( cFile )
         cFile += CHR( 0 )
         oZIP:CopyHere( cFile, xFlag )                                // copy one file

         // wait until all file are written
         xCount := 0
         DO WHILE .T.
            nCount := oZIP:items() :Count()
            IF nCount >= i
               EXIT
            ENDIF
            hb_idleSleep( 0.1 )
            xCount ++
            IF xCount > 50
               EXIT
            ENDIF
         ENDDO
      ENDIF
      DO EVENTS
   NEXT
   hb_idleSleep( 1.0 )

   // clean up
   oZIP := NIL
   oShell := NIL

   // just show Msg 1 Sec.
   INKEY( 1 )

RETURN NIL
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: ZIP / UNZIP under Fivewin

Postby Antonio Linares » Tue Mar 21, 2023 8:05 am

Dear Jimmy,

> "why" are bZip / bUnZip and Method Zip / UnZip implement in CLASS TWindow

Because the main window is the one that receives those notifications
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ZIP / UNZIP under Fivewin

Postby Jimmy » Tue Mar 21, 2023 8:34 am

hi Antonio,
Antonio Linares wrote:Because the main window is the one that receives those notifications

aaah ... i begin to understand Concept

but Fivewin have no "build-in" Function, or :?:

---

in *.MAK are
echo $(HBDIR)\lib\win\bcc\hbziparc.lib + >> b32.bc
echo $(HBDIR)\lib\win\bcc\hbmzip.lib + >> b32.bc
echo $(HBDIR)\lib\win\bcc\hbzlib.lib + >> b32.bc
echo $(HBDIR)\lib\win\bcc\minizip.lib + >> b32.bc

so which should i use :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: ZIP / UNZIP under Fivewin

Postby karinha » Tue Mar 21, 2023 11:34 am

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: ZIP / UNZIP under Fivewin

Postby Jimmy » Tue Mar 21, 2023 12:59 pm

karinha wrote:all. see this example:.

thx for Links.

have look at it and found Hb_ZIPFILE()

it does "collect" Files "recursive" for "D"irectory

---

for Backup i use Attribute "A" which i got from "Everything"

---

to ZIP a hole Folder you can use this Function
Code: Select all  Expand view
 // create ZIP for hole Folder "c:\fwh\samples\"
  ZIPFILE("C:\TEMP\TEST1.ZIP""c:\fwh\samples\")

Code: Select all  Expand view
FUNCTION ZIPFILE(cZipFile,  cDestFolder)
LOCAL oShell,oNameSrc,oNameDest, nFiles

   oShell    := CreateObject("Shell.Application")
   oNameSrc  := oShell:NameSpace(cZipFile)

   oNameDest := oShell:NameSpace(cDestFolder)
   nFiles :=  oNameDest:items():Count()
   oNameSrc:CopyHere(oNameDest:items(), nOr(FOF_NOCONFIRMATION,FOF_NOCONFIRMMKDIR,FOF_SIMPLEPROGRESS))

#ifdef __XPP__
   oNameDest:destroy()
   oNameSrc:destroy()
   oShell:destroy()
#else
   oNameDest := NIL
   oNameSrc := NIL
   oShell := NIL
#endif
RETURN NIL
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: ZIP / UNZIP under Fivewin

Postby Jimmy » Wed Mar 22, 2023 8:02 am

hi,

i have now use Hb_ZIPFILE() where i want to get all Files under c:\fwh\samples\

Code: Select all  Expand view
  lRet := HB_ZIPFILE( cTargetDir + cTargetZIP, acFiles,, { | cFile, nPos | NIL  }, .T.,, lWithPath )


i have made acFiles "recursive" and got "full-path-Filename"
Code: Select all  Expand view
PROCEDURE AddMoreDir( cNewdir,acFiles,acAttr)
LOCAL aDir := My_DIRECTORY( cNewdir + "*.*", "DHS" )
LOCAL ii, iMax := LEN(aDir)
LOCAL nStartAt := 1
LOCAL cFile, cAttr

   // "D"irectry on Top
   ASORT( aDir,,, { | x, y | "D" $ x[ LV_ATTR ] } )
   AEVAL( aDir, { | x, i | nStartAt := IF( "D" $ x[ LV_ATTR ], i, nStartAt ) } )
   ASORT( aDir, 1, nStartAt, { | x, y | LOWER( x[ LV_NAME ] ) < LOWER( y[ LV_NAME ] ) } )

   ASORT( aDir, nStartAt + 1,, { | x, y | ( UPPER( x[ LV_NAME ] ), UPPER( y[ LV_NAME ] ), .T. ) } )

   FOR ii := 1 TO iMax
      cFile := TRIM(  aDir[ii][LV_NAME] )
      cAttr := UPPER( aDir[ii][LV_ATTR] )

      IF cFile == ".." .AND. "D" $ cAttr
      ELSEIF cFile == "." .AND. "D" $ cAttr
      ELSE
         IF "D" $ cAttr
            AddMoreDir( EndwithSlash( cNewdir + cFile ),acFiles,acAttr)
         ELSE
            AADD(acFiles, cNewdir + cFile )
            AADD(acAttr , cAttr)
         ENDIF
      ENDIF
   NEXT
RETURN

this work in general and i got all Files in ZIP

but ZIP File "start" with \fwh and not with \fwh\samples :shock:
how can i create ZIP with HB_ZIPFILE() which begin with "Sub-Directory" instead of Root :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 74 guests