Fix up large file handling output

* Fix up large file handling output
* Fix calculation error for upload fragments
This commit is contained in:
abraunegg 2024-01-07 13:19:55 +11:00
parent abe4439014
commit 8a7a85062c
2 changed files with 17 additions and 16 deletions

View file

@ -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;
}

View file

@ -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)) {