From: Carl Hetherington Date: Mon, 8 Mar 2021 21:25:47 +0000 (+0100) Subject: Get progress during formatting. X-Git-Tag: v2.15.134~2 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=7981eefcfebb563ccf5627f132abdfdef22e0c23 Get progress during formatting. --- diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index eafa126b6..96f873cf6 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -86,19 +86,24 @@ CopyToDriveJob::run () set_state (FINISHED_OK); return; } else if (*s == DISK_WRITER_ERROR) { - optional const m = _nanomsg.receive (500); - optional const n = _nanomsg.receive (500); + auto const m = _nanomsg.receive (500); + auto const n = _nanomsg.receive (500); throw CopyError (m.get_value_or("Unknown"), raw_convert(n.get_value_or("0"))); - } else if (*s == DISK_WRITER_FORMATTING) { - sub (_("Formatting drive")); - set_progress_unknown (); - state = FORMAT; + } else if (*s == DISK_WRITER_FORMAT_PROGRESS) { + if (state == SETUP) { + sub (_("Formatting drive")); + state = FORMAT; + } + auto progress = _nanomsg.receive (500); + if (progress) { + set_progress (raw_convert(*progress)); + } } else if (*s == DISK_WRITER_COPY_PROGRESS) { if (state == FORMAT) { sub (_("Copying DCP")); state = COPY; } - optional progress = _nanomsg.receive (500); + auto progress = _nanomsg.receive (500); if (progress) { set_progress (raw_convert(*progress)); } @@ -107,7 +112,7 @@ CopyToDriveJob::run () sub (_("Verifying copied files")); state = VERIFY; } - optional progress = _nanomsg.receive (500); + auto progress = _nanomsg.receive (500); if (progress) { set_progress (raw_convert(*progress)); } diff --git a/src/lib/disk_writer_messages.h b/src/lib/disk_writer_messages.h index 406afc61d..ab86f083e 100644 --- a/src/lib/disk_writer_messages.h +++ b/src/lib/disk_writer_messages.h @@ -51,8 +51,9 @@ // Error message // Error number -// the drive is being formatted -#define DISK_WRITER_FORMATTING "F" +// the drive is being formatted, 40% done +#define DISK_WRITER_FORMAT_PROGRESS "F" +// 0.4\n // data is being copied, 30% done #define DISK_WRITER_COPY_PROGRESS "C" diff --git a/src/lib/ext.cc b/src/lib/ext.cc index 086afd91e..b88a88726 100644 --- a/src/lib/ext.cc +++ b/src/lib/ext.cc @@ -255,6 +255,16 @@ verify (vector const& copied_files, uint64_t total, Nanomsg* nanomsg } +static +void +format_progress (void* context, float progress) +{ + if (context) { + reinterpret_cast(context)->send(String::compose(DISK_WRITER_FORMAT_PROGRESS "\n%1\n", progress), SHORT_TIMEOUT); + } +} + + void #ifdef DCPOMATIC_WINDOWS dcpomatic::write (boost::filesystem::path dcp_path, string device, string, Nanomsg* nanomsg) @@ -329,11 +339,7 @@ try } LOG_DISK_NC ("Opened partition"); - if (nanomsg) { - nanomsg->send(DISK_WRITER_FORMATTING "\n", SHORT_TIMEOUT); - } - - r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2); + r = ext4_mkfs(&fs, bd, &info, F_SET_EXT2, format_progress, nanomsg); if (r != EOK) { throw CopyError ("Failed to make filesystem", r); }