X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fcopy_to_drive_job.cc;h=c6f9c84b0cea67867ad9f6cc8835a6aae4cfea16;hb=3f2142a90410755d090ace98ada1fee5a869da98;hp=eafa126b6148538ab56018d074e6274b5fca51a8;hpb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;p=dcpomatic.git diff --git a/src/lib/copy_to_drive_job.cc b/src/lib/copy_to_drive_job.cc index eafa126b6..c6f9c84b0 100644 --- a/src/lib/copy_to_drive_job.cc +++ b/src/lib/copy_to_drive_job.cc @@ -18,44 +18,53 @@ */ -#include "disk_writer_messages.h" -#include "copy_to_drive_job.h" + #include "compose.hpp" -#include "exceptions.h" +#include "copy_to_drive_job.h" #include "dcpomatic_log.h" +#include "disk_writer_messages.h" +#include "exceptions.h" #include #include -#include #include +#include +#include #include #include #include -#include #include "i18n.h" -using std::string; + using std::cout; using std::min; using std::shared_ptr; +using std::string; using boost::optional; using dcp::raw_convert; -CopyToDriveJob::CopyToDriveJob (boost::filesystem::path dcp, Drive drive, Nanomsg& nanomsg) + +CopyToDriveJob::CopyToDriveJob(std::vector const& dcps, Drive drive, Nanomsg& nanomsg) : Job (shared_ptr()) - , _dcp (dcp) + , _dcps (dcps) , _drive (drive) , _nanomsg (nanomsg) { } + string CopyToDriveJob::name () const { - return String::compose (_("Copying %1\nto %2"), _dcp.filename().string(), _drive.description()); + if (_dcps.size() == 1) { + return String::compose(_("Copying %1\nto %2"), _dcps[0].filename().string(), _drive.description()); + } + + return String::compose(_("Copying DCPs to %1"), _drive.description()); } + string CopyToDriveJob::json_name () const { @@ -65,8 +74,18 @@ CopyToDriveJob::json_name () const void CopyToDriveJob::run () { - LOG_DISK("Sending write request to disk writer for %1 %2", _dcp.string(), _drive.device()); - if (!_nanomsg.send(String::compose(DISK_WRITER_WRITE "\n%1\n%2\n", _dcp.string(), _drive.device()), 2000)) { + LOG_DISK("Sending write requests to disk %1 for:", _drive.device()); + for (auto dcp: _dcps) { + LOG_DISK("%1", dcp.string()); + } + + string request = String::compose(DISK_WRITER_WRITE "\n%1\n", _drive.device()); + for (auto dcp: _dcps) { + request += String::compose("%1\n", dcp.string()); + } + request += "\n"; + if (!_nanomsg.send(request, 2000)) { + LOG_DISK_NC("Failed to send write request."); throw CommunicationFailedError (); } @@ -86,19 +105,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 +131,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)); }