summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-09 20:53:22 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-13 00:27:39 +0200
commit747e81de1927c71b39dc916be05bb9296ca6b882 (patch)
tree4068bac39995c02aa43917f39fb3dff664f71efd /src/tools
parent6d27b49a7a767a9c8b31dc0f799da940ddb7232f (diff)
Support unmounting on macOS and Windows.v2.15.51
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/dcpomatic_disk.cc44
-rw-r--r--src/tools/dcpomatic_disk_writer.cc41
2 files changed, 68 insertions, 17 deletions
diff --git a/src/tools/dcpomatic_disk.cc b/src/tools/dcpomatic_disk.cc
index 3ceead860..bf4d45e20 100644
--- a/src/tools/dcpomatic_disk.cc
+++ b/src/tools/dcpomatic_disk.cc
@@ -178,7 +178,7 @@ private:
if (!_nanomsg.send(DISK_WRITER_UNMOUNT "\n", 2000)) {
throw CommunicationFailedError ();
}
- if (!_nanomsg.send(drive.as_xml() + "\n", 2000)) {
+ if (!_nanomsg.send(drive.as_xml(), 2000)) {
throw CommunicationFailedError ();
}
optional<string> reply = _nanomsg.receive (2000);
@@ -194,7 +194,7 @@ private:
}
}
-
+
DriveWipeWarningDialog* d = new DriveWipeWarningDialog (this, _drive->GetString(_drive->GetSelection()));
int const r = d->ShowModal ();
bool ok = r == wxID_OK && d->confirmed();
@@ -244,7 +244,9 @@ private:
JobManagerView* _jobs;
boost::optional<boost::filesystem::path> _dcp_path;
std::vector<Drive> _drives;
+#ifndef DCPOMATIC_OSX
boost::process::child* _writer;
+#endif
Nanomsg _nanomsg;
wxSizer* _sizer;
};
@@ -330,6 +332,44 @@ public:
ev.Skip ();
}
+ void report_exception ()
+ {
+ try {
+ throw;
+ } catch (FileError& e) {
+ error_dialog (
+ 0,
+ wxString::Format (
+ _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
+ std_to_wx (e.what()),
+ std_to_wx (e.file().string().c_str ())
+ )
+ );
+ } catch (exception& e) {
+ error_dialog (
+ 0,
+ wxString::Format (
+ _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
+ std_to_wx (e.what ())
+ )
+ );
+ } catch (...) {
+ error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
+ }
+ }
+
+ bool OnExceptionInMainLoop ()
+ {
+ report_exception ();
+ /* This will terminate the program */
+ return false;
+ }
+
+ void OnUnhandledException ()
+ {
+ report_exception ();
+ }
+
DOMFrame* _frame;
};
diff --git a/src/tools/dcpomatic_disk_writer.cc b/src/tools/dcpomatic_disk_writer.cc
index 4a93cba98..feee687f8 100644
--- a/src/tools/dcpomatic_disk_writer.cc
+++ b/src/tools/dcpomatic_disk_writer.cc
@@ -119,6 +119,8 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
uint8_t* buffer = new uint8_t[block_size];
Digester digester;
+ int progress_frequency = 5000;
+ int progress_count = 0;
uint64_t remaining = file_size (from);
while (remaining > 0) {
uint64_t const this_time = min(remaining, block_size);
@@ -148,7 +150,11 @@ write (boost::filesystem::path from, boost::filesystem::path to, uint64_t& total
}
remaining -= this_time;
total_remaining -= this_time;
- nanomsg->send(String::compose(DISK_WRITER_PROGRESS "\n%1\n", (1 - float(total_remaining) / total)), SHORT_TIMEOUT);
+
+ ++progress_count;
+ if ((progress_count % progress_frequency) == 0) {
+ nanomsg->send(String::compose(DISK_WRITER_PROGRESS "\n%1\n", (1 - float(total_remaining) / total)), SHORT_TIMEOUT);
+ }
}
fclose (in);
@@ -276,16 +282,18 @@ try
}
LOG_DISK_NC ("Wrote MBR");
-#ifdef DCPOMATIC_WINDOWS
struct ext4_mbr_bdevs bdevs;
r = ext4_mbr_scan (bd, &bdevs);
if (r != EOK) {
throw CopyError ("Failed to read MBR", r);
}
+#ifdef DCPOMATIC_WINDOWS
file_windows_partition_set (bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size);
#endif
+ LOG_DISK ("Writing to partition at %1 size %2; bd part size is %3", bdevs.partitions[0].part_offset, bdevs.partitions[0].part_size, bd->part_size);
+
#ifdef DCPOMATIC_LINUX
/* Re-read the partition table */
int fd = open(device.c_str(), O_RDONLY);
@@ -354,6 +362,8 @@ try
if (!nanomsg->send(DISK_WRITER_OK "\n", LONG_TIMEOUT)) {
throw CommunicationFailedError ();
}
+
+ disk_write_finished ();
} catch (CopyError& e) {
LOG_DISK("CopyError (from write): %1 %2", e.message(), e.number().get_value_or(0));
nanomsg->send(String::compose(DISK_WRITER_ERROR "\n%1\n%2\n", e.message(), e.number().get_value_or(0)), LONG_TIMEOUT);
@@ -388,6 +398,7 @@ polkit_callback (GObject *, GAsyncResult* res, gpointer data)
}
#endif
+
bool
idle ()
try
@@ -399,6 +410,8 @@ try
return true;
}
+ LOG_DISK("Writer receives command: %1", *s);
+
if (*s == DISK_WRITER_QUIT) {
exit (EXIT_SUCCESS);
} else if (*s == DISK_WRITER_UNMOUNT) {
@@ -406,21 +419,19 @@ try
optional<string> xml_head = nanomsg->receive (LONG_TIMEOUT);
optional<string> xml_body = nanomsg->receive (LONG_TIMEOUT);
if (!xml_head || !xml_body) {
+ LOG_DISK_NC("Failed to receive unmount request");
throw CommunicationFailedError ();
}
- if (Drive(*xml_head + *xml_body).unmount()) {
- if (!nanomsg->send (DISK_WRITER_OK "\n", LONG_TIMEOUT)) {
- throw CommunicationFailedError();
- }
- } else {
- if (!nanomsg->send (DISK_WRITER_ERROR "\n", LONG_TIMEOUT)) {
- throw CommunicationFailedError();
- }
+ bool const success = Drive(*xml_head + *xml_body).unmount();
+ if (!nanomsg->send (success ? (DISK_WRITER_OK "\n") : (DISK_WRITER_ERROR "\n"), LONG_TIMEOUT)) {
+ LOG_DISK_NC("CommunicationFailedError in unmount_finished");
+ throw CommunicationFailedError ();
}
- } else {
- optional<string> dcp_path = nanomsg->receive(LONG_TIMEOUT);
- optional<string> device = nanomsg->receive(LONG_TIMEOUT);
+ } else if (*s == DISK_WRITER_WRITE) {
+ optional<string> dcp_path = nanomsg->receive (LONG_TIMEOUT);
+ optional<string> device = nanomsg->receive (LONG_TIMEOUT);
if (!dcp_path || !device) {
+ LOG_DISK_NC("Failed to receive write request");
throw CommunicationFailedError();
}
@@ -429,7 +440,7 @@ try
#ifdef DCPOMATIC_OSX
if (!starts_with(*device, "/dev/disk")) {
LOG_DISK ("Will not write to %1", *device);
- nanomsg->try_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
+ nanomsg->send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
return true;
}
#endif
@@ -443,7 +454,7 @@ try
#ifdef DCPOMATIC_WINDOWS
if (!starts_with(*device, "\\\\.\\PHYSICALDRIVE")) {
LOG_DISK ("Will not write to %1", *device);
- nanomsg->try_send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
+ nanomsg->send(DISK_WRITER_ERROR "\nRefusing to write to this drive\n1\n", LONG_TIMEOUT);
return true;
}
#endif