Don't set up new film several times when setting up new SPL in player.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index c2d0534302bcacd084f78b26d52ab1582c68543a..a4333db827d4c4a9de2167e34559d00b07771b13 100644 (file)
@@ -52,6 +52,7 @@
 #include "lib/monitor_checker.h"
 #include <dcp/dcp.h>
 #include <dcp/raw_convert.h>
+#include <dcp/exceptions.h>
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
@@ -361,14 +362,18 @@ public:
 
        void load_dcp (boost::filesystem::path dir)
        {
-               dcp::DCP dcp (dir);
-               dcp.read ();
-               SPL spl;
-               BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
-                       spl.playlist.push_back (SPLEntry(j, dir));
+               try {
+                       dcp::DCP dcp (dir);
+                       dcp.read ();
+                       SPL spl;
+                       BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
+                               spl.playlist.push_back (SPLEntry(j, dir));
+                       }
+                       set_spl (spl);
+                       Config::instance()->add_to_player_history (dir);
+               } catch (dcp::DCPReadError& e) {
+                       error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
                }
-               set_spl (spl);
-               Config::instance()->add_to_player_history (dir);
        }
 
 #ifdef DCPOMATIC_VARIANT_SWAROOP
@@ -495,14 +500,15 @@ public:
                                _film->set_three_d (true);
                        }
 
-                       _viewer->set_film (_film);
-                       _viewer->seek (DCPTime(), true);
-                       _info->triggered_update ();
-
-                       set_menu_sensitivity ();
                        _controls->log (wxString::Format(_("Load DCP %s"), i.directory.filename().string().c_str()));
                }
 
+               _viewer->set_film (_film);
+               _viewer->seek (DCPTime(), true);
+               _info->triggered_update ();
+
+               set_menu_sensitivity ();
+
                wxMenuItemList old = _cpl_menu->GetMenuItems();
                for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
                        _cpl_menu->Remove (*i);