Skip to content

Commit

Permalink
shellext: format scrub duration nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
maharmstone committed Mar 15, 2024
1 parent 80d81f1 commit 01720e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/shellext/scrub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@
#include <shlwapi.h>
#include <uxtheme.h>

static wstring format_duration(uint64_t dur, const wchar_t* fmt) {
int len = GetDurationFormatEx(LOCALE_NAME_USER_DEFAULT, 0, nullptr, dur,
fmt, nullptr, 0);
if (len == 0)
throw last_error(GetLastError());

wstring s;

s.resize(len);

if (GetDurationFormatEx(LOCALE_NAME_USER_DEFAULT, 0, nullptr, dur,
fmt, s.data(), s.size()) == 0)
throw last_error(GetLastError());

return s;
}

void BtrfsScrub::UpdateTextBox(HWND hwndDlg, btrfs_query_scrub* bqs) {
btrfs_query_scrub* bqs2 = nullptr;
bool alloc_bqs2 = false;
Expand Down Expand Up @@ -213,7 +230,14 @@ void BtrfsScrub::UpdateTextBox(HWND hwndDlg, btrfs_query_scrub* bqs) {

format_size((uint64_t)speed, d2, false);

wstring_sprintf(u, t, d1.c_str(), bqs2->duration / 10000000, d2.c_str());
wstring dur;

if (bqs2->duration >= 36000000000)
dur = format_duration(bqs2->duration, L"h:mm:ss");
else
dur = format_duration(bqs2->duration, L"m:ss");

wstring_sprintf(u, t, d1.c_str(), dur.c_str(), d2.c_str());

s += u;
s += L"\r\n";
Expand Down
2 changes: 1 addition & 1 deletion src/shellext/shellbtrfs.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ BEGIN
IDS_SCRUB_MSG_UNRECOVERABLE_METADATA_FIRSTITEM
"Unrecoverable metadata checksum error at %llx on device %llx (root %llx, level %x, first item %llx,%x,%llx)"
IDS_SCRUB_MSG_FINISHED "Scrub finished at %s %s."
IDS_SCRUB_MSG_SUMMARY "Scrubbed %s in %llu seconds (%s/s)."
IDS_SCRUB_MSG_SUMMARY "Scrubbed %s in %s (%s/s)."
IDS_BALANCE_SCRUB_RUNNING "Cannot start balance while scrub running."
IDS_SCRUB_BALANCE_RUNNING "Cannot start scrub while balance running."
IDS_SCRUB_MSG_SUMMARY_ERRORS_RECOVERABLE "Recovered from %llu error(s)."
Expand Down

0 comments on commit 01720e3

Please sign in to comment.