1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include "StdAfx.h"
- #include "UnZipFile.h"
- #include <afx.h>
- #define ZIP_GPBF_LANGUAGE_ENCODING_FLAG 0x800
- CUnZipFile::CUnZipFile(void)
- {
- }
- CUnZipFile::CUnZipFile( LPCTSTR fileName )
- {
- CStringA strSourceFileA = CT2A(fileName);
-
- uf = unzOpen64(strSourceFileA);
- if (uf == NULL)
- {
- return ;
- }
- unz_global_info64 gi;
- if (unzGetGlobalInfo64(uf, &gi) != UNZ_OK)
- {
- return ;
- }
- m_nEntryNum = gi.number_entry;
- m_nCurrentEntryNum =0;
- m_bIsCurrentFileOpened =m_nEntryNum>0? TRUE:FALSE;
- }
- CUnZipFile::~CUnZipFile(void)
- {
- Close();
- }
- void CUnZipFile::Close( ){
- if(m_bIsCurrentFileOpened){
- unzCloseCurrentFile(uf);
- m_bIsCurrentFileOpened =FALSE;
- }
- if(m_bIsZipOpened){
- unzClose(uf);
- m_bIsZipOpened =FALSE;
- }
- }
- int CUnZipFile::Read( void * buffer,int bufferSize )
- {
- return unzReadCurrentFile(uf, buffer, bufferSize);
- }
- BOOL CUnZipFile::GetNextEntry( CString & strFileName )
- {
- if(!HasMoreEntry()) return FALSE;
- m_nCurrentEntryNum++;
- if(m_nCurrentEntryNum>1&&m_bIsCurrentFileOpened){
- unzCloseCurrentFile(uf);
- }
- if (m_nCurrentEntryNum>1&&unzGoToNextFile(uf) != UNZ_OK)
- {
- return FALSE;
- }
- char szFilePathA[MAX_PATH];
- unz_file_info64 FileInfo;
- if (unzGetCurrentFileInfo64(uf, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0) != UNZ_OK)
- {
- return FALSE;
- }
- if ((FileInfo.flag & ZIP_GPBF_LANGUAGE_ENCODING_FLAG) != 0)
- {
- strFileName = CA2T(szFilePathA,CP_UTF8);
- }
- else
- {
- strFileName = CA2T(szFilePathA);
- }
- if (unzOpenCurrentFile(uf) != UNZ_OK)
- {
- return FALSE;
- }
- m_bIsCurrentFileOpened =TRUE;
- return TRUE;
- }
- BOOL CUnZipFile::HasMoreEntry()
- {
- return m_nCurrentEntryNum<m_nEntryNum;
- }
|