diff --git a/Client.cpp b/Client.cpp index 72573350..305d543c 100644 --- a/Client.cpp +++ b/Client.cpp @@ -1507,29 +1507,29 @@ void CClient::UserCommand(const CString& sLine) { for (map::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) { Table.AddRow(); Table.SetCell("Username", it->first); - Table.SetCell("In", CString(it->second->BytesRead())); - Table.SetCell("Out", CString(it->second->BytesWritten())); - Table.SetCell("Total", CString(it->second->BytesRead() + it->second->BytesWritten())); + Table.SetCell("In", CString::ToByteStr(it->second->BytesRead())); + Table.SetCell("Out", CString::ToByteStr(it->second->BytesWritten())); + Table.SetCell("Total", CString::ToByteStr(it->second->BytesRead() + it->second->BytesWritten())); users_total_in += it->second->BytesRead(); users_total_out += it->second->BytesWritten(); } Table.AddRow(); Table.SetCell("Username", ""); - Table.SetCell("In", CString(users_total_in)); - Table.SetCell("Out", CString(users_total_out)); - Table.SetCell("Total", CString(users_total_in + users_total_out)); + Table.SetCell("In", CString::ToByteStr(users_total_in)); + Table.SetCell("Out", CString::ToByteStr(users_total_out)); + Table.SetCell("Total", CString::ToByteStr(users_total_in + users_total_out)); Table.AddRow(); Table.SetCell("Username", ""); - Table.SetCell("In", CString(CZNC::Get().BytesRead())); - Table.SetCell("Out", CString(CZNC::Get().BytesWritten())); - Table.SetCell("Total", CString(CZNC::Get().BytesRead() + CZNC::Get().BytesWritten())); + Table.SetCell("In", CString::ToByteStr(CZNC::Get().BytesRead())); + Table.SetCell("Out", CString::ToByteStr(CZNC::Get().BytesWritten())); + Table.SetCell("Total", CString::ToByteStr(CZNC::Get().BytesRead() + CZNC::Get().BytesWritten())); Table.AddRow(); Table.SetCell("Username", ""); - Table.SetCell("In", CString(users_total_in + CZNC::Get().BytesRead())); - Table.SetCell("Out", CString(users_total_out + CZNC::Get().BytesWritten())); - Table.SetCell("Total", CString(users_total_in + CZNC::Get().BytesRead() + users_total_out + CZNC::Get().BytesWritten())); + Table.SetCell("In", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead())); + Table.SetCell("Out", CString::ToByteStr(users_total_out + CZNC::Get().BytesWritten())); + Table.SetCell("Total", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead() + users_total_out + CZNC::Get().BytesWritten())); if (Table.size()) { unsigned int uTableIdx = 0; diff --git a/String.cpp b/String.cpp index b4a05a64..72b61898 100644 --- a/String.cpp +++ b/String.cpp @@ -852,6 +852,25 @@ CString CString::ToKBytes(double d) { return szRet; } +CString CString::ToByteStr(unsigned long long d) { + const unsigned long long KiB = 1024; + const unsigned long long MiB = KiB * 1024; + const unsigned long long GiB = MiB * 1024; + const unsigned long long TiB = GiB * 1024; + + if (d > TiB) { + return CString(d / (double) TiB) + " TiB"; + } else if (d > GiB) { + return CString(d / (double) GiB) + " GiB"; + } else if (d > MiB) { + return CString(d / (double) MiB) + " MiB"; + } else if (d > KiB) { + return CString(d / (double) KiB) + " KiB"; + } + + return CString(d) + " B"; +} + bool CString::ToBool() const { return (!Trim_n().Trim_n("0").empty() && Trim_n().CaseCmp("false") != 0); } short CString::ToShort() const { return strtoul(this->c_str(), (char**) NULL, 10); } unsigned short CString::ToUShort() const { return strtoul(this->c_str(), (char**) NULL, 10); } diff --git a/String.h b/String.h index 7b49e937..3d575c28 100644 --- a/String.h +++ b/String.h @@ -129,6 +129,7 @@ public: static CString ToPercent(double d); static CString ToKBytes(double d); + static CString ToByteStr(unsigned long long d); bool ToBool() const; short ToShort() const;