完整文件打包解包
void CPackDlg::OnBtnPack() { // TODO: Add your control notification handler code here CFileDialog savedlg(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"(类型:*.free)|*.free||"); if (IDOK != savedlg.DoModal()) return; int nTimeBegin = time(NULL); int nMiliTimeBegin = timeGetTime(); CString strPathName = savedlg.GetPathName(); CString strExt = savedlg.GetFileExt(); if (strExt!="free") strPathName+=".free"; int nFileNum = m_listFile.GetCount(); m_progress.SetRange(0,nFileNum); FILE* pFilePack = fopen(strPathName.GetBuffer(0),"wb"); if(!pFilePack) return; int nNumWrite = fwrite(&nFileNum;,sizeof(int),1,pFilePack); for (int i=0;i<nFileNum;i++) { CString str; m_listFile.GetText(i,str); int nFileNameLen = str.GetLength(); fwrite(&nFileNameLen;,sizeof(int),1,pFilePack); fwrite(str.GetBuffer(0),1,nFileNameLen,pFilePack); FILE* pFileOri = fopen(str.GetBuffer(0),"rb"); if (!pFileOri) { char buf[256]; sprintf(buf,"文件:\"%s\"不存在,打包失败!",str.GetBuffer(0)); fclose(pFilePack); MessageBox(buf); return; } fseek(pFileOri,0,SEEK_END); int nFileSize = ftell(pFileOri); fwrite(&nFileSize;,1,sizeof(int),pFilePack); fseek(pFileOri,0,SEEK_SET); // //方法一:这种方法效率比较低 // while(nFileSize-->0) // { // char c; // fread(&c,1,1,pFileOri); // fwrite(&c,1,1,pFilePack); // } //方法二:这种方法效率比较高 char *pBuf = new char[nFileSize]; fread(pBuf,1,nFileSize,pFileOri); fwrite(pBuf,1,nFileSize,pFilePack); delete []pBuf; m_progress.SetPos(i+1); fclose(pFileOri); } fclose(pFilePack); int nTimeEnd = time(NULL); int nMiliTimeEnd = timeGetTime(); char bufTime[128] = ""; char bufMiliTime[128] = ""; sprintf(bufTime,"打包用时:%d秒",nTimeEnd-nTimeBegin); sprintf(bufMiliTime,"打包用时:%d毫秒",nMiliTimeEnd-nMiliTimeBegin); if (nTimeEnd-nTimeBegin==0) MessageBox(bufMiliTime); else MessageBox(bufTime); } void CPackDlg::OnBtnUnpack() { // TODO: Add your control notification handler code here CString strPathName; m_editFileName2.GetWindowText(strPathName); //ASSERT(PathFileExists(str)); if (!PathFileExists(strPathName)) { MessageBox("文件不存在!"); return; } FILE* pFile = fopen(strPathName.GetBuffer(0),"rb"); if (!pFile) { MessageBox("文件打开失败!"); return; } int nTimeBegin = time(NULL); int nMiliTimeBegin = timeGetTime(); CString strPath = strPathName; strPath.MakeReverse(); int nIndex = strPath.Find("\\"); strPath.MakeReverse(); strPath = strPath.Left(strPath.GetLength()-nIndex); int nFileNum = 0; fread(&nFileNum;,4,1,pFile); m_progress2.SetRange(0,nFileNum); m_progress2.SetStep(1); for (int i=0;i<nFileNum;i++) { //m_progress2.SetPos(i+1); int nFileNameLen = 0; fread(&nFileNameLen;,4,1,pFile); char szFileName[128] = ""; fread(szFileName,1,nFileNameLen,pFile); CString strFileName = PathFindFileName(szFileName); strFileName = strPath+strFileName; m_listFile2.AddString(strFileName); UpdateData(false); FILE* pFilePack = fopen(strFileName,"wb"); if (!pFilePack) return; int nFileSize = 0; fread(&nFileSize;,4,1,pFile); char* pData = new char[nFileSize]; fread(pData,1,nFileSize,pFile); fwrite(pData,1,nFileSize,pFilePack); delete []pData; fclose(pFilePack); m_progress2.StepIt(); } fclose(pFile); int nTimeEnd = time(NULL); int nMiliTimeEnd = timeGetTime(); char bufTime[128] = ""; char bufMiliTime[128] = ""; sprintf(bufTime,"解包用时:%d秒",nTimeEnd-nTimeBegin); sprintf(bufMiliTime,"解包用时:%d毫秒",nMiliTimeEnd-nMiliTimeBegin); if (nTimeEnd-nTimeBegin==0) MessageBox(bufMiliTime); else MessageBox(bufTime); }
- 1
- wojiushi33442013-02-20你妹哟,这个东西是骗分的,根本就不能正确的打包与解包!大家千万不要下载呀。。
- bzxyzxt2014-01-18参考了一下 还是有借鉴意义的
- 粉丝: 1
- 资源: 72
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 冯璐阳 42105650—祝福.docx
- 基于多种算法及改进算法实现的移动机器人路径规划matlab源码(含A星算法+PRM+RRT的改进等).zip
- 布里斯托尔纸细分市场、总体规模、先进性、市占率行业分析报告2024年.docx
- Obi绳子插件,好用的很 6.5.4版本
- openjfx-22.0.1-windows-x64-bin-sdk.zip
- 基于ros和stm32f1的小车代码(含串口通信)+项目说明.zip
- 人体姿态估计-基于Tensorflow实现的人体姿态估计算法-附项目源码-优质项目分享.zip
- java实现所有算法大全
- JDBC DAO模式 (复习)
- Proteus仿真AT89C51电子密码锁