完整文件打包解包
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
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); }
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/TXT.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
- 1
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- wojiushi33442013-02-20你妹哟,这个东西是骗分的,根本就不能正确的打包与解包!大家千万不要下载呀。。
- bzxyzxt2014-01-18参考了一下 还是有借鉴意义的
![avatar](https://profile-avatar.csdnimg.cn/7471d3e7858c4b9498627ccc9024567f_wjh627641217.jpg!1)
- 粉丝: 1
- 资源: 72
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)