PtexWriterBase::PtexWriterBase(const char* path, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool compress) : _ok(true), _path(path), _tilefp(0) { memset(&_header, 0, sizeof(_header)); _header.magic = Magic; _header.version = PtexFileMajorVersion; _header.minorversion = PtexFileMinorVersion; _header.meshtype = mt; _header.datatype = dt; _header.alphachan = alphachan; _header.nchannels = nchannels; _header.nfaces = nfaces; _header.nlevels = 0; _header.extheadersize = sizeof(_extheader); _pixelSize = _header.pixelSize(); memset(&_extheader, 0, sizeof(_extheader)); if (mt == mt_triangle) _reduceFn = &PtexUtils::reduceTri; else _reduceFn = &PtexUtils::reduce; memset(&_zstream, 0, sizeof(_zstream)); deflateInit(&_zstream, compress ? Z_DEFAULT_COMPRESSION : 0); // create temp file for writing tiles // (must compress each tile before assembling a tiled face) std::string error; _tilefp = OpenTempFile(_tilepath); if (!_tilefp) { setError(fileError("Error creating temp file: ", _tilepath.c_str())); } }
void AssetsManagerEx::decompressDownloadedZip(const std::string &customId, const std::string &storagePath) { struct AsyncData { std::string customId; std::string zipFile; bool succeed; }; AsyncData* asyncData = new AsyncData; asyncData->customId = customId; asyncData->zipFile = storagePath; asyncData->succeed = false; std::function<void(void*)> decompressFinished = [this](void* param) { auto dataInner = reinterpret_cast<AsyncData*>(param); if (dataInner->succeed) { fileSuccess(dataInner->customId, dataInner->zipFile); } else { std::string errorMsg = "Unable to decompress file " + dataInner->zipFile; // Ensure zip file deletion (if decompress failure cause task thread exit anormally) _fileUtils->removeFile(dataInner->zipFile); dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DECOMPRESS, "", errorMsg); fileError(dataInner->customId, errorMsg); } delete dataInner; }; AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_OTHER, std::move(decompressFinished), (void*)asyncData, [this, asyncData]() { // Decompress all compressed files if (decompress(asyncData->zipFile)) { asyncData->succeed = true; } _fileUtils->removeFile(asyncData->zipFile); }); }
void AssetsManagerEx::onError(const network::DownloadTask& task, int errorCode, int errorCodeInternal, const std::string& errorStr) { // Skip version error occurred if (task.identifier == VERSION_ID) { CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else if (task.identifier == MANIFEST_ID) { dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST, task.identifier, errorStr, errorCode, errorCodeInternal); _updateState = State::FAIL_TO_UPDATE; } else { fileError(task.identifier, errorStr, errorCode, errorCodeInternal); } }
int main(int argc, char **argv) { if (argc != 3) isError("argc"); struct LineFile *lf = create_LineFile(argv[1], 1, 1, -1); struct HT *ht1 = create_HT(1000000); struct HT *ht2 = create_HT(1000000); long i; for (i = 0; i < lf->linesNum; ++i) { insert_HE_HT(ht1, lf->i1[i]); insert_HE_HT(ht2, lf->i2[i]); } FILE *fp = fopen(argv[2], "w"); fileError(fp, "main"); for (i = 0; i < lf->linesNum; ++i) { fprintf(fp, "%d\t%d\n", get_index_HT(ht1, lf->i1[i]), get_index_HT(ht2, lf->i2[i])); } fclose(fp); free_HT(ht1); free_HT(ht2); free_LineFile(lf); return 0; }
void DataBlock::writeToMem(std::string path) { int data_size = size; boost::iostreams::mapped_file_params param(path); param.flags = boost::iostreams::mapped_file::mapmode::readwrite; param.new_file_size = data_size; param.length = data_size; boost::iostreams::mapped_file_sink fout(param); if (!fout.is_open()) { throw fileError(std::string("Cannot write file: ") + path); } // push data to file readData((void*)fout.data(), data_size); fout.close(); // change permission // NOTE: here there might be a security issue need to be addressed boost::filesystem::wpath wpath(path); boost::filesystem::permissions(wpath, boost::filesystem::add_perms | boost::filesystem::group_read | boost::filesystem::others_read); }
int main(int argc, char* argv[]) { if ( argc != 2 ) usage(argv[0]); typedef enum {IN_WS, IN_WORD} StateType; StateType state = IN_WS; FILE* f = fopen(argv[1], "r"); if ( f == NULL ) fileError(argv[1]); uint64_t chars=0, words=0, lines=0; char c; while ( (c = fgetc(f)) != EOF ) { chars++; if ( c == '\n' ) lines++; switch (state) { case IN_WS: if ( !isspace(c) ) { words++; state = IN_WORD; } break; case IN_WORD: if ( isspace(c) ) { state = IN_WS; } break; } } if ( 0 != fclose(f) ) { perror("fclose"); exit(3); } printf(" %" PRIu64 " lines, %" PRIu64 " words, %" PRIu64 " characters\n", lines, words, chars ); }
/* Check for errors and close file */ void fileClose(File *f) { if (ferror(f->fp)) { fileError(f); } fclose(f->fp); }
/* Seek on file */ void fileSeek(File *f, long offset, int wherefrom) { if (fseek(f->fp, offset, wherefrom) != 0) { fileError(f); } }
void PtexMainWriter::finish() { // do nothing if there's no new data to write if (!_hasNewData) return; // copy missing faces from _reader if (_reader) { for (int i = 0, nfaces = _header.nfaces; i < nfaces; i++) { if (_faceinfo[i].flags == uint8_t(-1)) { // copy face data const Ptex::FaceInfo& info = _reader->getFaceInfo(i); int size = _pixelSize * info.res.size(); if (info.isConstant()) { PtexPtr<PtexFaceData> data ( _reader->getData(i) ); if (data) { writeConstantFace(i, info, data->getData()); } } else { void* data = malloc(size); _reader->getData(i, data, 0); writeFace(i, info, data, 0); free(data); } } } } else { // just flag missing faces as constant (black) for (int i = 0, nfaces = _header.nfaces; i < nfaces; i++) { if (_faceinfo[i].flags == uint8_t(-1)) _faceinfo[i].flags = FaceInfo::flag_constant; } } // write reductions to tmp file if (_genmipmaps) generateReductions(); // flag faces w/ constant neighborhoods flagConstantNeighorhoods(); // update header _header.nlevels = uint16_t(_levels.size()); _header.nfaces = uint32_t(_faceinfo.size()); // create new file FILE* newfp = fopen(_newpath.c_str(), "wb+"); if (!newfp) { setError(fileError("Can't write to ptex file: ", _newpath.c_str())); return; } // write blank header (to fill in later) writeBlank(newfp, HeaderSize); writeBlank(newfp, ExtHeaderSize); // write compressed face info block _header.faceinfosize = writeZipBlock(newfp, &_faceinfo[0], sizeof(FaceInfo)*_header.nfaces); // write compressed const data block _header.constdatasize = writeZipBlock(newfp, &_constdata[0], int(_constdata.size())); // write blank level info block (to fill in later) FilePos levelInfoPos = ftello(newfp); writeBlank(newfp, LevelInfoSize * _header.nlevels); // write level data blocks (and record level info) std::vector<LevelInfo> levelinfo(_header.nlevels); for (int li = 0; li < _header.nlevels; li++) { LevelInfo& info = levelinfo[li]; LevelRec& level = _levels[li]; int nfaces = int(level.fdh.size()); info.nfaces = nfaces; // output compressed level data header info.levelheadersize = writeZipBlock(newfp, &level.fdh[0], sizeof(FaceDataHeader)*nfaces); info.leveldatasize = info.levelheadersize; // copy level data from tmp file for (int fi = 0; fi < nfaces; fi++) info.leveldatasize += copyBlock(newfp, _tmpfp, level.pos[fi], level.fdh[fi].blocksize()); _header.leveldatasize += info.leveldatasize; } rewind(_tmpfp); // write meta data (if any) if (!_metadata.empty()) writeMetaData(newfp); // update extheader for edit data position _extheader.editdatapos = ftello(newfp); // rewrite level info block fseeko(newfp, levelInfoPos, SEEK_SET); _header.levelinfosize = writeBlock(newfp, &levelinfo[0], LevelInfoSize*_header.nlevels); // rewrite header fseeko(newfp, 0, SEEK_SET); writeBlock(newfp, &_header, HeaderSize); writeBlock(newfp, &_extheader, ExtHeaderSize); fclose(newfp); }
bln FileCFILEStream::Open( const FilePath &path, FileOpenMode::mode_t openMode, FileProcMode::mode_t procMode, FileCacheMode::mode_t cacheMode, fileError *error ) { this->Close(); bln is_fileExists = Files::IsExists( path ); if( openMode == FileOpenMode::OpenExisting ) { if( !is_fileExists ) { DSA( error, Error::DoesNotExist() ); return false; } } if( openMode == FileOpenMode::CreateNew ) { if( is_fileExists ) { DSA( error, Error::AlreadyExists() ); return false; } } if( openMode == FileOpenMode::CreateAlways ) { if( !(procMode & FileProcMode::Write) ) { DSA( error, fileError( Error::InvalidArgument(), "FileOpenMode::CreateAlways cannot be used without FileProcMode::Write" ) ); return false; } } TCStr < pathChar > procModeStr; if( (procMode & FileProcMode::Read) && (procMode & FileProcMode::Write) ) { procModeStr += is_fileExists ? PLATFORM_PATH( "r+" ) : PLATFORM_PATH( "w+" ); } else if( procMode & FileProcMode::Read ) { procModeStr += PLATFORM_PATH( "r" ); } else { ASSUME( procMode & FileProcMode::Write ); procModeStr += PLATFORM_PATH( "w" ); } procModeStr += PLATFORM_PATH( "b" ); _file = fopen( path.PlatformPath(), procModeStr.CStr() ); if( !_file ) { DSA( error, fileError( Error::UnknownError(), "fopen has failed" ) ); return false; } if( (cacheMode & FileCacheMode::DisableSystemWriteCache) && (procMode & FileProcMode::Write) ) { if( setvbuf( (FILE *)_file, 0, _IONBF, 0 ) != 0 ) { DSA( error, fileError( Error::UnknownError(), "setvbuf has failed, cannot disable caching" ) ); fclose( (FILE *)_file ); _file = 0; return false; } } _procMode = procMode; _openMode = openMode; _cacheMode = cacheMode; _offsetToStart = 0; _bufferSize = 0; _customBufferPtr = 0; if( FileProcMode::WriteAppend & procMode ) { _offsetToStart = ftell( (FILE *)_file ); if( _offsetToStart == -1 ) { DSA( error, fileError( Error::UnknownError(), "ftell has failed" ) ); return false; } } DSA( error, Error::Ok() ); return true; }
int KMailBox::countMail() { QFile mbox(_file); char *buffer = new char[MAXSTR]; int count=0, msgCount=0; bool inHeader = false; bool hasContentLen = false; bool msgRead = false; long contentLength=0; if( isLocked() ){ // debug("countMail: locked. returning."); delete[] buffer; return _numMessages; } if(!mbox.open(IO_ReadOnly)) { warning(i18n("countMail: file open error")); emit fileError(); delete[]buffer; return 0; } buffer[MAXSTR-1] = 0; while(mbox.readLine(buffer, MAXSTR-2) > 0) { if( !strchr(buffer, '\n') && !mbox.atEnd() ){ int c; while( (c=mbox.getch()) >=0 && c !='\n' ) ; } if( !inHeader && realfrom(buffer) ) { hasContentLen = false; inHeader = true; msgRead = false; } else if ( inHeader ){ if (compareHeader(buffer, "Content-Length")){ hasContentLen = true; contentLength = atol(buffer+15); } if (compareHeader(buffer, "Status")) { const char *field = buffer; field += 7; while(field && (*field== ' '||*field == '\t')) field++; if ( *field == 'N' || *field == 'U' ) msgRead = false; else msgRead = true; } else if (buffer[0] == '\n' ) { if( hasContentLen ) mbox.at( mbox.at() + contentLength); inHeader = false; if ( !msgRead ) count++; } }//in header if(++msgCount >= 100 ) { qApp->processEvents(); msgCount = 0; } }//while mbox.close(); delete[] buffer; return count; }//countMail
/* we want to cut the first row and the fourth row. chromosomes and positions. But we want to check if the cromosomes are 1-22 These are the ones to include, so well return a keeplist, and the correct pars->chromo and pars->positions. This is rather slow because we use make a new vector on each line. This can be optimized in future versions. */ bArray *doBimFile(functionPars* pars,const char *filename,const std::string delim){ ///@param filename A filename to read.@param delim A string of delimiters. std::vector<int> chromos;//for all lines std::vector<double> positions;//for all lines const int SIZE=500000;//this should only be 6 elements but lets make it big.. char buffer[SIZE]; std::ifstream pFile (filename,std::ios::in); if(!pFile){ fileError(filename); exit(0); } std::string tmp_string; int itemsInRow; int numRows =0; while(!pFile.eof()){ pFile.getline(buffer,SIZE); tmp_string = std::string(buffer); std::vector<std::string> tokens; itemsInRow = get_lexemes(tmp_string,tokens,delim); if (itemsInRow!=6 && itemsInRow!=0){ printf("plink bim file:%s doesn't have 6 columns in row:%d\n",filename,numRows); exit(0); }else if(itemsInRow==0) break; chromos.push_back(atoi((tokens[0]).c_str())); positions.push_back(atof((tokens[3]).c_str())); numRows++; } // copy(chromos.begin(), chromos.end(), std::ostream_iterator<int>(std::cout, ", ")); // copy(positions.begin(), positions.end(), std::ostream_iterator<float>(std::cout, ", ")); bArray *ret = allocBoolArray(chromos.size()); int numTrue = 0; for(unsigned int i=0;i<chromos.size();i++) if(chromos[i]!=0 && chromos[i]<23 ){ ret->array[i] = 1; numTrue++; }else ret->array[i] = 0; ret->numTrue = numTrue; dArray *pos = allocDoubleArray(ret->numTrue); iArray *chr = allocIntArray(ret->numTrue); int atPos=0; for(int i=0;i<ret->x;i++){ if(ret->array[i]){ pos->array[atPos] = positions[i]/PLINK_POS_SCALING; chr->array[atPos] = chromos[i]; atPos++; } } pars->chr = chr; pars->position= pos; return ret; }
void QED2KSession::readAlerts() { std::auto_ptr<libed2k::alert> a = m_session->pop_alert(); while (a.get()) { if (libed2k::server_name_resolved_alert* p = dynamic_cast<libed2k::server_name_resolved_alert*>(a.get())) { emit serverNameResolved(QString::fromUtf8(p->endpoint.c_str(), p->endpoint.size())); } if (libed2k::server_connection_initialized_alert* p = dynamic_cast<libed2k::server_connection_initialized_alert*>(a.get())) { emit serverConnectionInitialized(p->client_id, p->tcp_flags, p->aux_port); qDebug() << "server initialized: " << QString::fromStdString(p->name) << " " << QString::fromStdString(p->host) << " " << p->port; } else if (libed2k::server_status_alert* p = dynamic_cast<libed2k::server_status_alert*>(a.get())) { emit serverStatus(p->files_count, p->users_count); } else if (libed2k::server_identity_alert* p = dynamic_cast<libed2k::server_identity_alert*>(a.get())) { emit serverIdentity(QString::fromUtf8(p->server_name.c_str(), p->server_name.size()), QString::fromUtf8(p->server_descr.c_str(), p->server_descr.size())); } else if (libed2k::server_message_alert* p = dynamic_cast<libed2k::server_message_alert*>(a.get())) { emit serverMessage(QString::fromUtf8(p->server_message.c_str(), p->server_message.size())); } else if (libed2k::server_connection_closed* p = dynamic_cast<libed2k::server_connection_closed*>(a.get())) { emit serverConnectionClosed(QString::fromLocal8Bit(p->m_error.message().c_str())); } else if (libed2k::shared_files_alert* p = dynamic_cast<libed2k::shared_files_alert*>(a.get())) { QList<QED2KSearchResultEntry> vRes; vRes.reserve(p->m_files.m_collection.size()); bool bMoreResult = p->m_more; for (size_t n = 0; n < p->m_files.m_collection.size(); ++n) { QED2KSearchResultEntry sre = QED2KSearchResultEntry::fromSharedFileEntry(p->m_files.m_collection[n]); if (sre.isCorrect()) vRes.push_back(sre); } // emit special signal for derived class if (libed2k::shared_directory_files_alert* p2 = dynamic_cast<libed2k::shared_directory_files_alert*>(p)) { emit peerSharedDirectoryFiles( p2->m_np, md4toQString(p2->m_hash), QString::fromUtf8(p2->m_strDirectory.c_str(), p2->m_strDirectory.size()), vRes); } else if (libed2k::ismod_shared_directory_files_alert* p2 = dynamic_cast<libed2k::ismod_shared_directory_files_alert*>(p)) { emit peerIsModSharedFiles(p2->m_np, md4toQString(p2->m_hash), md4toQString(p2->m_dir_hash), vRes); } else { emit searchResult(p->m_np, md4toQString(p->m_hash), vRes, bMoreResult); } } else if (libed2k::listen_failed_alert* p = dynamic_cast<libed2k::listen_failed_alert*>(a.get())) { Q_UNUSED(p) // TODO - process signal - it means we have different client on same port } else if (libed2k::peer_connected_alert* p = dynamic_cast<libed2k::peer_connected_alert*>(a.get())) { emit peerConnected(p->m_np, md4toQString(p->m_hash), p->m_active); } else if (libed2k::peer_disconnected_alert* p = dynamic_cast<libed2k::peer_disconnected_alert*>(a.get())) { emit peerDisconnected(p->m_np, md4toQString(p->m_hash), p->m_ec); } else if (libed2k::peer_message_alert* p = dynamic_cast<libed2k::peer_message_alert*>(a.get())) { emit peerMessage(p->m_np, md4toQString(p->m_hash), QString::fromUtf8(p->m_strMessage.c_str(), p->m_strMessage.size())); } else if (libed2k::peer_captcha_request_alert* p = dynamic_cast<libed2k::peer_captcha_request_alert*>(a.get())) { QPixmap pm; if (!p->m_captcha.empty()) pm.loadFromData((const uchar*)&p->m_captcha[0], p->m_captcha.size()); // avoid windows rtl error emit peerCaptchaRequest(p->m_np, md4toQString(p->m_hash), pm); } else if (libed2k::peer_captcha_result_alert* p = dynamic_cast<libed2k::peer_captcha_result_alert*>(a.get())) { emit peerCaptchaResult(p->m_np, md4toQString(p->m_hash), p->m_nResult); } else if (libed2k::shared_files_access_denied* p = dynamic_cast<libed2k::shared_files_access_denied*>(a.get())) { emit peerSharedFilesAccessDenied(p->m_np, md4toQString(p->m_hash)); } else if (libed2k::shared_directories_alert* p = dynamic_cast<libed2k::shared_directories_alert*>(a.get())) { QStringList qstrl; for (size_t n = 0; n < p->m_dirs.size(); ++n) { qstrl.append(QString::fromUtf8(p->m_dirs[n].c_str(), p->m_dirs[n].size())); } emit peerSharedDirectories(p->m_np, md4toQString(p->m_hash), qstrl); } else if (libed2k::added_transfer_alert* p = dynamic_cast<libed2k::added_transfer_alert*>(a.get())) { QED2KHandle h(p->m_handle); if (!h.is_seed()) m_currentSessionTransfers.insert(h.hash()); if (!m_addTimes.contains(h.hash())) { m_addTimes.insert(h.hash(), QDateTime::currentDateTime()); } if (m_sharedFiles.contains(h.hash())) { emit transferShared(h); } else { emit transferAdded(QED2KHandle(h)); } } else if (libed2k::paused_transfer_alert* p = dynamic_cast<libed2k::paused_transfer_alert*>(a.get())) { emit transferPaused(QED2KHandle(p->m_handle)); } else if (libed2k::resumed_transfer_alert* p = dynamic_cast<libed2k::resumed_transfer_alert*>(a.get())) { emit transferResumed(QED2KHandle(p->m_handle)); } else if (libed2k::deleted_transfer_alert* p = dynamic_cast<libed2k::deleted_transfer_alert*>(a.get())) { emit transferDeleted(QString::fromStdString(p->m_hash.toString())); } else if (libed2k::finished_transfer_alert* p = dynamic_cast<libed2k::finished_transfer_alert*>(a.get())) { QED2KHandle h(p->m_handle); if (m_sharedFiles.contains(h.hash())) { emit transferRestored(h); } else { emit transferFinished(h); } } else if (libed2k::save_resume_data_alert* p = dynamic_cast<libed2k::save_resume_data_alert*>(a.get())) { Preferences pref; QED2KHandle h(p->m_handle); QDateTime t; writeResumeData(p, misc::metadataDirectory(pref.inputDir()), QFile::exists(h.filepath()), m_addTimes.value(h.hash(), t)); } else if (libed2k::transfer_params_alert* p = dynamic_cast<libed2k::transfer_params_alert*>(a.get())) { QFileInfo info(misc::toQStringU(p->m_atp.file_path)); if (info.absoluteDir() == QDir(m_currentPath)) { emit transferParametersReady(p->m_atp, p->m_ec); if (!p->m_ec) m_sharedFiles << addTransfer(p->m_atp).hash(); else qDebug() << "transfer params error: " << misc::toQStringU(p->m_ec.message()); } else { qDebug() << "ignore add transfer parameters for old directory: " << misc::toQStringU(p->m_atp.file_path); } } else if (libed2k::file_renamed_alert* p = dynamic_cast<libed2k::file_renamed_alert*>(a.get())) { emit transferSavePathChanged(QED2KHandle(p->m_handle)); } else if (libed2k::storage_moved_alert* p = dynamic_cast<libed2k::storage_moved_alert*>(a.get())) { emit transferStorageMoved(QED2KHandle(p->m_handle)); } else if (libed2k::file_error_alert* p = dynamic_cast<libed2k::file_error_alert*>(a.get())) { QED2KHandle h(p->m_handle); if (h.is_valid()) { emit fileError(h, QString::fromLocal8Bit(p->error.message().c_str(), p->error.message().size())); h.pause(); } } else if (libed2k::portmap_error_alert* p = dynamic_cast<libed2k::portmap_error_alert*>(a.get())) { qDebug("UPnP Failure, msg: %s", p->message().c_str()); //addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1") // .arg(misc::toQString(p->message())), "red"); } else if (libed2k::portmap_alert* p = dynamic_cast<libed2k::portmap_alert*>(a.get())) { qDebug("UPnP Success, msg: %s", p->message().c_str()); //addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1") // .arg(misc::toQString(p->message())), "blue"); } a = m_session->pop_alert(); } // deferred transfers loading and files sharing if (!m_fastTransfers.empty()) { QList<QString> keys = m_fastTransfers.keys(); int counter = 10; while(!keys.empty() && counter != 0 ) { QString key = keys.takeFirst(); libed2k::transfer_resume_data trd = m_fastTransfers.take(key); libed2k::add_transfer_params atp; QString filepath = QDir(m_currentPath).filePath(misc::toQStringU(trd.m_filename.m_collection)); boost::shared_ptr<libed2k::base_tag> onDisk = trd.m_fast_resume_data.getTagByNameId(libed2k::CT_EMULE_RESERVED1); Q_ASSERT(onDisk); if (QFile::exists(filepath) || !onDisk->asBool()) { atp.seed_mode = false; // make full path for transfer startup atp.file_path = filepath.toUtf8().constData(); atp.file_size = trd.m_filesize; atp.file_hash = trd.m_hash; if (trd.m_fast_resume_data.count() > 0) { atp.resume_data = const_cast<std::vector<char>* >( &trd.m_fast_resume_data.getTagByNameId(libed2k::FT_FAST_RESUME_DATA)->asBlob()); } QED2KHandle h = addTransfer(atp); m_sharedFiles << h.hash(); boost::shared_ptr<libed2k::base_tag> addDt = trd.m_fast_resume_data.getTagByNameId(libed2k::CT_EMULE_RESERVED2); if (addDt) { m_addTimes.insert(h.hash(), QDateTime::fromString(misc::toQStringU(addDt->asString()), Qt::ISODate)); } } else { qDebug() << "fast resume data file" << key << " lost target file, remove resume data"; if (QFile::remove(QDir(misc::metadataDirectory(m_currentPath)).filePath(key))) { qDebug() << "fast resume data file erased"; } } --counter; } } else { int counter = 4; while(!m_pendingFiles.empty() && counter != 0) { makeTransferParametersAsync(m_pendingFiles.takeFirst()); --counter; } } }
void fileExecute(const char* inputFile, bool bSingleStep) { FILE *fp; char szBuffer[128]; char* token; int line = 0; if ((fp=fopen(inputFile, "r")) != NULL) { do { rewind(fp); while (fgets(szBuffer, 128, fp) != NULL) { ++line; if (szBuffer[0] != 0) { printf("Executing %s", szBuffer); } token = strtok(szBuffer, " "); if (token == NULL) { break; } if (strcasecmp(token, "version") == 0) { token = strtok(NULL, " "); if (token == NULL) { fileError(1, line); } else { Url url(token); token = strtok(NULL, " "); if (token == NULL) { fileError(2, line); } else { DataSet = token; requestVersion(url); } } } else if (strcasecmp(token, "get") == 0) { token = strtok(NULL, " "); if (token == NULL) { fileError(1, line); } else { Url url(token); token = strtok(NULL, " "); if (token == NULL) { fileError(2, line); } else { DataSet = token; UtlSList names; while (token != NULL) { token = strtok(NULL, " "); if (token != NULL) { names.append(new UtlString(token)); } } requestGet(url, names); names.destroyAll(); } } } else if (strcasecmp(token, "set") == 0) { token = strtok(NULL, " "); if (token == NULL) { fileError(1, line); } else { Url url(token); token = strtok(NULL, " "); if (token == NULL) { fileError(2, line); } else { DataSet = token; UtlHashMap parameters; char *key; char *value; while (token != NULL) { key = strtok(NULL, " "); if (key == NULL) { break; } value = strtok(NULL, " "); if (value == NULL) { fileError(3, line); break; } parameters.insertKeyAndValue(new UtlString(key), new UtlString(value)); } int entries = parameters.entries(); if (entries != 0 || (entries%2) == 0) { requestSet(url, parameters); parameters.destroyAll(); } } } } else if (strcasecmp(token, "delete") == 0) { token = strtok(NULL, " "); if (token == NULL) { fileError(1, line); } else { Url url(token); token = strtok(NULL, " "); if (token == NULL) { fileError(2, line); } else { DataSet = token; UtlSList names; while (token != NULL) { token = strtok(NULL, " "); if (token != NULL) { names.append(new UtlString(token)); } } requestDelete(url, names); names.destroyAll(); } } } else { fprintf(stderr, "Unknown RPC request %s - ignoring line\n", token); } if (bSingleStep) { getchar(); } } } while ( bRepeatFile ); fclose(fp); } else { fprintf(stderr, "Can't open %s\n", inputFile); exit(1); } }