|
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
|
|
|
|
|
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
|
|
|
|
|