From 8a7a85062cc54737db713aebb7ff7fb4c76c8356 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Sun, 7 Jan 2024 13:19:55 +1100 Subject: [PATCH] Fix up large file handling output * Fix up large file handling output * Fix calculation error for upload fragments --- src/onedrive.d | 18 +++++++++--------- src/sync.d | 15 ++++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 16449bd1..a4552a70 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -1335,7 +1335,7 @@ class OneDriveApi { // For each onProgress, what is the % of dlnow to dltotal // floor - rounds down to nearest whole number real currentDLPercent = floor(double(dlnow)/dltotal*100); - string downloadLogEntry = leftJustify("Downloading: " ~ filename ~ " ", 77, '.'); + string downloadLogEntry = "Downloading: " ~ filename ~ " ... "; // Have we started downloading? if (currentDLPercent > 0){ @@ -1380,8 +1380,8 @@ class OneDriveApi { segmentCount++; auto eta = calc_eta(segmentCount, expected_total_segments, start_unix_time); dur!"seconds"(eta).split!("hours", "minutes", "seconds")(h, m, s); - etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); - string percentage = " " ~ leftJustify(to!string(currentDLPercent) ~ "%", 6, ' '); + etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); + string percentage = leftJustify(to!string(currentDLPercent) ~ "%", 5, ' '); addLogEntry(downloadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); } else { // 100% done @@ -1389,7 +1389,7 @@ class OneDriveApi { auto upload_duration = cast(int)(end_unix_time - start_unix_time); dur!"seconds"(upload_duration).split!("hours", "minutes", "seconds")(h, m, s); etaString = format!"| DONE in %02d:%02d:%02d"( h, m, s); - string percentage = " " ~ leftJustify(to!string(currentDLPercent) ~ "%", 6, ' '); + string percentage = leftJustify(to!string(currentDLPercent) ~ "%", 5, ' '); addLogEntry(downloadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); } @@ -1412,8 +1412,8 @@ class OneDriveApi { segmentCount++; auto eta = calc_eta(segmentCount, expected_total_segments, start_unix_time); dur!"seconds"(eta).split!("hours", "minutes", "seconds")(h, m, s); - etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); - string percentage = " " ~ leftJustify(to!string(currentDLPercent) ~ "%", 6, ' '); + etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); + string percentage = leftJustify(to!string(currentDLPercent) ~ "%", 5, ' '); addLogEntry(downloadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); } else { // 100% done @@ -1421,7 +1421,7 @@ class OneDriveApi { auto upload_duration = cast(int)(end_unix_time - start_unix_time); dur!"seconds"(upload_duration).split!("hours", "minutes", "seconds")(h, m, s); etaString = format!"| DONE in %02d:%02d:%02d"( h, m, s); - string percentage = " " ~ leftJustify(to!string(currentDLPercent) ~ "%", 6, ' '); + string percentage = leftJustify(to!string(currentDLPercent) ~ "%", 5, ' '); addLogEntry(downloadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); } @@ -1433,8 +1433,8 @@ class OneDriveApi { if ((currentDLPercent == 0) && (!barInit)) { // Calculate the output segmentCount++; - etaString = "| ETA --:--:--"; - string percentage = " " ~ leftJustify(to!string(currentDLPercent) ~ "%", 6, ' '); + etaString = "| ETA --:--:--"; + string percentage = leftJustify(to!string(currentDLPercent) ~ "%", 5, ' '); addLogEntry(downloadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); barInit = true; } diff --git a/src/sync.d b/src/sync.d index 7a64cadf..f9c5b7ac 100644 --- a/src/sync.d +++ b/src/sync.d @@ -24,6 +24,7 @@ import std.string; import std.uni; import std.uri; import std.utf; +import std.math; // What other modules that we have created do we need to import? import config; @@ -5136,11 +5137,11 @@ class SyncEngine { ulong fragmentCount = 0; ulong fragSize = 0; ulong offset = uploadSessionData["nextExpectedRanges"][0].str.splitter('-').front.to!ulong; - size_t expected_total_fragments = (roundTo!int(double(thisFileSize)/double(fragmentSize))); + size_t expected_total_fragments = cast(ulong) ceil(double(thisFileSize) / double(fragmentSize)); ulong start_unix_time = Clock.currTime.toUnixTime(); int h, m, s; string etaString; - string uploadLogEntry = leftJustify("Uploading: " ~ uploadSessionData["localPath"].str ~ " ", 76, '.'); + string uploadLogEntry = "Uploading: " ~ uploadSessionData["localPath"].str ~ " ... "; // Start the session upload using the active API instance for this thread while (true) { @@ -5151,17 +5152,17 @@ class SyncEngine { auto eta = calc_eta((fragmentCount -1), expected_total_fragments, start_unix_time); if (eta == 0) { // Initial calculation ... - etaString = format!"| ETA --:--:--"; + etaString = format!"| ETA --:--:--"; } else { // we have at least an ETA provided dur!"seconds"(eta).split!("hours", "minutes", "seconds")(h, m, s); - etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); + etaString = format!"| ETA %02d:%02d:%02d"( h, m, s); } // Calculate this progress output auto ratio = cast(double)(fragmentCount -1) / expected_total_fragments; // Convert the ratio to a percentage and format it to two decimal places - string percentage = leftJustify(format(" %05.2f%%", ratio * 100), 8, ' '); + string percentage = leftJustify(format("%d%%", cast(int)(ratio * 100)), 5, ' '); addLogEntry(uploadLogEntry ~ percentage ~ etaString, ["consoleOnly"]); // What fragment size will be used? @@ -5288,8 +5289,8 @@ class SyncEngine { ulong end_unix_time = Clock.currTime.toUnixTime(); auto upload_duration = cast(int)(end_unix_time - start_unix_time); dur!"seconds"(upload_duration).split!("hours", "minutes", "seconds")(h, m, s); - etaString = format!" | DONE in %02d:%02d:%02d"( h, m, s); - addLogEntry(uploadLogEntry ~ " 100% " ~ etaString, ["consoleOnly"]); + etaString = format!"| DONE in %02d:%02d:%02d"( h, m, s); + addLogEntry(uploadLogEntry ~ "100% " ~ etaString, ["consoleOnly"]); // Remove session file if it exists if (exists(threadUploadSessionFilePath)) {