void DatapackDownloaderMainSub::decodedIsFinishMain(QXzDecode &xzDecodeMain) { if(!xzDecodeMain.decode()) test_mirror_main(); else { const std::vector<char> &decodedData=xzDecodeMain.decodedData(); QTarDecode tarDecode; if(tarDecode.decodeData(decodedData)) { const std::vector<std::string> &fileList=tarDecode.getFileList(); const std::vector<std::vector<char> > &dataList=tarDecode.getDataList(); unsigned int index=0; while(index<fileList.size()) { if(!FacilityLibGateway::mkpath(FacilityLibGeneral::getFolderFromFile(mDatapackMain+fileList.at(index)))) { std::cerr << "unable to mkpath file of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } if(extensionAllowed.find(FacilityLibGeneral::getSuffix(fileList.at(index)))!=extensionAllowed.cend()) { FILE *file=::fopen((mDatapackMain+fileList.at(index)).c_str(),"wb"); if(file) { if(fwrite(dataList.at(index).data(),1,dataList.at(index).size(),file)!=dataList.at(index).size()) { fclose(file); std::cerr << "unable to write file content of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } fclose(file); } else { std::cerr << "unable to write file of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } } else { std::cerr << "file not allowed: " << mDatapackMain+fileList.at(index) << std::endl; return; } index++; } wait_datapack_content_main=false; checkIfContinueOrFinished(); } else test_mirror_main(); } }
void DatapackDownloaderMainSub::decodedIsFinishMain(const std::vector<char> &rawData) { std::vector<char> mDataToDecode=rawData; std::string mErrorString; { std::vector<char> dataToDecoded; unsigned long long const rSize = ZSTD_getDecompressedSize(mDataToDecode.data(), mDataToDecode.size()); if (rSize==ZSTD_CONTENTSIZE_ERROR) { mErrorString="it was not compressed by zstd"; } else if (rSize==ZSTD_CONTENTSIZE_UNKNOWN) { mErrorString="original size unknown. Use streaming decompression instead."; } else { dataToDecoded.resize(rSize); size_t const dSize = ZSTD_decompress(dataToDecoded.data(), rSize, mDataToDecode.data(), mDataToDecode.size()); if (dSize != rSize) mErrorString=std::string("error decoding: ")+ZSTD_getErrorName(dSize); else { dataToDecoded.resize(dSize); mDataToDecode=dataToDecoded; } } } if(!mErrorString.empty()) { std::cerr << "mErrorString: " << mErrorString << std::endl; test_mirror_main(); } else { const std::vector<char> &decodedData=mDataToDecode; QTarDecode tarDecode; if(tarDecode.decodeData(decodedData)) { const std::vector<std::string> &fileList=tarDecode.getFileList(); const std::vector<std::vector<char> > &dataList=tarDecode.getDataList(); unsigned int index=0; while(index<fileList.size()) { if(!FacilityLibGateway::mkpath(FacilityLibGeneral::getFolderFromFile(mDatapackMain+fileList.at(index)))) { std::cerr << "unable to mkpath file of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } if(extensionAllowed.find(FacilityLibGeneral::getSuffix(fileList.at(index)))!=extensionAllowed.cend()) { FILE *file=::fopen((mDatapackMain+fileList.at(index)).c_str(),"wb"); if(file) { if(fwrite(dataList.at(index).data(),1,dataList.at(index).size(),file)!=dataList.at(index).size()) { fclose(file); std::cerr << "unable to write file content of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } fclose(file); } else { std::cerr << "unable to write file of datapack " << mDatapackMain+fileList.at(index) << ": " << errno << std::endl; return; } } else { std::cerr << "file not allowed: " << mDatapackMain+fileList.at(index) << std::endl; return; } index++; } wait_datapack_content_main=false; checkIfContinueOrFinished(); } else test_mirror_main(); } }