Open Windows console earlier in startup.
[dcpomatic.git] / src / tools / dcpomatic.cc
index a7b3af8bce0999f44d4c420163988fccc72372ad..0ed65da8d82291721eac8a2b50355554cf63d9ba 100644 (file)
@@ -306,25 +306,6 @@ public:
                , _right_panel(new wxPanel(_splitter, wxID_ANY))
                , _film_viewer(_right_panel)
        {
-#if defined(DCPOMATIC_WINDOWS)
-               if (Config::instance()->win32_console()) {
-                       AllocConsole();
-
-                       HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
-                       int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
-                       FILE* hf_out = _fdopen(hCrt, "w");
-                       setvbuf(hf_out, NULL, _IONBF, 1);
-                       *stdout = *hf_out;
-
-                       HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
-                       hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
-                       FILE* hf_in = _fdopen(hCrt, "r");
-                       setvbuf(hf_in, NULL, _IONBF, 128);
-                       *stdin = *hf_in;
-
-                       cout << "DCP-o-matic is starting." << "\n";
-               }
-#endif
 
                auto bar = new wxMenuBar;
                setup_menu (bar);
@@ -388,6 +369,7 @@ public:
                left_panel->SetSizerAndFit(left_sizer);
 
                _controls = new StandardControls(_right_panel, _film_viewer, true);
+               _controls->set_film(_film_viewer.film());
                auto job_manager_view = new JobManagerView(_right_panel, false);
 
                auto right_sizer = new wxBoxSizer (wxVERTICAL);
@@ -706,13 +688,16 @@ private:
        void edit_copy ()
        {
                auto const sel = _film_editor->content_panel()->selected();
-               DCPOMATIC_ASSERT (sel.size() == 1);
-               _clipboard = sel.front()->clone();
+               if (sel.size() == 1) {
+                       _clipboard = sel.front()->clone();
+               }
        }
 
        void edit_paste ()
        {
-               DCPOMATIC_ASSERT (_clipboard);
+               if (!_clipboard) {
+                       return;
+               }
 
                PasteDialog dialog(this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty());
                if (dialog.ShowModal() != wxID_OK) {
@@ -1115,12 +1100,11 @@ private:
                for (auto i: translations) {
                        body += i.first + "\n" + i.second + "\n\n";
                }
-               list<string> to = { "carl@dcpomatic.com" };
                if (dialog.email().find("@") == string::npos) {
                        error_dialog (this, _("You must enter a valid email address when sending translations, "
                                              "otherwise the DCP-o-matic maintainers cannot credit you or contact you with questions."));
                } else {
-                       Emailer emailer(dialog.email(), to, "DCP-o-matic translations", body);
+                       Emailer emailer(dialog.email(), { "carl@dcpomatic.com" }, "DCP-o-matic translations", body);
                        try {
                                emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS);
                        } catch (NetworkError& e) {
@@ -1607,6 +1591,26 @@ private:
        bool OnInit () override
        {
                try {
+
+#if defined(DCPOMATIC_WINDOWS)
+               if (Config::instance()->win32_console()) {
+                       AllocConsole();
+
+                       HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
+                       int hCrt = _open_osfhandle((intptr_t) handle_out, _O_TEXT);
+                       FILE* hf_out = _fdopen(hCrt, "w");
+                       setvbuf(hf_out, NULL, _IONBF, 1);
+                       *stdout = *hf_out;
+
+                       HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
+                       hCrt = _open_osfhandle((intptr_t) handle_in, _O_TEXT);
+                       FILE* hf_in = _fdopen(hCrt, "r");
+                       setvbuf(hf_in, NULL, _IONBF, 128);
+                       *stdin = *hf_in;
+
+                       cout << "DCP-o-matic is starting." << "\n";
+               }
+#endif
                        wxInitAllImageHandlers ();
 
                        Config::FailedToLoad.connect(boost::bind(&App::config_failed_to_load, this, _1));
@@ -1709,7 +1713,7 @@ private:
                }
                catch (exception& e)
                {
-                       _splash.reset();
+                       close_splash();
                        error_dialog (nullptr, wxString::Format ("DCP-o-matic could not start."), std_to_wx(e.what()));
                }
 
@@ -1821,7 +1825,10 @@ private:
 
        void close_splash ()
        {
-               _splash.reset();
+               if (_splash) {
+                       _splash->Destroy();
+                       _splash = nullptr;
+               }
        }
 
        void config_failed_to_load (Config::LoadFailure what)
@@ -1839,7 +1846,7 @@ private:
                /* Destroy the splash screen here, as otherwise bad things seem to happen (for reasons unknown)
                   when we open our recreate dialog, close it, *then* try to Destroy the splash (the Destroy fails).
                */
-               _splash.reset();
+               close_splash();
 
                auto config = Config::instance();
                switch (reason) {
@@ -1908,7 +1915,7 @@ private:
        }
 
        DOMFrame* _frame = nullptr;
-       wx_ptr<wxSplashScreen> _splash;
+       wxSplashScreen* _splash = nullptr;
        shared_ptr<wxTimer> _timer;
        string _film_to_load;
        string _film_to_create;