uint32_t ArchiveMemberHeader::getSize() const { auto* end = static_cast<const char*>(memchr(size, ' ', sizeof(size))); std::string sizeString((const char*)size, end); auto sizeInt = std::stoll(sizeString, nullptr, 10); if (sizeInt < 0 || sizeInt >= std::numeric_limits<uint32_t>::max()) { wasm::Fatal() << "Malformed archive: size parsing failed\n"; } return static_cast<uint32_t>(sizeInt); }
void FileInfoListView::addItem(int index, FileInfo *fileInfo) { const TCHAR *filename = fileInfo->getFileName(); int imageIndex = IMAGE_FILE_INDEX; if (_tcscmp(fileInfo->getFileName(), _T("..")) == 0) { imageIndex = IMAGE_FOLDER_UP_INDEX; } else if (fileInfo->isDirectory()) { imageIndex = IMAGE_FOLDER_INDEX; } ListView::addItem(index, filename, (LPARAM)fileInfo, imageIndex); StringStorage sizeString(_T("<Folder>")); StringStorage modTimeString(_T("")); if (!fileInfo->isDirectory()) { // // Prepare size string // UINT64 fileSize = fileInfo->getSize(); if (fileSize <= 1024) { sizeString.format(_T("%ld B"), fileSize); } else if ((fileSize > 1024) && (fileSize <= 1024 * 1024)) { sizeString.format(_T("%4.2f KB"), static_cast<double>(fileSize) / 1024.0); } else if (fileSize > 1024 * 1024) { sizeString.format(_T("%4.2f MB"), static_cast<double>(fileSize) / (1024.0 * 1024)); } // // Prepare modification time string // DateTime dateTime(fileInfo->lastModified()); dateTime.toString(&modTimeString); } ListView::setSubItemText(index, 1, sizeString.getString()); ListView::setSubItemText(index, 2, modTimeString.getString()); ListView::sort(); }
void QtWebKitChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) { // save scrollbar maximum value if (!topMessageAdded_) { scrollBarMaximum_ = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical); } topMessageAdded_ = true; QWebElement continuationElement = firstElement_.findFirst("#insert"); bool insert = snippet->getAppendToPrevious(); bool fallback = continuationElement.isNull(); boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet; QWebElement newElement = snippetToDOM(newSnippet); if (insert && !fallback) { Q_ASSERT(!continuationElement.isNull()); continuationElement.replace(newElement); } else { continuationElement.removeFromDocument(); topInsertPoint_.prependOutside(newElement); } firstElement_ = newElement; if (lastElement_.isNull()) { lastElement_ = firstElement_; } if (fontSizeSteps_ != 0) { double size = 1.0 + 0.2 * fontSizeSteps_; QString sizeString(QString().setNum(size, 'g', 3) + "em"); const QWebElementCollection spans = firstElement_.findAll("span.swift_resizable"); Q_FOREACH (QWebElement span, spans) { span.setStyleProperty("font-size", sizeString); }
bool QTarDecode::decodeData(const std::vector<char> &data) { setErrorString("Unknown error"); if(data.size()<1024) return false; unsigned int offset=0; while(offset<data.size()) { //load the file name from ascii, from 0+offset with size of 100 std::string fileName(data.data()+offset,100); while(!fileName.empty() && fileName.at(fileName.size()-1)==0x00) fileName.resize(fileName.size()-1); //load the file type std::string fileType(data.data()+156+offset,1); while(!fileName.empty() && fileType.at(fileType.size()-1)==0x00) fileType.resize(fileType.size()-1); //load the ustar string std::string ustar(data.data()+257+offset,5); while(!fileName.empty() && ustar.at(ustar.size()-1)==0x00) ustar.resize(ustar.size()-1); //load the ustar version std::string ustarVersion(data.data()+263+offset,2); while(!fileName.empty() && ustarVersion.at(ustarVersion.size()-1)==0x00) ustarVersion.resize(ustarVersion.size()-1); bool ok=false; //load the file size from ascii, from 124+offset with size of 12 uint64_t finalSize=0; std::string sizeString(data.data()+124+offset,12); if(sizeString.at(sizeString.size()-1)==0x00) { //the size is in octal base sizeString.resize(sizeString.size()-1); finalSize=octaltouint64(sizeString,&ok); } else finalSize=stringtouint64(sizeString,&ok); //if the size conversion to qulonglong have failed, then qui with error if(ok==false) { //it's the end of the archive, no more verification break; } //if check if the ustar not found if(ustar!="ustar") { setErrorString("\"ustar\" string not found at "+std::to_string(257+offset)+", content: \""+ustar+"\""); return false; } if(ustarVersion!="00") { setErrorString("ustar version string is wrong, content:\""+ustarVersion+"\""); return false; } //check if the file have the good size for load the data if((offset+512+finalSize)>data.size()) { setErrorString("The tar file seem be too short"); return false; } if(fileType=="0") //this code manage only the file, then only the file is returned { std::vector<char> newdata; newdata.resize(finalSize); memcpy(newdata.data(),data.data()+512+offset,finalSize); fileList.push_back(fileName); dataList.push_back(newdata); } //calculate the offset for the next header bool retenu=((finalSize%512)!=0); //go to the next header offset+=512+(finalSize/512+retenu)*512; } if(fileList.size()>0) { std::string baseDirToTest=fileList.at(0); std::size_t found = baseDirToTest.find_last_of("/"); if(found!=std::string::npos && found>=baseDirToTest.size()) baseDirToTest.resize(baseDirToTest.size()-(baseDirToTest.size()-found)); bool isFoundForAllEntries=true; for (unsigned int i = 0; i < fileList.size(); ++i) if(!stringStartWith(fileList.at(i),baseDirToTest)) isFoundForAllEntries=false; if(isFoundForAllEntries) for (unsigned int i = 0; i < fileList.size(); ++i) fileList[i].erase(0,baseDirToTest.size()); } return true; }
void ImageSearchQuerySettings::addImageSizeToUrl() { QString sizeString("Large"); qDebug() << "TODO: implement ImageSizeToURL()"; addKeyValueToUrl("imgsz", sizeString); }
void BackupListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete) { BListView* list = dynamic_cast<BListView*>(owner); if (list == NULL) return; owner->PushState(); BRect bounds = list->ItemFrame(list->IndexOf(this)); rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); rgb_color backgroundColor = ui_color(B_LIST_BACKGROUND_COLOR); if (fIndex % 2) backgroundColor = (rgb_color){ 247, 247, 247, 255 }; // draw background list->SetDrawingMode(B_OP_OVER); list->SetHighColor(backgroundColor); list->FillRect(bounds); // set proper colors for "normal" items list->SetHighColor(textColor); list->SetLowColor(backgroundColor); // Set up points for things in BListItem BPoint checkboxPt = bounds.LeftTop(); BPoint namePt = bounds.LeftTop(); BPoint descriptionPt = bounds.LeftTop(); BPoint sizePt = bounds.RightTop(); namePt += BPoint(16 + 8, fFirstlineOffset); sizePt += BPoint(0, fFirstlineOffset); descriptionPt += BPoint(16 + 8, fSecondlineOffset); checkboxPt += BPoint(4, 2); list->SetFont(be_bold_font); list->DrawString(fName.String(), namePt); char sizeText[512]; size_to_string(fSize, sizeText, 512); BString sizeString(sizeText); list->SetFont(be_plain_font); sizePt -= BPoint( be_plain_font->StringWidth(sizeString.String()) + 4.0f, 0); list->DrawString(sizeString.String(), sizePt); if (textColor.red + textColor.green + textColor.blue > 128 * 3) list->SetHighColor(tint_color(textColor, B_DARKEN_1_TINT)); else list->SetHighColor(tint_color(textColor, B_LIGHTEN_1_TINT)); list->SetFontSize(11); list->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); list->DrawString(fDescription.String(), descriptionPt); if (!fEnabled) { fEnabled = new BCheckBox(BRect(0, 0, 16, 16), fName.String(), fName.String(), new BMessage(kMsgUpdateSelection)); list->AddChild(fEnabled); // First run, set default value fEnabled->SetValue(gLocationMap[fIndex].defaultValue ? B_CONTROL_ON : B_CONTROL_OFF); } fEnabled->SetHighColor(textColor); fEnabled->SetLowColor(backgroundColor); fEnabled->MoveTo(checkboxPt.x, checkboxPt.y); owner->PopState(); }