|
Mr Dietrich's efforts are quite worthy.
Your comments are somewhat less.
Presenting code that works under the conditions specified (dev env, operating system, hardware, etc.) is the only true necessary requirement of all programmers.
One can spend endless hours conforming or, for that matter, taking code from others and making that code conform, and still end up with the same executable. Programming is not about the code, it is about the functionality. We are not special because we write to some spec despite what your professors taught you. Your disappointment, we suspect, is really about unoffered functionality (sub-directories).
Are we talking about limitations within code or limitations within coders to understand?
Dave Harris
|
|
|
|
|
Is it possible to create a zip file with CreateZip and then at a later time use OpenZip and AddZip to append files to it? Every time I try I get a ZR_ZMODE return code and a message about trying to mix creating and opening.
Greg Smith
|
|
|
|
|
The macro PUTSHORT doesnt check for a failure in flush_outbuf where state.bs.out_offset will not be reset to zero. I got a crash in "state.bs.out_buf[state.bs.out_offset++]" then. I changed the code that way:
#define PUTSHORT(state,w) \<br />
{ if (state.bs.out_offset >= state.bs.out_size-1) \<br />
state.flush_outbuf(state.param,state.bs.out_buf, &state.bs.out_offset); \<br />
if (state.bs.out_offset < state.bs.out_size-1) \<br />
{ state.bs.out_buf[state.bs.out_offset++] = (char) ((w) & 0xff); \<br />
state.bs.out_buf[state.bs.out_offset++] = (char) ((ush)(w) >> 8); }\<br />
}
You might change that in PUTBYTE as well.
If the memory size assigned to CreateZip is to small for the file, there is no check/reallocation of memory. I changed the function TZip::write to get over this.
<br />
unsigned int TZip::write(const char *buf,unsigned int size)<br />
{ if (obuf!=0)<br />
{ if (opos+size>=mapsize)<br />
{<br />
int newmapsize=2*mapsize>opos+size?2*mapsize:opos+size;<br />
HANDLE hmapout2 = CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,newmapsize,NULL);<br />
if (hmapout2==NULL) <br />
return ZR_NOALLOC;<br />
char *obuf2;
<br />
obuf2 = (char*)MapViewOfFile(hmapout2,FILE_MAP_ALL_ACCESS,0,0,newmapsize);<br />
if (obuf2==0) <br />
{<br />
CloseHandle(hmapout2); <br />
hmapout2=0; <br />
return ZR_NOALLOC;<br />
}<br />
<br />
memcpy(obuf2,obuf,mapsize);<br />
<br />
UnmapViewOfFile(obuf);<br />
CloseHandle(hmapout); <br />
<br />
mapsize=newmapsize;<br />
obuf = obuf2;<br />
hmapout = hmapout2;<br />
}<br />
memcpy(obuf+opos, buf, size);<br />
opos+=size;<br />
return size;<br />
}<br />
else if (hfout!=0)<br />
{ DWORD writ; WriteFile(hfout,buf,size,&writ,NULL);<br />
return writ;<br />
}<br />
oerr=ZR_NOTINITED; return 0;<br />
}
Thanks for your good work.
Thomas
|
|
|
|
|
i like it don't depend MFC.
it help me, thank you very much.
|
|
|
|
|
If I extract a file from a zip file and then try to delete the extracted file later within the same instance of the application that performed the unzip operation, DeleteFile fails with the message "The process cannot access the file because it is being used by another process."
I messed around with trying unzClose at the end of TUnzip::Unzip, but that didn't work. I'm probably going down the wrong path with that approach though. The message about extracted files being read-only might shed some light on this problem but I havn't looked too far yet.
Any thoughts on this?
|
|
|
|
|
Cheers! )
And thank you again.
Mike
|
|
|
|
|
Hello.
For some reason, when I try to use a for loop to list the files in my zip, it keeps showing the first one during each iteration. After some debugging, I discovered that the value of my ze.index is apparently not changing when I call the GetZipItem function inside the loop. The problematic portion of my code is as follows:
<br />
HZIP hz = OpenZip(fileNameCChar,0,ZIP_FILENAME);<br />
ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;<br />
<br />
printf("Items in file: %i\n", numitems);
<br />
for (int i = 0; i < numitems; i++)<br />
{<br />
GetZipItem(hz,i,&ze);
<br />
printf("%d: %s\n", i, ze.name);
<br />
printf("ze.index: %i\n", ze.index);
}<br />
When I run this code, the name of the first file contained in the zip keeps repeating itself, and the value of ze.index is always zero (0).
Correct me if I'm wrong, but shouldn't the value of ze.index equal i when you call the GetZipItem using i as the second parameter? Is my logic is flawed in some way? This has been troubling me for about a day now. I appreciate any help.
-- modified at 10:53 Wednesday 21st March, 2007
|
|
|
|
|
Well, after a little more persistence, I fixed it myself. In my case, it works a lot better to increment the ze.index, rather than i.within the for loop. I’m not entirely sure why this is, but it works. And that’s good enough for me. If I find anything else out about it, I’ll be sure to make mention of it here.
<br />
HZIP hz = OpenZip(fileNameCChar,0,ZIP_FILENAME);<br />
ZIPENTRY ze;<br />
GetZipItem(hz,-1,&ze);<br />
int numitems=ze.index;<br />
<br />
for (ze.index = 0; ze.index < numitems; ze.index++)<br />
{<br />
GetZipItem(hz,ze.index,&ze<br />
char *ibuf = new char[ze.unc_size];<br />
UnzipItem(hz,ze.index, ibuf, ze.unc_size,ZIP_MEMORY);<br />
}<br />
Thanks!
|
|
|
|
|
Hello,
I get the following warnings/errors compiling with Visual Studio 2005.
------ Build started: Project: XZipTest, Configuration: Unicode Debug Win32 ------
Compiling...
StdAfx.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
Compiling...
About.cpp
Clipboard.cpp
d:\devtemp\xzip_demo\clipboard.cpp(241) : warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(252) : see declaration of 'wcscpy'
HyperLink.cpp
d:\devtemp\xzip_demo\hyperlink.cpp(392) : warning C4996: 'wcscat': This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(245) : see declaration of 'wcscat'
d:\devtemp\xzip_demo\hyperlink.cpp(393) : warning C4996: 'wcscat': This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(245) : see declaration of 'wcscat'
XListBox.cpp
d:\devtemp\xzip_demo\xlistbox.cpp(483) : warning C4996: '_swprintf': This function or variable may be unsafe. Consider using _swprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\wchar.h(773) : see declaration of '_swprintf'
d:\devtemp\xzip_demo\xlistbox.cpp(486) : warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(272) : see declaration of 'wcsncpy'
d:\devtemp\xzip_demo\xlistbox.cpp(491) : warning C4996: 'wcsncpy': This function or variable may be unsafe. Consider using wcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(272) : see declaration of 'wcsncpy'
d:\devtemp\xzip_demo\xlistbox.cpp(497) : warning C4996: '_vsnwprintf': This function or variable may be unsafe. Consider using _vsnwprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\wchar.h(719) : see declaration of '_vsnwprintf'
XZipTest.cpp
d:\devtemp\xzip_demo\xziptest.cpp(41) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
c:\programme\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(4477) : see declaration of 'CWinApp::Enable3dControls'
XZipTestDlg.cpp
d:\devtemp\xzip_demo\xziptestdlg.cpp(353) : error C2440: 'initializing' : cannot convert from 'const wchar_t *' to 'TCHAR *'
Conversion loses qualifiers
Generating Code...
XZipTest - 1 error(s), 8 warning(s)
------ Build started: Project: XZipTest, Configuration: Debug Win32 ------
Compiling...
StdAfx.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
Compiling...
About.cpp
Clipboard.cpp
d:\devtemp\xzip_demo\clipboard.cpp(241) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(74) : see declaration of 'strcpy'
HyperLink.cpp
d:\devtemp\xzip_demo\hyperlink.cpp(392) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(79) : see declaration of 'strcat'
d:\devtemp\xzip_demo\hyperlink.cpp(393) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\string.h(79) : see declaration of 'strcat'
XListBox.cpp
d:\devtemp\xzip_demo\xlistbox.cpp(483) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\stdio.h(345) : see declaration of 'sprintf'
d:\devtemp\xzip_demo\xlistbox.cpp(486) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\tchar.h(1518) : see declaration of '_tcsncpy'
d:\devtemp\xzip_demo\xlistbox.cpp(491) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\tchar.h(1518) : see declaration of '_tcsncpy'
d:\devtemp\xzip_demo\xlistbox.cpp(497) : warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\programme\microsoft visual studio 8\vc\include\stdio.h(339) : see declaration of '_vsnprintf'
XZipTest.cpp
d:\devtemp\xzip_demo\xziptest.cpp(41) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
c:\programme\microsoft visual studio 8\vc\atlmfc\include\afxwin.h(4477) : see declaration of 'CWinApp::Enable3dControls'
XZipTestDlg.cpp
d:\devtemp\xzip_demo\xziptestdlg.cpp(353) : error C2440: 'initializing' : cannot convert from 'const char *' to 'TCHAR *'
Conversion loses qualifiers
Generating Code...
XZipTest - 1 error(s), 8 warning(s)
------ Build started: Project: XZipTest, Configuration: Release Win32 ------
Compiling...
StdAfx.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
Compiling...
XZipTestDlg.cpp
.\XZipTestDlg.cpp(353) : error C2440: 'initializing' : cannot convert from 'const char *' to 'TCHAR *'
Conversion loses qualifiers
.\XZipTestDlg.cpp(426) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(74) : see declaration of 'strcpy'
.\XZipTestDlg.cpp(427) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
XZipTest.cpp
.\XZipTest.cpp(41) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
C:\Programme\Microsoft Visual Studio 8\VC\atlmfc\include\afxwin.h(4477) : see declaration of 'CWinApp::Enable3dControls'
XListBox.cpp
.\XListBox.cpp(483) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\stdio.h(345) : see declaration of 'sprintf'
.\XListBox.cpp(486) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\tchar.h(1518) : see declaration of '_tcsncpy'
.\XListBox.cpp(491) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\tchar.h(1518) : see declaration of '_tcsncpy'
.\XListBox.cpp(497) : warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\stdio.h(339) : see declaration of '_vsnprintf'
HyperLink.cpp
.\HyperLink.cpp(392) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
.\HyperLink.cpp(393) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
Clipboard.cpp
.\Clipboard.cpp(241) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(74) : see declaration of 'strcpy'
About.cpp
Generating Code...
XZipTest - 1 error(s), 10 warning(s)
------ Build started: Project: XZipTest, Configuration: Unicode Release Win32 ------
Compiling...
StdAfx.cpp
WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
Compiling...
XZipTestDlg.cpp
.\XZipTestDlg.cpp(353) : error C2440: 'initializing' : cannot convert from 'const char *' to 'TCHAR *'
Conversion loses qualifiers
.\XZipTestDlg.cpp(426) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(74) : see declaration of 'strcpy'
.\XZipTestDlg.cpp(427) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
XZipTest.cpp
.\XZipTest.cpp(41) : warning C4996: 'CWinApp::Enable3dControls': CWinApp::Enable3dControls is no longer needed. You should remove this call.
C:\Programme\Microsoft Visual Studio 8\VC\atlmfc\include\afxwin.h(4477) : see declaration of 'CWinApp::Enable3dControls'
XListBox.cpp
.\XListBox.cpp(483) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\stdio.h(345) : see declaration of 'sprintf'
.\XListBox.cpp(486) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\tchar.h(1518) : see declaration of '_tcsncpy'
.\XListBox.cpp(491) : warning C4996: '_tcsncpy': This function or variable may be unsafe. Consider using _tcsncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\tchar.h(1518) : see declaration of '_tcsncpy'
.\XListBox.cpp(497) : warning C4996: '_vsnprintf': This function or variable may be unsafe. Consider using _vsnprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\stdio.h(339) : see declaration of '_vsnprintf'
HyperLink.cpp
.\HyperLink.cpp(392) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
.\HyperLink.cpp(393) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(79) : see declaration of 'strcat'
Clipboard.cpp
.\Clipboard.cpp(241) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Programme\Microsoft Visual Studio 8\VC\include\string.h(74) : see declaration of 'strcpy'
About.cpp
Generating Code...
XZipTest - 1 error(s), 10 warning(s)
========== Build: 0 succeeded, 4 failed, 0 up-to-date, 0 skipped ==========
Andreas.
|
|
|
|
|
These warnings are occurring because VS2005 deprecated all the C runtime library functions that potentially overflowed their buffers. You can find detailed explanation of this in the VS2005 docs, along with a preprocessor symbol to set which disables the warnings.
|
|
|
|
|
No, only the warnings are about deprecation.
This does not explain the errors, which are caused by the missuse of TCHAR & Co.
Note the fact that the build is Unicode:
------ Build started: Project: XZipTest, Configuration: Unicode Release Win32 ------
And now the error:
.\XZipTestDlg.cpp(353) : error C2440: 'initializing' : cannot convert from 'const char *' to 'TCHAR *'
And nobody can tell how many such errors are masked by crappy casts.
Good coding discipline (like avoiding casts) is not just pedantry.
|
|
|
|
|
Hello,
I have posted this to show the autor that there is a problem with VS2005. I know that I could set _CRT_SECURE_NO_WARNINGS in the project.
Andreas.
|
|
|
|
|
I use C++Builder 3.0 and include the XUnzip.h as header file then got the following error when compiling, please help
[LinkerError] Unresolved external 'OpenZipU(void*,unsigned int,unsigned long)' referenced from G:\Test\testing.OBJ.
Thank you
|
|
|
|
|
I face the same problem and found the following is the cause
DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that is being created
where HZIP is not defined as void *.
Comment out the
#define STRICT in XUnzip.h will help.
|
|
|
|
|
If I intentionally patch the zip file to corrupt one or two of the compressed files in the archive, XUnzip creates corrupted files - not good!
zr = GetZipItem(hz, i, &ze); // always returns ZR_OK
zr = UnzipItem(hz, i, (void*)(LPCTSTR)ze.name, 0, ZIP_FILENAME); // always returns ZR_OK
If I use WinZip or WinRar they both do not extract the file(s) but complain about a CRC error and corrupted file.
Does anyone know of a fix, or am I overlooking something?
|
|
|
|
|
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
|
|
|
|
|