|
When you try to unzip files from a .ZIP with subdirs the unzipping returns an error 0x200 NO FILE. I have found a bug in Xunzip.cpp here:
void EnsureDirectory(const TCHAR *rootdir, const TCHAR *dir)
....
if (lastslash!=dir)
{
TCHAR tmp[MAX_PATH];
_tcsncpy(tmp, dir, lastslash-dir);
tmp[lastslash-dir] = _T('\0');
EnsureDirectory(rootdir,tmp);
name++;
}
TCHAR cd[MAX_PATH];
_tcscpy(cd,rootdir);
// 20-06-2005 COSMOS
// Here was: _tcscat(cd,name); Which isn't correct
// We have to create the last level directory like this:
_tcscat(cd,dir);
CreateDirectory(cd,NULL);
....
Hope this helps.
|
|
|
|
|
Who know how to delete a file from zip archive with these codes, or how to replace an existing file?
thanks .:->
|
|
|
|
|
hi!
i have created two zip files of same test.png file. when i check both zipped files with windiff.exe, they were different. but files inside the zip are same. whereas i did same with WinRAR and created two zip files of same test.png file. when i compared them with windiff.exe they were identical. could u plz tell me why this happens.
Thanks in advance.
Ahmad Jalil Qarshi
|
|
|
|
|
Hi.
I have the need to open an existing zip file, and add files to it...
Is this possible, since OpenZip(..) then ZipAdd(..) fails.
J
|
|
|
|
|
OK -- My bad!
Needed to include windows.h before the xzip.h file(s)
#include <windows.h>
#include "XZip.h"
#include "XUnzip.h"
Soz,
Joe
|
|
|
|
|
Hi Hans,
Good work. We use your class in our software and it works good. I found however that the files inside the ZIP are stamped with UTC time instead of local time.
GetFileInformationByHandle returns UTC times for a file, so they must be converted to local time before writing to Zip file. BTW, contrary to MSDN, my tests showed that GetFileInformationByHandle returns file time in UTC for both FAT and NTFS file system.
So here's a little code that needs to be added to XZip in order to convert file time from UTC to local time. Add it in GetFileInfo function, after GetFileInformationByHandle call. (Line 2189 in XZip.cpp of May 7th, 2003 release).
Thanks.
Damir Valiulin
BY_HANDLE_FILE_INFORMATION bhi;
BOOL res=GetFileInformationByHandle(hf,&bhi);
if (!res)
return ZR_NOFILE;
{
SYSTEMTIME stUTC, stLocal;
GetSystemTime(&stUTC);
GetLocalTime(&stLocal);
FILETIME ftUTC, ftLocal;
SystemTimeToFileTime(&stUTC, &ftUTC);
SystemTimeToFileTime(&stLocal, &ftLocal);
LONG64 uiUTC, uiLocal;
memcpy (&uiUTC, &ftUTC, min(sizeof(LONG64), sizeof(FILETIME)));
memcpy (&uiLocal, &ftLocal, min(sizeof(LONG64), sizeof(FILETIME)));
LONG64 uiTimeDiff = uiUTC - uiLocal;
FILETIME* pFileTimes[3] = { &bhi.ftLastWriteTime, &bhi.ftLastAccessTime, &bhi.ftCreationTime };
for (int i=0; i<3; i++){
LONG64 uiUTC_file;
memcpy (&uiUTC_file, pFileTimes[i], min(sizeof(LONG64), sizeof(FILETIME)));
LONG64 uiLocal_file = uiUTC_file - uiTimeDiff;
memcpy (pFileTimes[i], &uiLocal_file, min(sizeof(LONG64), sizeof(FILETIME)));
}
}
|
|
|
|
|
This is a very useful module! However:
When I add 50,000 small textfiles to a new zip-file, the resulting zip is about 25MB and contains 50,000 files, everything is fine.
When I add 60,000 small textfiles, the resulting zip file is about 8MB contains only 8,000 files, and no errors where reported from the ZipAdd function...
BR/Karl
|
|
|
|
|
Just want to say thanks for a change Good library, very easy to implement in my own and works without problems for my purposes
|
|
|
|
|
|
How to use XZip and XUnzip with password?
|
|
|
|
|
I just started useing the XZip and XUnzip code and ive been unable to find a way to change the compression level is there a way or is it just static? i found a struct that was named configuration_table and it seems to deal with compression levels but i cant figure out where i would change it in the code to make the compression level change.
thanks in advance
Greg
|
|
|
|
|
How do you set it to not readonly when unzipping files?
|
|
|
|
|
Here's solution.
In the file XUnzip.cpp line: 4100 replace:
h = ::CreateFile((const TCHAR*)dst, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, <br />
ze.attr, NULL);
for:
h = ::CreateFile((const TCHAR*)dst, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, <br />
ze.attr ^= FILE_ATTRIBUTE_READONLY, NULL);
|
|
|
|
|
hi !
i used XZip in my project , and its compiling properly.CreateZip is also working fine.However when i try to add a file to it using ZipAdd the program crashes.
its crashing on the following line in ZipAdd :
lasterrorZ = zip->Add(szDest, src, len, flags);
it gave a stack overflow error and crashed.
Any idea what might have gone wrong ?
Thanks for the help in advance
Regards
Kane
"Some guys hack just to get themselves a girlfriend.what a pathetic reason , huh ? "
|
|
|
|
|
kanetheterrible1 wrote:
lasterrorZ = zip->Add(szDest, src, len, flags);
You must have gone to some work to come up with the Add() function, since it isn't in Zip.h!
The correct function - as shown in the demo - is ZipAdd().
Example:
TCHAR * cp = _tcsrchr(lpszSrcFile, _T('\\'));
if (cp == NULL)
cp = (TCHAR *) lpszSrcFile;
else
cp++;
HZIP hz = CreateZip((void *)lpszZipArchive, 0, ZIP_FILENAME);
if (hz)
{
ZRESULT zr = ZipAdd(hz, cp, (void *)lpszSrcFile, 0, ZIP_FILENAME);
CloseZip(hz);
if (zr == ZR_OK)
{
...
|
|
|
|
|
hi !
i know...i used CreateZip () and ZipAdd( ) only. In fact i used the exact code u created in the function Zip( ). I saw thru messageboxes that CreateZip() is working fine, but say , i put a couple of checks , like :
HZIP hz = CreateZip((void *)lpszZipArchive, 0, ZIP_FILENAME); <br />
if (hz) { <br />
MessageBox("I am here");<br />
ZRESULT zr = ZipAdd(hz, cp, (void *)lpszSrcFile, 0, ZIP_FILENAME); <br />
MessageBox("I passed ");<br />
CloseZip(hz);
Then in the output , the messagebox "i am here " is gettign displayed, and then the application is crashing.
Then i went to explore why CreateZip( ) crashed , and then when i went to the function i saw that in the line i mentioned before it is crashing, that is this line : lasterrorZ = zip->Add(szDest, src, len, flags);
now here , zip itself is a member of class TZIP , and i went to look at the function Add() of the class, but didn't understand much of it..actually i am newbie when it comes to zipping/unzipping programatically..so might be sounding a bit stupid here ..
By the way , i am using the class in a COM .dll ..it shouldn't make any difference ..?
Thanks
Regards
Kane
"Some guys hack just to get themselves a girlfriend.What a pathetic reason huh ?"
|
|
|
|
|
kanetheterrible1 wrote:
i am using the class in a COM .dll ..it shouldn't make any difference ..?
I don't know, I haven't tried that. I suggest you create a small test MFC app to test your code. If that works, then it must be the COM dll.
|
|
|
|
|
hi !
It was just as suspected.Xzip is working for MFC apps but failing for the COM .dll .However i fail to see why because a)I am using MFC inside the COM .dll and b) Xzip is supposed to be compaitble with any win32 programs.
Now while fishing through i code , i found out the exact place where it goes wrong :
The ZipAdd( ) is actually calling the function Add( ) of class TZIP , which is trying to add the deflated/stored data in the zip file ( as specified in XZip.cpp, line no 2687 ...the snippet is as follows
ZRESULT writeres=ZR_OK;<br />
if (!isdir && method==DEFLATE) <br />
writeres=ideflate(&zfi);<br />
else if (!isdir && method==STORE) <br />
writeres=istore();<br />
else if (isdir) <br />
csize=0;<br />
iclose();<br />
writ += csize;<br />
if (oerr!=ZR_OK) <br />
return oerr;<br />
if (writeres!=ZR_OK) <br />
return ZR_WRITE;<br /> , now here , the program is crashing excatly on the line writeres=ideflate(&zfi); .Checking with MessageBoxes show that when the function ideflate() is being called , the program is crashing instanty * without * the control being transferred to the ideflate( ) function.The debugger is showing a stack overflow error in the statement.
Now it's working fine in MFC , but there is no real reason why it shouldn't work for a COM which uses MFC. Additionally i noted that even though as we can see we already completed writing the header , and the program crashed only while adding the data , the zip file that is being created , is showing up as a corrupt zip file.
Can you give me any hints as to what can possibly crash the app particularly on that line ?Or what kind of exception handling can be possibly done ?Winzip also uses zip through a com .dll , and they have no problem..so it's either i made a mistake in my com programming , or something is making XZip uncompatible to COM. If you have any idea as to what possibly can make ideflate( ) crash , i could have a closer look.
Thanks again for your time
Regards
Kane
"Some guys hack just to get themselves a girlfriend.What a pathetic reason , huh ? "
|
|
|
|
|
Hi,
I too encountered the problem with a stack overflow when used in COM.
A possible solution (seems to work for me) is to create the TState object 'state' on the heap instead of the stack. Replace the 'ideflate(TZipFileInfo *zfi)' function with the following:
ZRESULT TZip::ideflate(TZipFileInfo *zfi)
{
TState* state=new TState();
(*state).readfunc=sread; (*state).flush_outbuf=sflush;
(*state).param=this; (*state).level=8; (*state).seekable=iseekable; (*state).err=NULL;
// the following line will make ct_init realise it has to perform the init
(*state).ts.static_dtree[0].dl.len = 0;
// It would be nicer if I could figure out precisely which data had to
// be initted each time, and which didn't, but that's kind of difficult.
// Maybe for the next version...
//
bi_init(*state,buf, sizeof(buf), TRUE); // it used to be just 1024-size, not 16384 as here
ct_init(*state,&zfi->att);
lm_init(*state,(*state).level, &zfi->flg);
ulg sz = deflate(*state);
csize=sz;
if ((*state).err!=NULL)
{
delete state;
return ZR_FLATE;
}
else
{
delete state;
return ZR_OK;
}
}
Best regards,
Michael
|
|
|
|
|
USE THIS INPLACE OF THE CURRENT IDEFLATE (beginner contribution unknown to errors, checks out ok for me)
ZRESULT TZip::ideflate(TZipFileInfo *zfi)
{
TState *state = new TState();
state->readfunc=sread; state->flush_outbuf=sflush;
state->param=this; state->level=8; state->seekable=iseekable; state->err=NULL;
// the following line will make ct_init realise it has to perform the init
state->ts.static_dtree[0].dl.len = 0;
// It would be nicer if I could figure out precisely which data had to
// be initted each time, and which didn't, but that's kind of difficult.
// Maybe for the next version...
//
bi_init(*state,buf, sizeof(buf), TRUE); // it used to be just 1024-size, not 16384 as here
ct_init(*state,&zfi->att);
lm_init(*state,state->level, &zfi->flg);
ulg sz = deflate(*state);
csize=sz;
if (state->err!=NULL)
{
delete [] state;
return ZR_FLATE;
}
else
{
delete [] state;
return ZR_OK;
}
//return 0;
}
|
|
|
|
|
Hi,
I can't add a file in an existing archive ( not created with CreateZip(...) ).
In XZip.cpp, function OpenZip(...) :
"
TZipHandleData *han = new TZipHandleData;
han->flag = 1;
"
In XZip.cpp, fonction ZipAdd(...) :
"
TZipHandleData *han = (TZipHandleData*)hz;
if (han->flag != 2)
{
lasterrorZ = ZR_ZMODE;
return ZR_ZMODE;
}
"
The flag has the value 2 only when it is created with CreateZip(...).
Thanks.
|
|
|
|
|
how can i use it in eVC????
Thanks ahead
|
|
|
|
|
I tried writing a simple program that would open a zip file and extract all of its files. I started by including XUnzip.h and I got a complaint from Visual C++ 6.0: "error C2065: 'HZIP' : undeclared identifier". I disabled precompiled headers, but I don't understand what's going on.
Help anyone?
|
|
|
|
|
I solved it by including windows.h and remember to do rebuild all when you changed a .h file, or you will get the same error over and over.
|
|
|
|
|
Hello,
I am using your code and it works great when I had files into my zip file.
But now I would like to add a folder and am using
ZRESULT zr = ZipAdd(hZipFile, _T("c:\\TestDir"), 0, 0, ZIP_FOLDER);
It returns zero but the resulting zip file is empty. I traced a bit of the code and it seems the destination becomes "c" only (converted to a char) but even fixing this didn't seem to help.
Any suggestions?
|
|
|
|
|