Add some useful command-line options to dcpomatic2_disk.
[dcpomatic.git] / src / tools / dcpomatic_disk.cc
index 3daffb72d0b94d7d8b0c1b340f4d1359bcaa2c3f..f495ecc4188b8bb9b2aef37548da8ace017ed38a 100644 (file)
@@ -38,6 +38,7 @@
 #include "lib/util.h"
 #include "lib/version.h"
 #include "lib/warnings.h"
+#include <wx/cmdline.h>
 #include <wx/wx.h>
 DCPOMATIC_DISABLE_WARNINGS
 #include <boost/process.hpp>
@@ -173,6 +174,16 @@ public:
        ~DOMFrame ()
        {
                _nanomsg.send(DISK_WRITER_QUIT "\n", 2000);
+               /* This seems really horrible but it's suggested by the examples on nanomsg.org, so...
+                * Without this the quit is not received (at least sometimes) causing #2018.
+                */
+               dcpomatic_sleep_seconds (1);
+       }
+
+       void set_dcp (boost::filesystem::path dcp)
+       {
+               _dcp_path = dcp;
+               _dcp_name->SetLabel (std_to_wx(dcp.filename().string()));
        }
 
 private:
@@ -232,8 +243,7 @@ private:
                        return;
                }
 
-               _dcp_path = path;
-               _dcp_name->SetLabel (std_to_wx(_dcp_path->filename().string()));
+               set_dcp (path);
                setup_sensitivity ();
        }
 
@@ -250,8 +260,8 @@ private:
                DCPOMATIC_ASSERT (static_cast<bool>(_dcp_path));
 
                auto ping = [this](int attempt) {
-                       if (_nanomsg.send(DISK_WRITER_PING "\n", 2000)) {
-                               auto reply = _nanomsg.receive (2000);
+                       if (_nanomsg.send(DISK_WRITER_PING "\n", 1000)) {
+                               auto reply = _nanomsg.receive (1000);
                                if (reply && *reply == DISK_WRITER_PONG) {
                                        return true;
                                } else if (reply) {
@@ -262,6 +272,7 @@ private:
                        } else {
                                LOG_DISK("Could not send ping to writer (attempt %1)", attempt);
                        }
+                       dcpomatic_sleep_seconds (1);
                        return false;
                };
 
@@ -274,7 +285,7 @@ private:
                }
 
                if (!have_writer) {
-#ifdef DCPOMATIC_WINDOWS
+#if defined(DCPOMATIC_WINDOWS)
                        auto m = new MessageDialog (
                                this,
                                _("DCP-o-matic Disk Writer"),
@@ -283,6 +294,15 @@ private:
                        m->ShowModal ();
                        m->Destroy ();
                        return;
+#elif defined(DCPOMATIC_OSX)
+                       auto m = new MessageDialog (
+                               this,
+                               _("DCP-o-matic Disk Writer"),
+                               _("Did you install the DCP-o-matic Disk Writer.pkg from the .dmg?  Please check and try again.")
+                               );
+                       m->ShowModal ();
+                       m->Destroy ();
+                       return;
 #else
                        LOG_DISK_NC ("Failed to ping writer");
                        throw CommunicationFailedError ();
@@ -379,11 +399,18 @@ private:
 };
 
 
+static const wxCmdLineEntryDesc command_line_description[] = {
+       { wxCMD_LINE_OPTION, "d", "dcp", "DCP to write", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_SWITCH, "s", "sure", "skip alpha test warnings", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },
+       { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
+};
+
+
 class App : public wxApp
 {
 public:
        App ()
-               : _frame (0)
+               : _frame (nullptr)
        {}
 
        bool OnInit ()
@@ -427,18 +454,24 @@ public:
                        */
                        Config::drop ();
 
-                       auto warning = new DiskWarningDialog ();
-                       warning->ShowModal ();
-                       if (!warning->confirmed()) {
-                               return false;
+                       if (!_skip_alpha_check) {
+                               auto warning = new DiskWarningDialog ();
+                               warning->ShowModal ();
+                               if (!warning->confirmed()) {
+                                       return false;
+                               }
+                               warning->Destroy ();
                        }
-                       warning->Destroy ();
 
                        _frame = new DOMFrame (_("DCP-o-matic Disk Writer"));
                        SetTopWindow (_frame);
 
                        _frame->Show ();
 
+                       if (_dcp_to_write) {
+                               _frame->set_dcp (*_dcp_to_write);
+                       }
+
                        signal_manager = new wxSignalManager (this);
                        Bind (wxEVT_IDLE, boost::bind (&App::idle, this, _1));
                }
@@ -451,6 +484,24 @@ public:
                return true;
        }
 
+       void OnInitCmdLine (wxCmdLineParser& parser)
+       {
+               parser.SetDesc (command_line_description);
+               parser.SetSwitchChars (wxT ("-"));
+       }
+
+       bool OnCmdLineParsed (wxCmdLineParser& parser)
+       {
+               _skip_alpha_check = parser.Found(wxT("sure"));
+
+               wxString dcp;
+               if (parser.Found(wxT("dcp"), &dcp)) {
+                       _dcp_to_write = wx_to_std (dcp);
+               }
+
+               return true;
+       }
+
        void config_failed_to_load ()
        {
                message_dialog (_frame, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
@@ -506,6 +557,8 @@ public:
        }
 
        DOMFrame* _frame;
+       bool _skip_alpha_check = false;
+       boost::optional<boost::filesystem::path> _dcp_to_write;
 };
 
 IMPLEMENT_APP (App)