From 16595efbdb9ffe07f4e6255ecf02ae9c1ee16102 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 27 Oct 2023 05:27:38 +1100 Subject: [PATCH] Update FR #2359 Update --display-quota output to: Deleted: 8.19 GB (8793627814 bytes) Remaining: 25580.69 GB (27467060611614 bytes) State: normal Total: 25600.00 GB (27487790694400 bytes) Used: 11.12 GB (11936454972 bytes) --- src/sync.d | 22 +++++++++++----------- src/util.d | 9 +++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/sync.d b/src/sync.d index d52a18ca..25496f6c 100644 --- a/src/sync.d +++ b/src/sync.d @@ -2406,7 +2406,7 @@ class SyncEngine { // What do we display here for space remaining if (appConfig.remainingFreeSpace > 0) { // Display the actual value - log.vlog("Remaining Free Space: ", (appConfig.remainingFreeSpace/1024) , " KB"); + log.vlog("Remaining Free Space: ", byteToGibiByte(appConfig.remainingFreeSpace) , " GB (", appConfig.remainingFreeSpace, " bytes)"); } else { // zero or non-zero value or restricted if (!appConfig.quotaRestricted){ @@ -7023,6 +7023,8 @@ class SyncEngine { // Query OneDrive for the quota details void queryOneDriveForQuotaDetails() { // This function is similar to getRemainingFreeSpace() but is different in data being analysed and output method + + JSONValue currentDriveQuota; string driveId; @@ -7065,11 +7067,11 @@ class SyncEngine { // Update values if ("deleted" in currentDriveQuota["quota"]) { - deletedValue = to!string(currentDriveQuota["quota"]["deleted"].integer); + deletedValue = byteToGibiByte(currentDriveQuota["quota"]["deleted"].integer); } if ("remaining" in currentDriveQuota["quota"]) { - remainingValue = to!string(currentDriveQuota["quota"]["remaining"].integer); + remainingValue = byteToGibiByte(currentDriveQuota["quota"]["remaining"].integer); } if ("state" in currentDriveQuota["quota"]) { @@ -7077,23 +7079,21 @@ class SyncEngine { } if ("total" in currentDriveQuota["quota"]) { - totalValue = to!string(currentDriveQuota["quota"]["total"].integer); + totalValue = byteToGibiByte(currentDriveQuota["quota"]["total"].integer); } if ("used" in currentDriveQuota["quota"]) { - usedValue = to!string(currentDriveQuota["quota"]["used"].integer); + usedValue = byteToGibiByte(currentDriveQuota["quota"]["used"].integer); } writeln("Microsoft OneDrive quota information as reported for this Drive ID: ", driveId); writeln(); - writeln("Deleted: ", deletedValue); - writeln("Remaining: ", remainingValue); + writeln("Deleted: ", deletedValue, " GB (", currentDriveQuota["quota"]["deleted"].integer, " bytes)"); + writeln("Remaining: ", remainingValue, " GB (", currentDriveQuota["quota"]["remaining"].integer, " bytes)"); writeln("State: ", stateValue); - writeln("Total: ", totalValue); - writeln("Used: ", usedValue); + writeln("Total: ", totalValue, " GB (", currentDriveQuota["quota"]["total"].integer, " bytes)"); + writeln("Used: ", usedValue, " GB (", currentDriveQuota["quota"]["used"].integer, " bytes)"); writeln(); - writeln("The numeric values above are expressed in bytes"); - } else { writeln("Microsoft OneDrive quota information is being restricted for this Drive ID: ", driveId); } diff --git a/src/util.d b/src/util.d index dfd348f8..0b36d0dc 100644 --- a/src/util.d +++ b/src/util.d @@ -21,6 +21,8 @@ import std.json; import std.traits; import core.stdc.stdlib; import core.thread; +import std.math; +import std.format; // What other modules that we have created do we need to import? import log; @@ -790,4 +792,11 @@ bool hasETag(const ref JSONValue item) { bool hasSharedElement(const ref JSONValue item) { return ("eTag" in item) != null; +} + +// Convert bytes to GB +string byteToGibiByte(ulong bytes) { + double gib = bytes / pow(1024.0,3); + double roundedGib = round(gib * 100) / 100; + return to!string(format("%.2f", roundedGib)); // Format to ensure two decimal places } \ No newline at end of file