Descargaros los fuentes y obteneis las dlls. Tambien teneis que utilizar los fichero .h que se incluyen en la sección #pragma BEGINDUMP
El ejemplo que seguro no funciona del todo correctamente pero ayudará en el camino hacia el exito, es este:
Code: Select all
#include "fivewin.ch"
function main()
local oWnd
local oMenu
MENU oMenu
MENUITEM "Zip" ACTION Test()
ENDMENU
DEFINE WINDOW oWnd TITLE "Prueba de ventana" MENU oMenu
ACTIVATE WINDOW oWnd MAXIMIZED
return nil
function test()
local oDlg
local oLbx1
local oLbx2
local oMeter
local oAdd, oOut, oName, oComprimir, oIn, oNameIn, oExtract
local cFileOut := space( 300 )
local cFileIn := space( 300 )
local aItems1 := {}
local aItems2 := {}
local cItem := ""
local nPercent := 0
DEFINE DIALOG oDlg NAME "IDD_ABOUTBOX"
REDEFINE GET oIn VAR cFileIn ID 101 OF oDlg
REDEFINE BUTTON oNameIn ID 102 OF oDlg ACTION SelName( oIn )
REDEFINE LISTBOX oLbx1 VAR cItem ITEMS aItems1 ID 103 OF oDlg
REDEFINE BUTTON oExtract ID 104 OF oDlg ACTION Abrir( cFileIn, oLbx1, oMeter )
REDEFINE GET oOut VAR cFileOut ID 105 OF oDlg
REDEFINE BUTTON oName ID 106 OF oDlg ACTION SelName( oOut )
REDEFINE LISTBOX oLbx2 VAR cItem ITEMS aItems2 ID 107 OF oDlg
REDEFINE BUTTON oAdd ID 108 OF oDlg ACTION Add( oLbx2 )
REDEFINE BUTTON oComprimir ID 109 OF oDlg ACTION Comprimir( oLbx2, oOut, oMeter )
REDEFINE METER oMeter VAR nPercent TOTAL 100 ID 110 OF oDlg
ACTIVATE DIALOG oDlg CENTERED
return nil
/////////////////////////////////////////////////////////////////////////////
static function Abrir( cFileName, oLbx, oMeter )
/////////////////////////////////////////////////////////////////////////////
local n
local hUnz
local aInfo
local nItems
local cFile
local cCurDir := curdrive() + ":\" + curdir() + "\"
cFileName := alltrim( cFileName )
if empty( cFileName )
MsgStop( "Debe indicar un nombre de fichero" )
return 0
endif
if !File( cFileName )
MsgStop( "No se encuentra el fichero:" + CRLF + CRLF + cFileName )
return 0
endif
hUnz := UnzipOpenFile( cFileName )
aInfo := UnzipGetItem( hUnz, -1 )
nItems := aInfo[2]
oMeter:SetTotal( nItems )
for n := 0 to nItems-1
aInfo := UnzipGetItem( hUnz, n )
if !empty( aInfo )
cFile := aInfo[7]
if lower( cCurdir ) $ lower( cFile )
cFile := substr( cFile, len( cCurDir )+1 )
endif
cFile := alltrim( cFile )
oLbx:Add( cFile )
endif
oMeter:Set( n )
next
UnzipClose()
return nil
/////////////////////////////////////////////////////////////////////////////
static function Add( oLbx )
/////////////////////////////////////////////////////////////////////////////
local aFiles := cGetFileEx( "*.*", "Seleccione ficheros" )
local n
if empty( aFiles )
return 0
endif
if valtype( aFiles ) == "C"
aFiles := {aFiles}
endif
for n := 1 to len( aFiles )
oLbx:Add( aFiles[n] )
next
return nil
/////////////////////////////////////////////////////////////////////////////
static function SelName( oGet, lLoad )
/////////////////////////////////////////////////////////////////////////////
local cFileName
if lLoad == nil; lLoad := .f.; endif
cFileName := cGetFile( "*.zip",if( lLoad, "Seleccione fichero","Guardar como..."), 1, , lLoad )
if empty( cFileName )
MsgInfo( "Proceso cancelado","Atención")
return 0
endif
if lLoad .and. !( "." $ cFileName )
cFileName += ".zip"
endif
oGet:cText := cFileName
oGet:Refresh()
if lLoad
endif
return 0
/////////////////////////////////////////////////////////////////////////////
static function Comprimir( oLbx, oGet, oMeter )
/////////////////////////////////////////////////////////////////////////////
local cFileName
local n
local nLen := oLbx:Len()
local hZip
local cFile
if nLen <= 0
MsgStop( "Debe seleccionar ficheros para comprimir","Atención")
return 0
endif
cFileName := alltrim(oGet:cText)
if empty( cFileName )
MsgStop( "Debe indicar el nombre de un fichero valido","Atención")
return 0
endif
if !( "." $ cFileName )
cFileName += ".zip"
endif
oMeter:SetTotal( nLen )
hZip := ZipCreateFile( cFileName )
for n := 1 to nLen
cFile := oLbx:aItems[n]
ZipAddFile( hZip, cFileName( cFile ), cFile )
oMeter:Set(n)
next
ZipClose( hZip )
MsgInfo( "Proceso concluido" )
return nil
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
#include <shlobj.h>
#include <stdlib.h>
#include "j:\litezip.h"
#include "j:\liteunzip.h"
static far char IniDir[] = ".\\";
static char szDirName[ MAX_PATH ];
static far char Title[] = "Select the file";
#define S_ARRAY 0x8000
HB_FUNC( ZIPCREATEFILE )
{
HZIP hz;
hb_retnl((long)ZipCreateFile(&hz, hb_parc( 2 ),0); // ,0 es la pwd
hb_stornl( (long)hz, 1 );
}
HB_FUNC( ZIPADDFILE )
{
HZIP hz = (HZIP) hb_parnl( 1 );
hb_retnl( ZipAddFile( hz, hb_parc( 2 ), hb_parc( 3 )));
}
HB_FUNC( ZIPCLOSE )
{
hb_retnl( ZipClose((HZIP) hb_parnl( 1 )));
}
HB_FUNC( UNZIPOPENFILE )
{
HUNZIP huz;
hb_retnl( (long) UnzipOpenFile(&huz, hb_parc( 1 ),0); // ,0 es la pwd
hb_stornl((long) huz, 1 );
}
HB_FUNC( UNZIPGETITEM )
{
HUNZIP huz = (HUNZIP) hb_parnl( 1 );
ZIPENTRY ze;
SYSTEMTIME stUTC;
char lpszString[MAX_PATH];
ZeroMemory( &ze, sizeof( ZIPENTRY ));
if( hb_pcount() > 1 )
{
ze.Index = (DWORD) hb_parni( 2 );
}
UnzipGetItem( huz, &ze );
hb_reta( 7 );
hb_stornl( (long) &ze, -1, 1 );
hb_storni( (int) ze.Index, -1, 2 );
hb_storni( (int) ze.Attributes, -1, 3 );
FileTimeToSystemTime(&ze.ModifyTime,&stUTC);
wsprintf(lpszString, "%02d/%02d/%d %02d:%02d", stUTC.wDay, stUTC.wMonth, stUTC.wYear, stUTC.wHour, stUTC.wMinute);
hb_storc( lpszString, -1, 4 );
hb_stornl( ze.CompressedSize, -1, 5 );
hb_stornl( ze.UncompressedSize, -1, 6 );
hb_storc( ze.Name, -1, 7 );
}
HB_FUNC( UNZIPITEMTOFILE )
{
HUNZIP huz = (HUNZIP) hb_parnl( 1 );
UnzipItemToFile( huz, hb_parc( 2 ), (ZIPENTRY*) hb_parnl( 3 ) );
hb_ret();
}
HB_FUNC( UNZIPCLOSE )
{
UnzipClose( (HUNZIP) hb_parnl( 1 ));
hb_ret();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
HB_FUNC ( CGETFILEEX )
{
OPENFILENAME ofn;
char buffer[65536];
char cFullName[64][1024];
char cCurDir[512];
char cFileName[512];
int iPosition = 0;
int iNumSelected = 0;
int n;
LPSTR pFile,pFilter,pTitle,pDir;
WORD w = 0, wLen;
int flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER ; // | OFN_FILEMUSTEXIST
buffer[0] = 0 ;
// alloc for title
pTitle = ( LPSTR ) hb_xgrab( 128 );
if ( hb_pcount() > 1 && ISCHAR( 2 ) )
{
wLen = min( ( unsigned long ) 127, hb_parclen( 2 ) );
CopyMemory( pTitle, hb_parc( 2 ), wLen );
* ( pTitle + wLen ) = 0;
}
else
{
pTitle = Title;
}
// alloc for initial dir
pDir = ( LPSTR ) hb_xgrab( 128 );
if ( hb_pcount() > 3 && ISCHAR( 4 ) )
{
wLen = min( ( unsigned long ) 127, hb_parclen( 4 ) );
CopyMemory( pDir, hb_parc( 4 ), wLen );
* ( pDir + wLen ) = 0;
}
else
{
* ( pDir ) = 0;
}
// alloc for file
pFile = ( LPSTR ) hb_xgrab( 255 );
if ( hb_pcount() > 7 && ISCHAR( 8 ) )
{
wLen = min( ( unsigned long ) 254, hb_parclen( 8 ) );
CopyMemory( pFile, hb_parc( 8 ), wLen );
}
else
{
wLen = min( ( unsigned long ) 254, hb_parclen( 1 ) );
CopyMemory( pFile, hb_parc( 1 ), wLen );
}
* ( pFile + wLen ) = 0;
// alloc for mask
pFilter = ( LPSTR ) hb_xgrab( 400 );
wLen = min( ( unsigned long ) 398, hb_parclen( 1 ) );
CopyMemory( pFilter, hb_parc( 1 ), wLen );
* ( pFilter + wLen ) = 0;
#ifndef __FLAT__
// _xunlock();
#endif
while( * ( pFilter + w ) )
{
if( * ( pFilter + w ) == '|' )
{
* ( pFilter + w ) = 0;
if ( hb_pcount() < 8 )
* (pFile) = 0;
}
w++;
}
* ( pFilter + wLen ) = 0;
* ( pFilter + wLen + 1 ) = 0;
if( hb_pcount() == 8 )
strcpy( buffer, hb_parc(8));
memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = GetActiveWindow();
ofn.lpstrFilter = pFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = buffer;
ofn.nMaxFile = sizeof(buffer);
ofn.lpstrInitialDir = hb_parc(3);
ofn.lpstrTitle = pTitle;
ofn.nMaxFileTitle = 512;
ofn.Flags = flags;
if( GetOpenFileName( &ofn ) )
{
if(ofn.nFileExtension!=0)
{
hb_retc( ofn.lpstrFile );
}
else
{
wsprintf(cCurDir,"%s",&buffer[iPosition]);
iPosition=iPosition+strlen(cCurDir)+1;
do
{
iNumSelected++;
wsprintf(cFileName,"%s",&buffer[iPosition]);
iPosition=iPosition+strlen(cFileName)+1;
wsprintf(cFullName[iNumSelected],"%s\\%s",cCurDir,cFileName);
}
while( (strlen(cFileName)!=0) && ( iNumSelected <= 63 ) );
if(iNumSelected > 1)
{
hb_reta( iNumSelected - 1 );
for (n = 1; n < iNumSelected; n++)
{
hb_storc( cFullName[n], -1, n );
}
}
else
{
hb_retc( &buffer[0] );
}
}
}
else
{
hb_retc( "" );
}
}
// del msdn
INT CALLBACK BrowseCallbackProc(HWND hwnd,
UINT uMsg,
LPARAM lp,
LPARAM pData)
{
switch(uMsg)
{
case BFFM_INITIALIZED:
if (szDirName)
{
// WParam is TRUE since you are passing a path.
// It would be FALSE if you were passing a pidl.
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDirName);
}
break;
}
return 0;
}
#pragma ENDDUMP
/*
prueba.rc
IDD_ABOUTBOX DIALOG 61, 128, 572, 280
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Zip - UnZip"
FONT 8, "MS Sans Serif"
{
LTEXT "Fichero de origen:", -1, 16, 17, 104, 8
EDITTEXT 101, 16, 30, 242, 14, ES_AUTOHSCROLL
PUSHBUTTON "...", 102, 262, 30, 16, 14
LISTBOX 103, 16, 54, 242, 140, LBS_STANDARD
PUSHBUTTON "Abrir", 104, 210, 203, 50, 14
LTEXT "Fichero de destino:", -1, 299, 17, 104, 8
EDITTEXT 105, 299, 30, 242, 14, ES_AUTOHSCROLL
PUSHBUTTON "...", 106, 545, 30, 16, 14
LISTBOX 107, 299, 54, 242, 140, LBS_STANDARD
PUSHBUTTON "...", 108, 545, 177, 16, 14
PUSHBUTTON "Comprimir", 109, 492, 203, 50, 14
CONTROL "", 110, "TMeter", 0 | WS_CHILD | WS_VISIBLE, 17, 229, 520, 3
DEFPUSHBUTTON "OK", 1, 492, 256, 50, 14
}
*/
En los ficheros hay uno en concreto que arroja algo de luz, a falta de documentación es "vb.txt" donde indica mas o menos lo que recibe cada parámetro.
Yo lo he enlazado con VC.
Hay que enlazar las libs correspondientes para poder llamar a las funciones de la dll
Si estais con Borland, creo que se pueden sacar las libs de una dll con implib. Esto no lo tengo muy seguro.
Creo que esto solucionaría en gran parte el problema de harbour con los zips.