void TUI::DrawSwapCacheStats () const { csPrintf (CS_ANSI_CURSOR(45,19) " "); if (globalLighter->swapManager) { uint64 swappedIn, swappedOut, maxSize; globalLighter->swapManager->GetSizes (swappedIn, swappedOut, maxSize); csPrintf (CS_ANSI_CURSOR(47,19) "%s/%s in, %s out", FormatByteSize (swappedIn).GetData(), FormatByteSize (maxSize).GetData(), FormatByteSize (swappedOut).GetData()); } csPrintf (CS_ANSI_CURSOR(1,1)); }
void Set(const TCHAR *_name, const DownloadStatus *_download_status, bool _failed) { name = _name; TCHAR path[MAX_PATH]; LocalPath(path, name); if (File::Exists(path)) { FormatByteSize(size.buffer(), size.MAX_SIZE, File::GetSize(path)); #ifdef HAVE_POSIX FormatISO8601(last_modified.buffer(), BrokenDateTime::FromUnixTimeUTC(File::GetLastModification(path))); #else // XXX implement last_modified.clear(); #endif } else { size.clear(); last_modified.clear(); } downloading = _download_status != NULL; if (downloading) download_status = *_download_status; failed = _failed; }
void ManagedFileListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned i) { const FileItem &file = items[i]; canvas.Select(row_renderer.GetFirstFont()); row_renderer.DrawFirstRow(canvas, rc, file.name.c_str()); canvas.Select(row_renderer.GetSecondFont()); if (file.downloading) { StaticString<64> text; if (file.download_status.position < 0) { text = _("Queued"); } else if (file.download_status.size > 0) { text.Format(_T("%s (%u%%)"), _("Downloading"), unsigned(file.download_status.position * 100 / file.download_status.size)); } else { TCHAR size[32]; FormatByteSize(size, ARRAY_SIZE(size), file.download_status.position); text.Format(_T("%s (%s)"), _("Downloading"), size); } row_renderer.DrawRightFirstRow(canvas, rc, text); } else if (file.failed) { const TCHAR *text = _("Error"); row_renderer.DrawRightFirstRow(canvas, rc, text); } row_renderer.DrawRightSecondRow(canvas, rc, file.last_modified.c_str()); row_renderer.DrawSecondRow(canvas, rc, file.size.c_str()); }
void UpdateInfoBoxFreeRAM(InfoBoxData &data) { #ifdef HAVE_MEM_INFO FormatByteSize(data.value.buffer(), data.value.MAX_SIZE, SystemFreeRAM(), true); #else data.SetInvalid(); #endif }
void ManagedFileListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned i) { const FileItem &file = items[i]; const unsigned margin = Layout::GetTextPadding(); canvas.Select(row_renderer.GetFirstFont()); row_renderer.DrawFirstRow(canvas, rc, file.name.c_str()); canvas.Select(row_renderer.GetSecondFont()); if (file.downloading) { StaticString<64> text; if (file.download_status.position < 0) { text = _("Queued"); } else if (file.download_status.size > 0) { text.Format(_T("%s (%u%%)"), _("Downloading"), unsigned(file.download_status.position * 100 / file.download_status.size)); } else { TCHAR size[32]; FormatByteSize(size, ARRAY_SIZE(size), file.download_status.position); text.Format(_T("%s (%s)"), _("Downloading"), size); } const unsigned width = canvas.CalcTextWidth(text); canvas.DrawText(rc.right - width - margin, rc.top + row_renderer.GetFirstY(), text); } else if (file.failed) { const TCHAR *text = _("Error"); const unsigned width = canvas.CalcTextWidth(text); canvas.DrawText(rc.right - width - margin, rc.top + row_renderer.GetFirstY(), text); } row_renderer.DrawSecondRow(canvas, rc, file.size.c_str()); canvas.DrawText((rc.left + rc.right) / 2, rc.top + row_renderer.GetSecondY(), file.last_modified.c_str()); }
void ManagedFileListWidget::OnPaintItem(Canvas &canvas, const PixelRect rc, unsigned i) { const FileItem &file = items[i]; const UPixelScalar margin = Layout::GetTextPadding(); canvas.DrawText(rc.left + margin, rc.top + margin, file.name.c_str()); if (file.downloading) { StaticString<64> text; if (file.download_status.position < 0) { text = _("Queued"); } else if (file.download_status.size > 0) { text.Format(_T("%s (%u%%)"), _("Downloading"), unsigned(file.download_status.position * 100 / file.download_status.size)); } else { TCHAR size[32]; FormatByteSize(size, ARRAY_SIZE(size), file.download_status.position); text.Format(_T("%s (%s)"), _("Downloading"), size); } UPixelScalar width = canvas.CalcTextWidth(text); canvas.DrawText(rc.right - width - margin, rc.top + margin, text); } else if (file.failed) { const TCHAR *text = _("Error"); UPixelScalar width = canvas.CalcTextWidth(text); canvas.DrawText(rc.right - width - margin, rc.top + margin, text); } canvas.DrawText(rc.left + margin, rc.top + 2 * margin + font_height, file.size.c_str()); canvas.DrawText((rc.left + rc.right) / 2, rc.top + 2 * margin + font_height, file.last_modified.c_str()); }
// --------------------------------------------------------------------------- void __fastcall TFrmMain::Grid1GetValue(TObject *Sender, const int Col, const int Row, TValue &Value) { if (UpdateGrid) { FileSearch(TreeView1->Selected->TagString, "*", Grid1); } // Init Data arrays // we not use Col - because Col return Column - but Column may realigned if (Row < Data.Length) { if (Grid1->Columns[Col] == ColumnName) { Value = TValue::From<String>(Data[Row]->FileName); } else if (Grid1->Columns[Col] == ColumnCreatedDate) { if (TFile::Exists(Data[Row]->ToString())) { Value = TValue::From<TDateTime>(TFile::GetCreationTime(Data[Row]->ToString())); } } else if (Grid1->Columns[Col] == ColumnModifiedDate) { if (TFile::Exists(Data[Row]->ToString())) { Value = TValue::From<TDateTime>(TFile::GetLastWriteTime(Data[Row]->ToString())); } } else if (Grid1->Columns[Col] == ColumnSize) { if (TFile::Exists(Data[Row]->ToString())) { Value = TValue::From<UnicodeString>(FormatByteSize(Data[Row]->Size())); } } else if (Grid1->Columns[Col] == ColumnFolderSize) { Value = TValue::From<double>((double)(Data[Row]->Size() / (double) Data[Row]->FolderSize) * 100); } } }
int main(int argc, char **argv) { plan_tests(31); TCHAR buffer[256]; FormatByteSize(buffer, ARRAY_SIZE(buffer), 0); ok1(StringIsEqual(buffer, _T("0 B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1); ok1(StringIsEqual(buffer, _T("1 B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 9); ok1(StringIsEqual(buffer, _T("9 B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10); ok1(StringIsEqual(buffer, _T("10 B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345); ok1(StringIsEqual(buffer, _T("345 B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024); ok1(StringIsEqual(buffer, _T("1.00 KB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 + 512); ok1(StringIsEqual(buffer, _T("1.50 KB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 9 * 1024); ok1(StringIsEqual(buffer, _T("9.00 KB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10 * 1024); ok1(StringIsEqual(buffer, _T("10.0 KB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345 * 1024); ok1(StringIsEqual(buffer, _T("345 KB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024); ok1(StringIsEqual(buffer, _T("1.00 MB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024 + 512 * 1024); ok1(StringIsEqual(buffer, _T("1.50 MB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 9 * 1024 * 1024); ok1(StringIsEqual(buffer, _T("9.00 MB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10 * 1024 * 1024); ok1(StringIsEqual(buffer, _T("10.0 MB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345 * 1024 * 1024); ok1(StringIsEqual(buffer, _T("345 MB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024 * 1024); ok1(StringIsEqual(buffer, _T("1.00 GB"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 0, true); ok1(StringIsEqual(buffer, _T("0B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1, true); ok1(StringIsEqual(buffer, _T("1B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10, true); ok1(StringIsEqual(buffer, _T("10B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345, true); ok1(StringIsEqual(buffer, _T("345B"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024, true); ok1(StringIsEqual(buffer, _T("1.0K"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 + 512, true); ok1(StringIsEqual(buffer, _T("1.5K"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 9 * 1024, true); ok1(StringIsEqual(buffer, _T("9.0K"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10 * 1024, true); ok1(StringIsEqual(buffer, _T("10.0K"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345 * 1024, true); ok1(StringIsEqual(buffer, _T("345K"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024, true); ok1(StringIsEqual(buffer, _T("1.0M"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024 + 512 * 1024, true); ok1(StringIsEqual(buffer, _T("1.5M"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 9 * 1024 * 1024, true); ok1(StringIsEqual(buffer, _T("9.0M"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 10 * 1024 * 1024, true); ok1(StringIsEqual(buffer, _T("10.0M"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 345 * 1024 * 1024, true); ok1(StringIsEqual(buffer, _T("345M"))); FormatByteSize(buffer, ARRAY_SIZE(buffer), 1 * 1024 * 1024 * 1024, true); ok1(StringIsEqual(buffer, _T("1.0G"))); return exit_status(); }