Add git commits to writer log files.
[dcpomatic.git] / src / tools / dcpomatic_disk.cc
index 3ceead860f2fd4c2f773900930310baa939c26aa..6f72bfed0e749b672e5d1208afb560b3fbbfa3f7 100644 (file)
@@ -24,6 +24,7 @@
 #include "wx/drive_wipe_warning_dialog.h"
 #include "wx/try_unmount_dialog.h"
 #include "wx/message_dialog.h"
+#include "wx/disk_warning_dialog.h"
 #include "lib/file_log.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/util.h"
@@ -33,6 +34,7 @@
 #include "lib/copy_to_drive_job.h"
 #include "lib/job_manager.h"
 #include "lib/disk_writer_messages.h"
+#include "lib/version.h"
 #include <wx/wx.h>
 #include <boost/process.hpp>
 #ifdef DCPOMATIC_WINDOWS
@@ -111,7 +113,7 @@ public:
                 */
                dcpomatic_log.reset(new FileLog(config_path() / "disk.log"));
                dcpomatic_log->set_types (dcpomatic_log->types() | LogEntry::TYPE_DISK);
-               LOG_DISK_NC("dcpomatic_disk started");
+               LOG_DISK("dcpomatic_disk %1 started", dcpomatic_git_commit);
 
                drive_refresh ();
 
@@ -175,10 +177,11 @@ private:
                                return;
                        }
 
+                       LOG_DISK("Sending unmount request to disk writer for %1", drive.as_xml());
                        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 +197,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 +247,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;
 };
@@ -298,6 +303,12 @@ public:
                        */
                        Config::drop ();
 
+                       DiskWarningDialog* warning = new DiskWarningDialog ();
+                       warning->ShowModal ();
+                       if (!warning->confirmed()) {
+                               return false;
+                       }
+
                        _frame = new DOMFrame (_("DCP-o-matic Disk Writer"));
                        SetTopWindow (_frame);
 
@@ -309,6 +320,7 @@ public:
                catch (exception& e)
                {
                        error_dialog (0, wxString::Format ("DCP-o-matic could not start."), std_to_wx(e.what()));
+                       return false;
                }
 
                return true;
@@ -330,6 +342,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;
 };