64,643
社区成员
发帖
与我相关
我的任务
分享
BOOL CtestView::ZipAllFile(CString &cTarFile) //cTarFile : f:\主程序目录\etouch.exe
{
//MessageBox(cTarFile);
/* if (cTarFile == L"")return FALSE;
CInfoZip InfoZip;
if (!InfoZip.InitializeZip())return FALSE;
CString path=cTarFile;
int nPos=path.ReverseFind('\\');//从右边找到第一个“\\”字符,返回其数组下标的位置
path=path.Left(nPos+1); //保留字符串的前nPos+1个字符(包括“\\”);
if (nPos<2 || nPos>(MAX_PATH-40))return FALSE;
CString filename;
filename.Format(L"mymail%08x.zip",GetTickCount());
path=path+filename;//f:\主程序目录\mymail34234324.zip
BeginWaitCursor();
int nPages = m_PageManager.m_PageList.GetSize();
char **pFiles = (char **) new LPVOID [nPages];
int i=0;
for (i=0;i<nPages;i++)
{
pFiles[i] = new char[MAX_PATH+1];
memset(pFiles[i],0,MAX_PATH+1);
//wsprintf(pFiles[i],L"mymail%04d.JPG",i);
sprintf(pFiles[i],"mymail%04d.JPG",i);
CString ImageFile;// = pFiles[i];
ImageFile.Format(L"mymail%04d.JPG",i);
//CString ImageFile(pFiles[i]);
//string str( cstr );
m_PageManager.SavePageToImage(ImageFile,L"JPG",i);
}
BOOL sult = TRUE;
int len = WideCharToMultiByte(CP_ACP,0,path,path.GetLength(),NULL,0,NULL,NULL);
char *chr=new char[len+1];
WideCharToMultiByte(CP_ACP,0,path,path.GetLength(),chr,len+1,NULL,NULL);
chr[len]=0;
//string limage = chr;
if (!InfoZip.AddFiles(chr, pFiles, nPages))sult = FALSE;
if (!InfoZip.Finalize())sult = FALSE;
EndWaitCursor();
CString deletfile;
for(i=0; i<nPages; i++)
{
deletfile.Format(L"%s",pFiles[i]);
::DeleteFile(deletfile.AllocSysString());
delete pFiles[i];
}
delete pFiles;
cTarFile = path.AllocSysString();
return sult;*/
if (cTarFile == L"")return FALSE;
CInfoZip InfoZip;
if (!InfoZip.InitializeZip())return FALSE;
CString path=cTarFile;
int nPos=path.ReverseFind('\\');//从右边找到第一个“\\”字符,返回其数组下标的位置
path=path.Left(nPos+1); //保留字符串的前nPos+1个字符(包括“\\”);
if (nPos<2 || nPos>(MAX_PATH-40))return FALSE;
CString filename;
filename.Format(L"mymail%08x.zip",GetTickCount());
path=path+filename;//f:\主程序目录\mymail34234324.zip
BeginWaitCursor();
int nPages = m_PageManager.m_PageList.GetSize();
char **pFiles = (char **) new int [nPages];
for (int i=0;i<nPages;i++)
{
pFiles[i] = new char[MAX_PATH+1];
memset(pFiles[i],0,MAX_PATH+1);
sprintf(pFiles[i],"mymail%08x.JPG",i);
CString ImageFile = (CString)pFiles[i];
// CString ImageFile;// = pFiles[i];
// ImageFile.Format(L"mymail%08x.JPG",i);
//ImageFile.Format(L"%s",pFiles[i]);
m_PageManager.SavePageToImage(ImageFile,L"JPG",i);
}
BOOL sult = TRUE;
int len = WideCharToMultiByte(CP_ACP,0,path,path.GetLength(),NULL,0,NULL,NULL);
char *chr=new char[len+1];
WideCharToMultiByte(CP_ACP,0,path,path.GetLength(),chr,len+1,NULL,NULL);
chr[len]=0;
if (!InfoZip.AddFiles(chr, pFiles, nPages))sult = FALSE;
if (!InfoZip.Finalize())sult = FALSE;
EndWaitCursor();
CString deletfile;
for(int i=0; i<nPages; i++)
{
deletfile.Format(L"%s",pFiles[i]);
::DeleteFile(deletfile.AllocSysString());
delete pFiles[i];
}
delete pFiles;
cTarFile = path.AllocSysString();
return sult;
}
BOOL CInfoZip::AddFiles(const char *pszArchive, char ** paFiles, int iFileCount)
{
CZipParams zpParams;
SetDefaultValues(&zpParams);
// seting archive name
zpParams.m_pszArchiveFileName = (char*)malloc(strlen(pszArchive)+1);
ZeroMemory(zpParams.m_pszArchiveFileName, strlen(pszArchive)+1);
strcpy(zpParams.m_pszArchiveFileName, pszArchive);//复制 f:\目录\mymail234234.zip
// seting file count
zpParams.m_liFileCount = iFileCount;
// seting file names
for (int i=0; i<iFileCount; i++)
{
zpParams.m_pszFileNames[i] = (char*)malloc(MAX_PATH+1);
ZeroMemory(zpParams.m_pszFileNames[i], MAX_PATH+1);
strcpy(zpParams.m_pszFileNames[i], paFiles[i]);
}
// executing command
int iProcessedCount = m_ZipDllExec(&zpParams); //调试到这里出错。。。
ReleaseParams(&zpParams);
return (iProcessedCount == iFileCount);
}