|
I encountered the same issue. Problem is that ZRESULT TUnzip::Unzip(int index,void *dst,unsigned int len,DWORD flags) does not check crc error. Existing code is:
unzCloseCurrentFile(uf) < 0;
if (haderr)
return ZR_WRITE;
It should be something like:
bool closeErr = unzCloseCurrentFile(uf) < 0;
if (haderr || closeErr)
return ZR_WRITE;
|
|
|
|
|
When I use UnzipItem as the examples show:
<br />
HZIP hz = OpenZip("somefile.zip", 0, ZIP_FILENAME);<br />
ZIPENTRY ze; int i; <br />
FindZipItem(hz,"file.dat",&i,&ze);<br />
char *ibuf = new char[ze.unc_size];<br />
ZRESULT zres = UnzipItem(hz,i, ibuf, ze.unc_size,ZIP_MEMORY);<br />
delete[] buf;<br />
I always get ZR_MORE instead of ZR_OK returned.
I have looked at the code and don't see how it can ever produce ZR_OK on either a non compressed file or compressed file, when decompressing to a ZIP_MEMORY in one go, even if you specify a buffer larger than needed.
My fix for this is to change:
<br />
int unzReadCurrentFile (unzFile file, voidp buf, unsigned len)<br />
{<br />
...<br />
...<br />
<br />
pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;<br />
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);<br />
if (err==Z_STREAM_END)<br />
{<br />
if( pfile_in_zip_read_info->rest_read_uncompressed > 0 )<br />
{<br />
return iRead;
}<br />
return Z_OK;
}<br />
if (err!=Z_OK) break;<br />
}<br />
}<br />
<br />
if( err == Z_OK )<br />
{<br />
if( pfile_in_zip_read_info->rest_read_uncompressed > 0 )<br />
{<br />
return iRead;
}<br />
return Z_OK;
}<br />
return err;<br />
}<br />
|
|
|
|
|
I had the same problem and this fixed it for me. Thanks!
|
|
|
|
|
Does it support Zip64 format?
Nobody travels the road to success without a puncture or two!!!
Hemant Virmani
|
|
|
|
|
I have looked through the sample project (which appears to be in VC++ 6.0), but am having trouble putting it to actual use.
There are a lot of depreciated function calls, and an error that comes up in Visual Studio 2005 (See below).
I just want to make a .zip and put a couple of already existing files into it. Assuming I have two files (i.e. "C:\Test1.txt" and "C:\Test2.txt") and want to create a "C:\Test.zip", can anyone tell me how to do this?
About the error, VS2005 doesn't want to do implicit casts like the following:
TCHAR * cp = _tcsrchr(lpszSrcFile, _T('\\'));
So, you need to change it to the following to make it work:
TCHAR * cp = (TCHAR *)_tcsrchr(lpszSrcFile, _T('\\'));
However, I don't know if this is safe or not... I assume there is a reason this kind of cast is no longer implicit.
Thanks in advance for any help with the first part of this post!
|
|
|
|
|
Dooh! I missed it the first time. Exactly what I asked for was in the header file.
I included the files, set to not use precompiled headers for the XZip.cpp file, and this code worked like a charm.
<br />
HZIP hz = CreateZip("c:\\temp.zip",0,ZIP_FILENAME);<br />
ZipAdd(hz,"Test1.txt", "c:\\Test1.txt",0,ZIP_FILENAME);<br />
ZipAdd(hz,"Test2.txt", "c:\\Test2.txt",0,ZIP_FILENAME);<br />
CloseZip(hz);<br />
Thanks!
|
|
|
|
|
First off I want to say this is an awesome piece of work the zipping is fantastic but the unzip keeps crashing when I try and read items in the zip file using the example code
GetZipItem(hz, -1, &ze);
int numitems = ze.index;
for (int i = 0; i < numitems; i++){
GetZipItem(hz, i, &ze); // crashes here
}
I have been able to trach the bug to the function
FILETIME timet2filetime(const time_t timer)
But I don’t know what I should do to fix please help
|
|
|
|
|
okay nevor mind i made my own fix to it as shown below
FILETIME timet2filetime(const time_t timer)
{
struct tm *newtime;
__int64 ltime;
_time64( <ime );
// Obtain coordinated universal time:
newtime = _gmtime64( <ime ); // C4996
SYSTEMTIME st;
st.wYear = (WORD)(newtime->tm_year+1900);
st.wMonth = (WORD)(newtime->tm_mon+1);
st.wDay = (WORD)(newtime->tm_mday);
st.wHour = (WORD)(newtime->tm_hour);
st.wMinute = (WORD)(newtime->tm_min);
st.wSecond = (WORD)(newtime->tm_sec);
st.wMilliseconds=0;
FILETIME ft;
SystemTimeToFileTime(&st,&ft);
return ft;
}
from
FILETIME timet2filetime(const time_t timer)
{
struct tm *tm = gmtime(&timer);
SYSTEMTIME st;
st.wYear = (WORD)(tm->tm_year+1900);
st.wMonth = (WORD)(tm->tm_mon+1);
st.wDay = (WORD)(tm->tm_mday);
st.wHour = (WORD)(tm->tm_hour);
st.wMinute = (WORD)(tm->tm_min);
st.wSecond = (WORD)(tm->tm_sec);
st.wMilliseconds=0;
FILETIME ft;
SystemTimeToFileTime(&st,&ft);
return ft;
}
but the fix only works if you call from GetZipItemA ??? any one have an ideaw for a bettor fix than this
|
|
|
|
|
This problem exists because the structure in the zip file is 32 bits and the default time_t is 64 bits (Visual Studio 2005). You can avoid the problem with this line:
#define _USE_32BIT_TIME_T
|
|
|
|
|
ty but a bit slow i figured that out more than a mounth ago
|
|
|
|
|
if you define #define _USE_32BIT_TIME_T you wont be able to target 64 bit platforms.
Better solution, substitute all references of time_t by __time32_t, and the call gmtime by _gmtime32. This works on 32/64 bits platforms.
|
|
|
|
|
if you define #define _USE_32BIT_TIME_T you wont be able to target 64 bit platforms.
Better solution, substitute all references of time_t by __time32_t, and the call gmtime by _gmtime32. This works on 32/64 bits platforms.
FILETIME timet2filetime(time_t timer)
{
struct tm *tm = _gmtime32(&timer);
SYSTEMTIME st;
st.wYear = (WORD)(tm->tm_year+1900);
st.wMonth = (WORD)(tm->tm_mon+1);
st.wDay = (WORD)(tm->tm_mday);
st.wHour = (WORD)(tm->tm_hour);
st.wMinute = (WORD)(tm->tm_min);
st.wSecond = (WORD)(tm->tm_sec);
st.wMilliseconds=0;
FILETIME ft;
SystemTimeToFileTime(&st,&ft);
return ft;
}
/////////////////////////////////
FILETIME timet2filetime(__time32_t timer)
{
struct tm *tm = _gmtime32(&timer);
SYSTEMTIME st;
st.wYear = (WORD)(tm->tm_year+1900);
st.wMonth = (WORD)(tm->tm_mon+1);
st.wDay = (WORD)(tm->tm_mday);
st.wHour = (WORD)(tm->tm_hour);
st.wMinute = (WORD)(tm->tm_min);
st.wSecond = (WORD)(tm->tm_sec);
st.wMilliseconds=0;
FILETIME ft;
SystemTimeToFileTime(&st,&ft);
return ft;
}KZ
|
|
|
|
|
I'm trying to determine why the files extracted are always extracted read only. If I open up the zip file with another zip program and get the properties, they are not hidden and not read only. But when XUnZip extracts the files it makes them read only.
I have traced this down to the ze.attr field which is 161 for these files. 161 in hex is A1, which are the flags Normal, Archive and Read_Only.
Why is this happening?
-- modified at 8:20 Thursday 27th April, 2006
Found the problem. in XUnzip.cpp
unsigned long a = ufi.external_fa;
bool uisdir = (a&0x40000000)!=0;
//bool uwriteable= (a&0x08000000)!=0;
bool uwriteable= (a&0x00800000)!=0; // ***hd***
//bool ureadable= (a&0x01000000)!=0;
//bool uexecutable=(a&0x00400000)!=0;
bool wreadonly= (a&0x00000001)!=0;
bool whidden= (a&0x00000002)!=0;
bool wsystem= (a&0x00000004)!=0;
bool wisdir= (a&0x00000010)!=0;
bool warchive= (a&0x00000020)!=0;
ze->attr=FILE_ATTRIBUTE_NORMAL;
if (uisdir || wisdir)
ze->attr |= FILE_ATTRIBUTE_DIRECTORY;
if (warchive)
ze->attr|=FILE_ATTRIBUTE_ARCHIVE;
if (whidden)
ze->attr|=FILE_ATTRIBUTE_HIDDEN;
if (!uwriteable||wreadonly)
ze->attr|=FILE_ATTRIBUTE_READONLY;
if (wsystem)
ze->attr|=FILE_ATTRIBUTE_SYSTEM;
for this particular file, the ufi.external_fa is 32. This is hex 00000020 so the only attribute that should be set is the FILE_ATTRIBUTE_ARCHIVE. But, the FILE_ATTRIBUTE_READONLY is being set if either the windows readonly flag is set OR the unix unwritable flag. But it appears the zip utility I am using to create this zip file does not set the unix bytes.
I can kludge this easily to work for me, since I'm only using it on windows machines, by simply changing it to:
if (wreadonly)
ze->attr|=FILE_ATTRIBUTE_READONLY;
Actually, this is a bug with the program creating the zip file. Realistically, PUnzip.cpp should deal with this in some graceful manner.
|
|
|
|
|
Recently I got several archives where my program crashed with an access violation in GetZipEntry(handle, -1, &zipEntry). A little debugging showed that unzOpenInternal returns NULL, but TUnzip::Open still returns ZR_OK.
I changed the last line of TUnzip::Open to
return uf ? ZR_OK : ZR_CORRUPT;
This fix works for me, but I didn't spent too much time in analyzing the code, so perhaps someone with more time (and a better understanding of that code) will check that fix and perhaps find a better solution.
Regards
Heinz
|
|
|
|
|
Heinz,
I independently found the same problem and basically the same solution. I didn't analyze the code either.
Regards
Art
|
|
|
|
|
I had the same problem.
I traced it to using a gzipped file from linux gzip.
xunzip did not find file inforamtions.
The file informations in a .gz file seem to be at the beginning of the file,
the ones of a .zip file at the end.
I would be very interested in having a solution to getting xunzip to decompress
a file which was compressed with gzip on a linux system.
Does anyone have an idea?
|
|
|
|
|
I compiled under visual studio 2005 and created a zip archive. When I call FindZipItem on the archive the program crashes in ZRESULT TUnzip::Get(int index,ZIPENTRY *ze) with an assertion error.
I think the code is failing because the only data in the extra header only contains "UT" only. The code then fails on the timet2filetime conversions.
Any ideas?
Ron
....
while (epos+4<extralen)
{="" char="" etype[3];="" etype[0]="extra[epos+0];" etype[1]="extra[epos+1];" etype[2]="0;
" int="" size="extra[epos+2];
" if="" (strcmp(etype,"ut")!="0)" {epos="" +="4+size;" continue;}
="" flags="extra[epos+4];
" bool="" hasmtime="(flags&1)!=0;
" hasatime="(flags&2)!=0;
" hasctime="(flags&4)!=0;
" epos+="5;
" (hasmtime)
="" time_t="" mtime="*(time_t*)(extra+epos);" ze-="">mtime = timet2filetime(mtime);
}
if (hasatime)
{ time_t atime = *(time_t*)(extra+epos); epos+=4;
ze->atime = timet2filetime(atime);
}
if (hasctime)
{ time_t ctime = *(time_t*)(extra+epos);
ze->ctime = timet2filetime(ctime);
}
break;
}
|
|
|
|
|
the code is failing because XUnzip assumes time_t is a 32bit integer, however by default in VS2005 time_t is a 64bit integer, for a simple fix you can set _USE_32BIT_TIME_T as a preprocessor definition in your project settings, this will force time_t to be 32bit
|
|
|
|
|
void pointers are considered a no no in c++ code, but rather than complain about it, I'm thinking I might do something about it.
I would like to go through all the code and get rid of the void pointers by overloading functions, etc...
Now, I wouldn't want to do this if it means that I would only be doing it for myself, as it will probably be a little bit of work.
Do you, Hans Dietrich, mind if I do this, and then give you back the code?
|
|
|
|
|
No, I don't mind. I would ask that you test all of the functions that are affected by your changes.
|
|
|
|
|
The original (PK)ZIP format does not support Unicode filenames, but I saw that you mentioned porting Create() to Unicode and was wondering if you changed any of the internal structure to accomodate unicode filenames.
I did some testing on a japanese windows xp platform with your demo project. I renamed some of the files in the demo to have german umlaut characters in them - they were automagically replaced by their non-umlaut equivalent. However, using japanese characters worked like a charm, so I am thinking that ANSI filenames are used. Am I terribly mistaken?
Also, if it is not trivial to implement ZIP archives with Unicode filenames, do you know of any other freely available archive/compression library that I could use? I'd appreciate any input.
Thanks!
|
|
|
|
|
I have these lines in my code :
#include"XUnzip.cpp"
using namespace std;
void phase1(){
HZIP hz = OpenZip("c:\test.zip",0, ZIP_FILENAME);
ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
for (int i=0; i
|
|
|
|
|
Wow, that's strange it gives you that error becuase it doesn't give me that error.
But it's fairly simple to fix. Just make your string a non const pointer.
char FileName[_MAX_PATH];
strcpy( FileName, "C:\\test.zip" };
HZIP hz = OpenZip(FileName, 0, ZIP_FILENAME);
Incidently, make sure you use \\ instead of \ because \t is a tab.
|
|
|
|
|
Thanks for your answer.
My problem was that I used "\" instead of the "\\" !!
JJ
|
|
|
|
|
I tried to add new files to zip that was already created with this class. I was able to open the zip but was unable to add anything to it. I also tried adding edited versions of files already in the zip and had the same problem. My only alternative (so far) is to pull all the files out of the zip, add or edit the files and then zip them into a new zip. Anybody else have a better way?
|
|
|
|