首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于zipWriteInFileInZip写的资料全是CDCDCDCD

2013-07-16 
关于zipWriteInFileInZip写的文件全是CDCDCDCD本帖最后由 lezard 于 2013-07-09 19:06:53 编辑int MobileD

关于zipWriteInFileInZip写的文件全是CDCDCDCD
本帖最后由 lezard 于 2013-07-09 19:06:53 编辑

int MobileDevice::compressApplicationDocumentToLocal(afc_connection *serviceHandle, voidp hz,const wchar_t *dir, int& nCurIndex, int nTotal){
    int ret = 0;
    std::vector<boost::shared_ptr<MobileFile>> files;
    ret = this->subFileAndDirectory(serviceHandle,dir,files);
    if(ret == 0 && files.size() > 0){
        for (int i = 0; i < (int)files.size(); ++i)
        {
            boost::shared_ptr<MobileFile> file = files[i];

            if(StringHelper::EndWithW(file.get()->Path(),L".app")){
                continue;
            }

            zip_fileinfo zipdItem={0};
            boost::scoped_array<char> filePathU8(UnicodeToUft8(file.get()->Path()));
            if(file.get()->FileType() == MobileFile::Directory){ //文件夹
                boost::scoped_array<char> dirPathU8(new char[strlen(filePathU8.get())+1]);
                strcpy(dirPathU8.get(),filePathU8.get()+1);   //去掉"/"
                dirPathU8.get()[strlen(filePathU8.get())-1]='/';  //zip压缩,文件夹以/结尾
                dirPathU8.get()[strlen(filePathU8.get())]='\0';
                if(zipOpenNewFileInZip(hz,dirPathU8.get(),&zipdItem,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_BEST_COMPRESSION)==UNZ_OK){
                    char temp[1]={0};
                    zipWriteInFileInZip(hz,temp,0);
                    ret = this->compressApplicationDocumentToLocal(serviceHandle,hz,file.get()->Path(),nCurIndex,nTotal);


                }
                else{
                    ret = kAMDCannotCompressFile;
                }
            }
            else{ //文件
                if(StringHelper::EndWithW(file.get()->Path(),L".GlobalPreferences.plist")){
                    continue;
                }
                else if(StringHelper::EndWithW(file.get()->Path(),L"com.apple.PeoplePicker.plist")){
                    continue;
                }
else if(wcscmp(file.get()->Path(),L"/iTunesMetadata.plist")==0){
continue;
}


                boost::scoped_array<char> newFilePathU8(new char[strlen(filePathU8.get())+1]);
                strcpy(newFilePathU8.get(),filePathU8.get()+1); //去掉"/"
                newFilePathU8.get()[strlen(filePathU8.get())]='\0';
                if(zipOpenNewFileInZip(hz,newFilePathU8.get(),&zipdItem,NULL,0,NULL,0,NULL,Z_DEFLATED,Z_BEST_COMPRESSION)==UNZ_OK){
                    byte* fileBuffer =NULL;
                    unsigned long fileSize = 0;
                    //fileBuffer 申请内存并赋值
                    ++nCurIndex;
                    if(ret == 0)


                    {
                        ret = zipWriteInFileInZip(hz,fileBuffer,fileSize);
                    }
                    zipCloseFileInZip( hz );
                    if(fileBuffer){
                        delete [] fileBuffer;
                    }
                }
                else{
                    ret = kAMDCannotCompressFile;
                }
            }
            if(ret!=0){
                break;
            }
        }
    }
    return ret;
}


上面的代码,无论fileBuffer中的值是什么,写的zip文件中文件的内容全都是CDCDCDCD,求大神帮助啊 C++ ZIP zlib
[解决办法]
                    byte* fileBuffer =NULL;
                    unsigned long fileSize = 0;


                    //fileBuffer 申请内存并赋值
                    ++nCurIndex;
                    if(ret == 0)
                    {
                        ret = zipWriteInFileInZip(hz,fileBuffer,fileSize);
                    }
                    zipCloseFileInZip( hz );
                    if(fileBuffer){
                        delete [] fileBuffer;
                    }
怎么申请内存并赋值?

热点排行