bool BAMseek::loadFile(const std::string & filename){ QProgressDialog progress("Indexing file.", "Cancel file load.", 0, 100, this); progress.setWindowModality(Qt::WindowModal); slider->setRange(1, 1); spinbox->setRange(1,1); slider->setValue(1); spinbox->setValue(1); pr.reset(new PageReader(filename, &progress)); if(pr->invalid){ pr.reset(0); header->clear(); header->append(tr("Unable to recognize file as a BAM or SAM file")); header->append(tr(filename.c_str())); return false; } std::string title = filename + " (" + getFileSizeString(filename) + ")"; setWindowTitle(tr(title.c_str())); header->clear(); header->append(tr(pr->getHeader().c_str())); slider->setRange(1, pr->getNumPages()); spinbox->setRange(1,pr->getNumPages()); slider->setValue(1); spinbox->setValue(1); jumpToPage(1); return true; }
string visualmd5sum(const char * pathname) { int n; char buf[SLICECAP]; unsigned char out[MD5_DIGEST_LENGTH]; string md5str; int oldProgress = 0, newProgress = 0; MD5_CTX ctx; uint32_t nslice = 0, sindex = 0; string tipstr; tipstr += "\033[32mMD5SUM\033[0m("; tipstr += pathname; tipstr += ")"; string hfilesize = getFileSizeString(pathname); if ( (n = getFileNslice(pathname, &nslice)) < 0) { Error::msg("getFileNslice error"); return md5str; } FILE *fp; if ( (fp = fopen(pathname, "rb")) == NULL) { Error::ret("md5sum#fopen"); return md5str; } MD5_Init(&ctx); while( (n = fread(buf, sizeof(char), SLICECAP, fp)) >0 ) { MD5_Update(&ctx, buf, n); if (nslice > (1024 * 512)) { newProgress = (++sindex*1.0)/nslice*100; if (newProgress > oldProgress) { //printf("\033[2K\r\033[0m"); fprintf(stderr, "\033[2K\r\033[0m%-40s%10s\t%3d%%", tipstr.c_str(), hfilesize.c_str(), newProgress); } oldProgress = newProgress; } } if (nslice > (1024 * 512)) printf("\n"); MD5_Final(out, &ctx); for(n = 0; n< MD5_DIGEST_LENGTH; n++) { snprintf(buf, SLICECAP, "%02x", out[n]); md5str += buf; } return md5str; }
// Returns a friendly string for the total size of files remaining to download in torrent inline std::string getTextRemaining() { return getFileSizeString(getRemaining()); }
// Returns a friendly string for the total size of files in torrent inline std::string getTextSize() { return getFileSizeString(getSize()); }
// Returns a friendly string for the current download total inline std::string getTextTotalDownloaded() { return getFileSizeString(getTotalDownloaded()); }
std::string getRateString(int64_t file_rate) { return getFileSizeString(file_rate) + (file_rate ? "/s" : ""); }
std::string gt::Torrent::getTextRemaining() { return getFileSizeString(getRemaining()); }
std::string gt::Torrent::getTextSize() { return getFileSizeString(getSize()); }
std::string gt::Torrent::getTextTotalDownloaded() { return getFileSizeString(getTotalDownloaded()); }
void SrvDTP::sendFile(const char *pathname, uint32_t nslice, uint32_t sindex, uint16_t slicecap) { //cout << endl << endl << pathname << endl << endl; Packet & packet = *(this->ppacket); char buf[MAXLINE]; Database * pdb = psrvPI->getPDB(); string inode = getInode(pathname); std::map<string, string> selectParamMap = { {"INODE", inode} }; if (pdb->select("file", selectParamMap)) { vector< map<string ,string> > resultMapVector = pdb->getResult(); if (!resultMapVector.empty()) { string dbAccess = resultMapVector[0]["ACCESS"]; unsigned long long access = std::stoull(dbAccess) + 1; snprintf(buf, MAXLINE, "%llu", access); dbAccess = buf; std::map<string, string> updateParamMap = { {"ACCESS", dbAccess} }; if (pdb->update("file", resultMapVector[0]["ID"], updateParamMap)) { cout << "update ACCESS+1 ok" <<endl; } else { printf("\033[31mupdate ACCESS+1 error\033[0m\n"); } } else { printf("\033[31mINODE not exist\033[0m\n"); } } else { Error::msg("\033[31mDatabase select error\033[0m\n"); } int n; //uint32_t nslice =0, sindex = 0; // off64_t curpos = sindex * slicecap; // if ( lseek64(fileno(psrvPI->getFp()), curpos, SEEK_SET) < 0) // { // packet.sendSTAT_ERR(strerror_r(errno, buf, MAXLINE)); // return; // } else { // printf("Recv file [%s %u/%u] now\n", pathname, sindex, nslice); // // send STAT_OK // packet.sendSTAT_OK(); // } string sizestr = getFilesize(string(pathname)); if (sizestr.empty()) { packet.sendSTAT_ERR("getFilesize() failed"); return; } // confirm enough space to write on client host packet.sendSTAT(STAT_SIZE, sizestr); psrvPI->recvOnePacket(); if (packet.getTagid() == TAG_STAT && packet.getStatid() == STAT_ERR) { return; } else if (packet.getTagid() == TAG_STAT && packet.getStatid() == STAT_OK) { ; } else { Error::msg("unknown packet"); packet.print(); return; } //if ( (fp = fopen(pathname, "rb")) == NULL) if ( psrvPI->setFp(fopen(pathname, "rb")) == NULL) { // send STAT_ERR Response // GNU-specific strerror_r: char *strerror_r(int errnum, char *buf, size_t buflen); packet.sendSTAT_ERR(strerror_r(errno, buf, MAXLINE)); return; } else if ( (n = getFileNslice(pathname, &nslice)) <= 0) { if ( n == 0) { printf("EOF[%s]: 0 bytes\n", pathname); Fclose(&psrvPI->getFp()); packet.sendSTAT_OK(); packet.sendDATA_TEXT(getFileSizeString(pathname)); packet.sendDATA_FILE(0, 0, 0, NULL); packet.sendSTAT_EOF("EOF: 0 bytes"); return; } else if ( n == -2) { snprintf(buf, MAXLINE, "Too large file size"); packet.sendSTAT_ERR(buf); } else { snprintf(buf, MAXLINE, "File stat error"); packet.sendSTAT_ERR(buf); } return; } else { // send STAT_OK packet.sendSTAT_OK(); } packet.sendDATA_TEXT(getFileSizeString(pathname)); char body[PBODYCAP]; printf("Send [%s] now\n", pathname); while( (n = fread(body, sizeof(char), PBODYCAP, psrvPI->getFp())) >0 ) { packet.sendDATA_FILE(nslice, ++sindex, n, body); } // send EOF Fclose(&psrvPI->getFp()); printf("EOF [%s]\n", pathname); packet.sendSTAT_EOF(); }
// Returns a friendly string for the current upload total inline string getTextTotalUploaded() { return getFileSizeString(getTotalUploaded()); }