From cdf8d103f1ed6a932eb30b589b578d23ca66a514 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 10 May 2021 18:49:44 +0200 Subject: Add downloader, fix room navigation lag Fix bug where getting next page fails if there is no search bar --- src/Storage.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Storage.cpp') diff --git a/src/Storage.cpp b/src/Storage.cpp index 6a98267..85a150c 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -259,4 +259,22 @@ namespace QuickMedia { return false; } + + std::string file_size_to_human_readable_string(size_t bytes) { + double kb = (double)bytes / 1024.0; + double mb = (double)bytes / 1024.0 / 1024.0; + double gb = (double)bytes / 1024.0 / 1024.0 / 1024.0; + char result[32]; + + if(gb >= 1.0) + snprintf(result, sizeof(result), "%.1f GiB", gb); + else if(mb >= 1.0) + snprintf(result, sizeof(result), "%.1f MiB", mb); + else if(kb >= 1.0) + snprintf(result, sizeof(result), "%.1f KiB", kb); + else + snprintf(result, sizeof(result), "%zu bytes", bytes); + + return result; + } } -- cgit v1.2.3