Does any one know how to save directory information with files compressed using zlibstat. I have looked for a manual for the library but was unable to find one. I want to be able to recurse a folder zipping all of the contents. The recursive part is easy enough and zipping each file as well but the resulting zip file does not contain any folder information so the file all unzip to the root folder.

Folder zip rotuine, the recursion proc sends the folder names to this proc one at a time...

FolderZip FRAME pszFolder
LOCAL hFind :D
LOCAL w32fd :WIN32_FIND_DATA

invoke SetCurrentDirectory,
invoke FindFirstFile,"*.*",offset w32fd

test eax,eax
jns >
ret
:
mov ,eax

:
mov eax,
cmp al,"."
je >.skip
invoke AddFileToZip,offset w32fd.cFileName
.skip
invoke FindNextFile,,offset w32fd
test eax,eax
jnz <

invoke FindClose,

RET
ENDF


The actual zip routine...

AddFileToZip FRAME pszFileName
uses ebx, esi, edi
LOCAL buffer :B
LOCAL hFile2Zip :D
LOCAL ftw :FILETIME
LOCAL ftl :FILETIME
LOCAL fatdate :D
LOCAL zipfi :zip_fileinfo
LOCAL gMem :D
LOCAL cbRead :D

invoke CreateFile,,GENERIC_READ or GENERIC_WRITE, \
FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0
test eax,eax
js >>.INVALID_HANDLE_VALUE
mov ,eax
invoke GetFileTime,,0,0,addr ftw
invoke FileTimeToLocalFileTime,addr ftw,addr ftl
invoke FileTimeToDosDateTime,addr ftl,addr fatdate+2 ,addr fatdate
push
pop
mov esi,
lea edi,buffer

mov ecx,"/"
L2:
mov al,
cmp al,"\"
cmove eax,ecx
mov ,al
inc edi,esi
test al,al
jnz <L2

invoke zlib:zipOpenNewFileInZip,,addr buffer,addr zipfi, \
0,0,0,0,0,Z_DEFLATED,Z_DEFAULT_COMPRESSION

invoke GetFileSize,,0
mov ebx,eax
test eax,eax
jz >>.EMPTYFILE
invoke GlobalAlloc,GMEM_FIXED,ebx
mov ,eax
:
invoke ReadFile,,,ebx,addr cbRead,0
cmp D,0
jz >
invoke zipWriteInFileInZip,,, ;write block
jmp <
:
invoke GlobalFree,
.EMPTYFILE
invoke zlib:zipCloseFileInZip,
.INVALID_HANDLE_VALUE

ret

ENDF


Any help would be appreciated,

Donkey
Posted on 2006-06-10 22:14:32 by donkey
Worst come to worst you could build a batchfile which can reconstruct the directory by moving files after unpacking them - and then shove that batchfile in the zip too.
I dunno, I haven't used that lib, however there's 1000 ways to skin a cat.
Posted on 2006-06-10 23:34:08 by Homer
Sorry,

My stupidity and laziness. I used SetCurrentDirectory in order to avoid having to build fully qualified paths, if I had done that I would have noticed that in sending the full path to zlibstat it automatically adds the directory information. Well I guess I can make it optional now as well :)

Donkey
Posted on 2006-06-10 23:46:24 by donkey
http://www.codeproject.com/cpp/zip.asp

The source there covers everything.
Posted on 2006-06-10 23:48:00 by Homer