static void print_recov_stats( int forecast, const lmgr_recov_stat_t * p_stat ) { char buff[128]; unsigned long long diff; FormatFileSize( buff, 128, p_stat->status_size[RS_FILE_OK] + p_stat->status_size[RS_FILE_EMPTY] ); if (forecast) printf( " - full recovery: %Lu files (%s), %Lu non-files\n", p_stat->status_count[RS_FILE_OK] + p_stat->status_count[RS_FILE_EMPTY], buff, p_stat->status_count[RS_NON_FILE] ); else printf( " - successfully recovered: %Lu files (%s), %Lu non-files\n", p_stat->status_count[RS_FILE_OK] + p_stat->status_count[RS_FILE_EMPTY], buff, p_stat->status_count[RS_NON_FILE] ); FormatFileSize( buff, 128, p_stat->status_size[RS_FILE_DELTA] ); printf( " - old version: %10Lu entries (%s)\n", p_stat->status_count[RS_FILE_DELTA], buff ); FormatFileSize( buff, 128, p_stat->status_size[RS_NOBACKUP] ); printf( " - not recoverable: %10Lu entries (%s)\n", p_stat->status_count[RS_NOBACKUP], buff ); diff = p_stat->total - p_stat->status_count[RS_FILE_OK] - p_stat->status_count[RS_FILE_DELTA] - p_stat->status_count[RS_FILE_EMPTY] - p_stat->status_count[RS_NOBACKUP] - p_stat->status_count[RS_NON_FILE] - p_stat->status_count[RS_ERROR]; FormatFileSize( buff, 128, p_stat->status_size[RS_ERROR] ); if ( forecast ) printf( " - other/errors: %10Lu/%Lu (%s)\n", diff, p_stat->status_count[RS_ERROR], buff ); else { printf( " - errors: %10Lu entries (%s)\n", p_stat->status_count[RS_ERROR], buff ); printf( " - still to be recovered: %4Lu entries\n", diff ); } }
void CTextProgressCtrl::OnTimer(UINT nIDEvent) { if (nIDEvent == RedrawTimer) { FinishRedraw(); } else if (nIDEvent == ProgressRefreshTimer) { if (Downloader != NULL) { if (Downloader->GetTotalFileSize() > 0) { SetRange(0, Downloader->GetTotalFileSize()); SetPos(Downloader->GetDownloadedFileSize()); CString sText; sText.Format(_T("%s / %s"), FormatFileSize(Downloader->GetDownloadedFileSize()), FormatFileSize(Downloader->GetTotalFileSize())); m_strSize = sText; } else { int newPos = (int) Downloader->GetDownloadedFileSize(); if (newPos > Hi) { Hi *= 10; SetRange(0, Hi); } SetPos(newPos); } Redraw(FALSE); } } CWnd::OnTimer(nIDEvent); }
nglString nuiFileTree::GetFileInfo(const nglPath& rPath) { nglString str; nglPathInfo info; rPath.GetInfo(info); // file modification date nglTimeInfo timeInfo; nglString timestr; nglTime lastMod = info.LastMod; lastMod.GetLocalTime(timeInfo); timestr.Format(_T("%d/%d/%d, %d:%d"), timeInfo.Year+1900, timeInfo.Month, timeInfo.Day, timeInfo.Hours, timeInfo.Minutes); str.Append(timestr); if (rPath.IsLeaf()) { // file size str.Append(_T(" - ")); FormatFileSize(info.Size, str); } return str; }
void FileSharingWidget::renderFileSizeAndProgress(QPainter &p) { assert(Metainfo_.FileSize_ >= 0); if (Metainfo_.FileSizeStr_.isEmpty()) { Metainfo_.FileSizeStr_ = FormatFileSize(Metainfo_.FileSize_); } p.save(); QFont font = Utils::appFont(Utils::FontsFamily::SEGOE_UI, Utils::scale_value(12)); p.setFont(font); p.setPen(QColor(0x979797)); auto x = downloadButton().GetWidth(); x += Utils::scale_value(12); auto y = Utils::scale_value(47); QString text; if (isState(State::PlainFile_Downloading) || isState(State::PlainFile_Uploading)) { text = FormatFileSize(BytesTransferred_); text += " of "; } text += Metainfo_.FileSizeStr_; p.drawText(x, y, text); FileSizeAndProgressStr_ = text; p.restore(); }
void nsFolderCompactState::ShowDoneStatus() { if (m_folder) { nsString statusString; nsCOMPtr <nsIStringBundle> bundle; nsresult rv = GetBaseStringBundle(getter_AddRefs(bundle)); NS_ENSURE_SUCCESS_VOID(rv); nsAutoString expungedAmount; FormatFileSize(m_totalExpungedBytes, true, expungedAmount); const char16_t* params[] = { expungedAmount.get() }; rv = bundle->FormatStringFromName(u"compactingDone", params, 1, getter_Copies(statusString)); if (!statusString.IsEmpty() && NS_SUCCEEDED(rv)) ShowStatusMsg(statusString); } }
bool FileSharingWidget::getLocalFileMetainfo() { assert(FsInfo_); const auto &localPath = FsInfo_->GetLocalPath(); QFileInfo info(localPath); if (!info.exists()) { return false; } assert(Metainfo_.Filename_.isEmpty()); assert(Metainfo_.FileSize_ == 0); assert(Metainfo_.FileSizeStr_.isEmpty()); Metainfo_.Filename_ = info.fileName(); Metainfo_.FileSize_ = info.size(); Metainfo_.FileSizeStr_ = FormatFileSize(Metainfo_.FileSize_); return true; }
nsresult nsMimeHtmlDisplayEmitter::AddAttachmentField(const char *field, const char *value) { if (mSkipAttachment) return NS_OK; // Don't let bad things happen if ( !value || !*value ) return NS_OK; // Don't output this ugly header... if (!strcmp(field, HEADER_X_MOZILLA_PART_URL)) return NS_OK; nsCOMPtr<nsIMsgHeaderSink> headerSink; nsresult rv = GetHeaderSink(getter_AddRefs(headerSink)); if (NS_SUCCEEDED(rv) && headerSink) { headerSink->AddAttachmentField(field, value); } else { // Currently, we only care about the part size. if (strcmp(field, HEADER_X_MOZILLA_PART_SIZE)) return NS_OK; uint64_t size = atoi(value); nsAutoString sizeString; rv = FormatFileSize(size, false, sizeString); UtilityWrite("<td class=\"mimeAttachmentSize\">"); UtilityWrite(NS_ConvertUTF16toUTF8(sizeString).get()); UtilityWrite("</td>"); } return NS_OK; }
static void GetProps(Doc doc, PropertiesLayout *layoutData, DisplayModel *dm, bool extended) { CrashIf(!doc.IsEngine() && !doc.IsEbook()); DocType engineType = doc.GetDocType(); WCHAR *str = str::Dup(gPluginMode ? gPluginURL : doc.GetFilePath()); layoutData->AddProperty(_TR("File:"), str); str = doc.GetProperty(Prop_Title); layoutData->AddProperty(_TR("Title:"), str); str = doc.GetProperty(Prop_Subject); layoutData->AddProperty(_TR("Subject:"), str); str = doc.GetProperty(Prop_Author); layoutData->AddProperty(_TR("Author:"), str); str = doc.GetProperty(Prop_Copyright); layoutData->AddProperty(_TR("Copyright:"), str); str = doc.GetProperty(Prop_CreationDate); if (Engine_PDF == engineType) ConvDateToDisplay(&str, PdfDateParse); else if (Engine_XPS == engineType) ConvDateToDisplay(&str, IsoDateParse); else if (Engine_Epub == engineType || Doc_Epub == engineType) ConvDateToDisplay(&str, IsoDateParse); else if (Engine_Mobi == engineType || Doc_Mobi == engineType) ConvDateToDisplay(&str, IsoDateParse); layoutData->AddProperty(_TR("Created:"), str); str = doc.GetProperty(Prop_ModificationDate); if (Engine_PDF == engineType) ConvDateToDisplay(&str, PdfDateParse); else if (Engine_XPS == engineType) ConvDateToDisplay(&str, IsoDateParse); else if (Engine_Epub == engineType || Doc_Epub == engineType) ConvDateToDisplay(&str, IsoDateParse); else if (Engine_Mobi == engineType || Doc_Mobi == engineType) ConvDateToDisplay(&str, IsoDateParse); layoutData->AddProperty(_TR("Modified:"), str); str = doc.GetProperty(Prop_CreatorApp); layoutData->AddProperty(_TR("Application:"), str); str = doc.GetProperty(Prop_PdfProducer); // TODO: remove PDF from string layoutData->AddProperty(_TR("PDF Producer:"), str); str = doc.GetProperty(Prop_PdfVersion); layoutData->AddProperty(_TR("PDF Version:"), str); str = FormatPdfFileStructure(doc); layoutData->AddProperty(_TR("PDF Optimizations:"), str); size_t fileSize = file::GetSize(doc.GetFilePath()); if (fileSize == INVALID_FILE_SIZE && doc.IsEngine()) free(doc.AsEngine()->GetFileData(&fileSize)); if (fileSize != INVALID_FILE_SIZE) { str = FormatFileSize(fileSize); layoutData->AddProperty(_TR("File Size:"), str); } if (doc.IsEngine()) { str = str::Format(L"%d", doc.AsEngine()->PageCount()); layoutData->AddProperty(_TR("Number of Pages:"), str); } if (dm && dm->engineType != Engine_Chm) { str = FormatPageSize(dm->engine, dm->CurrentPageNo(), dm->Rotation()); if (IsUIRightToLeft() && IsVistaOrGreater()) { // ensure that the size remains ungarbled left-to-right // (note: XP doesn't know about \u202A...\u202C) str = str::Format(L"\u202A%s\u202C", ScopedMem<WCHAR>(str)); } layoutData->AddProperty(_TR("Page Size:"), str); } str = FormatPermissions(doc); layoutData->AddProperty(_TR("Denied Permissions:"), str); #if defined(DEBUG) || defined(ENABLE_EXTENDED_PROPERTIES) if (extended) { // TODO: FontList extraction can take a while str = doc.GetProperty(Prop_FontList); if (str) { // add a space between basic and extended file properties layoutData->AddProperty(L" ", str::Dup(L" ")); } layoutData->AddProperty(_TR("Fonts:"), str); } #endif }
/** parse date/time yyyymmdd[HH[MM[SS]]] */ time_t str2date( char *str ) { struct tm datetime = { .tm_sec = 0, .tm_min = 0, .tm_hour = 0, .tm_mday = 0, .tm_mon = 0, .tm_year = 0, .tm_wday = 0, .tm_yday = 0, .tm_isdst = -1 }; char tmpstr[16]; int tmpint; char * curr = str; /* extract year */ if (extract_digits(curr, tmpstr, 4) < 4) return (time_t)-1; curr += 4; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; datetime.tm_year = tmpint - 1900; /* 1900 => 0 */ /* extract month */ if (extract_digits(curr, tmpstr, 2) < 2) return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) <= 0) return (time_t)-1; else if (tmpint > 12) return (time_t)-1; datetime.tm_mon = tmpint - 1; /* January => 0 */ /* extract day */ if (extract_digits(curr, tmpstr, 2) < 2) return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) <= 0) return (time_t)-1; else if (tmpint > 31) return (time_t)-1; datetime.tm_mday = tmpint; /* 1st => 1 */ /* extract hours */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 23) return (time_t)-1; datetime.tm_hour = tmpint; /* extract minutes */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 59) return (time_t)-1; datetime.tm_min = tmpint; /* extract seconds */ tmpint = extract_digits(curr, tmpstr, 2); if (tmpint == 0) /* not specified */ goto convert; else if (tmpint < 2) /* invalid */ return (time_t)-1; curr += 2; if ((tmpint = str2int(tmpstr)) == -1) return (time_t)-1; else if (tmpint > 59) return (time_t)-1; datetime.tm_sec = tmpint; if (*curr != '\0') return (time_t)-1; convert: return mktime(&datetime); } /** * Print attributes to a string */ int PrintAttrs( char *out_str, size_t strsize, const attr_set_t * p_attr_set, int overide_mask ) { int mask = p_attr_set->attr_mask; size_t written = 0; char tmpbuf[256]; if ( overide_mask ) mask = mask & overide_mask; if ( mask & ATTR_MASK_fullpath ) written += snprintf( out_str + written, strsize - written, "Fullpath: \"%s\"\n", ATTR( p_attr_set, fullpath ) ); if ( mask & ATTR_MASK_name ) written += snprintf( out_str + written, strsize - written, "Name: \"%s\"\n", ATTR( p_attr_set, name ) ); #ifdef ATTR_INDEX_type if ( mask & ATTR_MASK_type ) written += snprintf( out_str + written, strsize - written, "Type: %s\n", ATTR( p_attr_set, type ) ); #endif if ( mask & ATTR_MASK_owner ) written += snprintf( out_str + written, strsize - written, "Owner: \"%s\"\n", ATTR( p_attr_set, owner ) ); if ( mask & ATTR_MASK_gr_name ) written += snprintf( out_str + written, strsize - written, "Group: \"%s\"\n", ATTR( p_attr_set, gr_name ) ); if ( mask & ATTR_MASK_size ) { FormatFileSize( tmpbuf, 256, ATTR( p_attr_set, size ) ); written += snprintf( out_str + written, strsize - written, "Size: %s\n", tmpbuf ); } if ( mask & ATTR_MASK_depth ) written += snprintf( out_str + written, strsize - written, "Depth: %d\n", ATTR( p_attr_set, depth ) ); #ifdef ATTR_INDEX_dircount if ( mask & ATTR_MASK_dircount ) written += snprintf( out_str + written, strsize - written, "DirCount: %d\n", ATTR( p_attr_set, dircount ) ); #endif if ( mask & ATTR_MASK_last_access ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_access ) ); written += snprintf( out_str + written, strsize - written, "Last Access: %s ago\n", tmpbuf ); } #ifdef ATTR_INDEX_last_copy if ( mask & ATTR_MASK_last_copy ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_copy ) ); written += snprintf( out_str + written, strsize - written, "Last Copy: %s ago\n", tmpbuf ); } #endif if ( mask & ATTR_MASK_last_mod ) { FormatDurationFloat( tmpbuf, 256, time( NULL ) - ATTR( p_attr_set, last_mod ) ); written += snprintf( out_str + written, strsize - written, "Last Mod: %s ago\n", tmpbuf ); } return written; }
static int recov_list(recov_type_e state) { struct lmgr_iterator_t *it; int rc; entry_id_t id; attr_set_t attrs; char buff[128]; recov_status_t st; const char *status; /* TODO iter opt */ it = ListMgr_RecovList(&lmgr, state); if (it == NULL) { fprintf(stderr, "ERROR: cannot get the list of entries\n"); return -1; } attrs.attr_mask = RECOV_ATTR_MASK; printf("%-8s %-15s %-40s %s\n", "type", "state", "path", "size"); while (!terminate && ((rc = ListMgr_RecovGetNext(it, &id, &attrs, &st)) != DB_END_OF_LIST)) { if (rc) { fprintf(stderr, "ERROR %d getting entry from recovery table\n", rc); ListMgr_CloseIterator(it); return rc; } FormatFileSize(buff, 128, ATTR(&attrs, size)); switch (st) { case RS_FILE_OK: status = "done"; break; case RS_FILE_DELTA: status = "done_old_data"; break; case RS_NON_FILE: status = "done_non_file"; break; case RS_FILE_EMPTY: status = "done_empty"; break; case RS_NOBACKUP: status = "done_no_backup"; break; case RS_ERROR: status = "failed"; break; case -1: status = "todo"; break; default: status = "?"; } printf("%-8s %-15s %-40s %s\n", ATTR(&attrs, type), status, ATTR(&attrs, fullpath), buff); /* reset mask */ attrs.attr_mask = RECOV_ATTR_MASK; } return 0; }
static int recov_resume(int retry_errors) { struct lmgr_iterator_t *it; int rc, st; entry_id_t id, new_id; attr_set_t attrs, new_attrs; char buff[128]; /* TODO iter opt */ it = ListMgr_RecovResume(&lmgr, path_filter, retry_errors, NULL); if (it == NULL) { fprintf(stderr, "ERROR: cannot get the list of entries to be recovered\n"); return -1; } attrs.attr_mask = RECOV_ATTR_MASK; while (!terminate && ((rc = ListMgr_RecovGetNext(it, &id, &attrs, NULL)) != DB_END_OF_LIST)) { if (rc) { fprintf(stderr, "ERROR %d getting entry from recovery table\n", rc); ListMgr_CloseIterator(it); return rc; } FormatFileSize(buff, 128, ATTR(&attrs, size)); if (ATTR_MASK_TEST(&attrs, fullpath)) printf("Restoring %s (%s)...", ATTR(&attrs, fullpath), buff); else printf("Restoring " DFID " (%s)...", PFID(&id), buff); /* TODO process entries asynchronously, in parallel, in separate * threads */ st = rbhext_recover(&id, &attrs, &new_id, &new_attrs, NULL); if ((st == RS_FILE_OK) || (st == RS_FILE_EMPTY) || (st == RS_NON_FILE) || (st == RS_FILE_DELTA)) { /* don't insert readonly attrs */ new_attrs.attr_mask &= ~readonly_attr_set; /* insert the entry in the database, and update recovery status */ rc = ListMgr_Insert(&lmgr, &new_id, &new_attrs, true); if (rc) { fprintf(stderr, "DB insert failure for '%s'\n", ATTR(&new_attrs, fullpath)); st = RS_ERROR; } } /* old id must be used for impacting recovery table */ if (ListMgr_RecovSetState(&lmgr, &id, st)) st = RS_ERROR; switch (st) { case RS_FILE_OK: printf(" OK\n"); break; case RS_FILE_DELTA: printf(" OK (old version)\n"); break; case RS_NON_FILE: printf(" OK (non-file)\n"); break; case RS_FILE_EMPTY: printf(" OK (empty file)\n"); break; case RS_NOBACKUP: printf(" No backup available\n"); break; case RS_ERROR: printf(" FAILED\n"); break; default: printf(" ERROR st=%d, rc=%d\n", st, rc); break; } /* reset mask */ attrs.attr_mask = RECOV_ATTR_MASK; } return 0; }
static void GetProps(Controller *ctrl, PropertiesLayout *layoutData, bool extended) { CrashIf(!ctrl); WCHAR *str = str::Dup(gPluginMode ? gPluginURL : ctrl->FilePath()); layoutData->AddProperty(_TR("File:"), str, true); str = ctrl->GetProperty(Prop_Title); layoutData->AddProperty(_TR("Title:"), str); str = ctrl->GetProperty(Prop_Subject); layoutData->AddProperty(_TR("Subject:"), str); str = ctrl->GetProperty(Prop_Author); layoutData->AddProperty(_TR("Author:"), str); str = ctrl->GetProperty(Prop_Copyright); layoutData->AddProperty(_TR("Copyright:"), str); str = ctrl->GetProperty(Prop_CreationDate); if (str && ctrl->AsFixed() && Engine_PDF == ctrl->AsFixed()->engineType) ConvDateToDisplay(&str, PdfDateParse); else ConvDateToDisplay(&str, IsoDateParse); layoutData->AddProperty(_TR("Created:"), str); str = ctrl->GetProperty(Prop_ModificationDate); if (str && ctrl->AsFixed() && Engine_PDF == ctrl->AsFixed()->engineType) ConvDateToDisplay(&str, PdfDateParse); else ConvDateToDisplay(&str, IsoDateParse); layoutData->AddProperty(_TR("Modified:"), str); str = ctrl->GetProperty(Prop_CreatorApp); layoutData->AddProperty(_TR("Application:"), str); str = ctrl->GetProperty(Prop_PdfProducer); layoutData->AddProperty(_TR("PDF Producer:"), str); str = ctrl->GetProperty(Prop_PdfVersion); layoutData->AddProperty(_TR("PDF Version:"), str); str = FormatPdfFileStructure(ctrl); layoutData->AddProperty(_TR("PDF Optimizations:"), str); int64 fileSize = file::GetSize(ctrl->FilePath()); if (-1 == fileSize && ctrl->AsFixed()) { size_t fileSizeT; if (ScopedMem<unsigned char>(ctrl->AsFixed()->GetEngine()->GetFileData(&fileSizeT))) fileSize = fileSizeT; } if (-1 != fileSize) { str = FormatFileSize((size_t)fileSize); layoutData->AddProperty(_TR("File Size:"), str); } // TODO: display page count per current layout for ebooks? if (!ctrl->AsEbook()) { str = str::Format(L"%d", ctrl->PageCount()); layoutData->AddProperty(_TR("Number of Pages:"), str); } if (ctrl->AsFixed()) { str = FormatPageSize(ctrl->AsFixed()->GetEngine(), ctrl->CurrentPageNo(), ctrl->AsFixed()->GetRotation()); if (IsUIRightToLeft() && IsVistaOrGreater()) { // ensure that the size remains ungarbled left-to-right // (note: XP doesn't know about \u202A...\u202C) WCHAR *tmp = str; str = str::Format(L"\u202A%s\u202C", tmp); free(tmp); } layoutData->AddProperty(_TR("Page Size:"), str); } str = FormatPermissions(ctrl); layoutData->AddProperty(_TR("Denied Permissions:"), str); #if defined(DEBUG) || defined(ENABLE_EXTENDED_PROPERTIES) if (extended) { // TODO: FontList extraction can take a while str = ctrl->GetProperty(Prop_FontList); if (str) { // add a space between basic and extended file properties layoutData->AddProperty(L" ", str::Dup(L" ")); } layoutData->AddProperty(_TR("Fonts:"), str); } #else UNUSED(extended); #endif }