And another missed warnings.h
[dcpomatic.git] / src / tools / dcpomatic_disk.cc
index 67705ffcb65d941d97f2960bfdf337b28da19cb9..e4cc6c264e65df68d1e4d5c33934c853af075f83 100644 (file)
 #include "lib/signal_manager.h"
 #include "lib/util.h"
 #include "lib/version.h"
-#include "lib/warnings.h"
+#include <dcp/warnings.h>
+#include <wx/cmdline.h>
 #include <wx/wx.h>
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 #include <boost/process.hpp>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #ifdef DCPOMATIC_WINDOWS
 #include <boost/process/windows.hpp>
 #endif
@@ -138,7 +139,7 @@ public:
                /* XXX: this is a hack, but I expect we'll need logs and I'm not sure if there's
                 * a better place to put them.
                 */
-               dcpomatic_log.reset(new FileLog(config_path() / "disk.log"));
+               dcpomatic_log = make_shared<FileLog>(State::write_path("disk.log"));
                dcpomatic_log->set_types (dcpomatic_log->types() | LogEntry::TYPE_DISK);
                LOG_DISK("dcpomatic_disk %1 started", dcpomatic_git_commit);
 
@@ -173,6 +174,21 @@ 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)
+       {
+               if (!boost::filesystem::exists(dcp / "ASSETMAP") && !boost::filesystem::exists(dcp / "ASSETMAP.xml")) {
+                       error_dialog (nullptr, _("No ASSETMAP or ASSETMAP.xml found in this folder.  Please choose a DCP folder."));
+                       return;
+               }
+
+               _dcp_path = dcp;
+               _dcp_name->SetLabel (std_to_wx(dcp.filename().string()));
        }
 
 private:
@@ -232,8 +248,7 @@ private:
                        return;
                }
 
-               _dcp_path = path;
-               _dcp_name->SetLabel (std_to_wx(_dcp_path->filename().string()));
+               set_dcp (path);
                setup_sensitivity ();
        }
 
@@ -389,14 +404,21 @@ 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 ()
+       bool OnInit () override
        {
                try {
                        Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
@@ -437,18 +459,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));
                }
@@ -461,6 +489,24 @@ public:
                return true;
        }
 
+       void OnInitCmdLine (wxCmdLineParser& parser) override
+       {
+               parser.SetDesc (command_line_description);
+               parser.SetSwitchChars (wxT ("-"));
+       }
+
+       bool OnCmdLineParsed (wxCmdLineParser& parser) override
+       {
+               _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."));
@@ -503,19 +549,21 @@ public:
                }
        }
 
-       bool OnExceptionInMainLoop ()
+       bool OnExceptionInMainLoop () override
        {
                report_exception ();
                /* This will terminate the program */
                return false;
        }
 
-       void OnUnhandledException ()
+       void OnUnhandledException () override
        {
                report_exception ();
        }
 
        DOMFrame* _frame;
+       bool _skip_alpha_check = false;
+       boost::optional<boost::filesystem::path> _dcp_to_write;
 };
 
 IMPLEMENT_APP (App)