Use make_shared<>.
[dcpomatic.git] / src / tools / dcpomatic.cc
index 799124ee8f816042f420714787bf874e4e49aed3..6c789632a2dff6e46c73f10fb91be54985dfe2b0 100644 (file)
@@ -72,6 +72,7 @@
 #endif
 #include <boost/filesystem.hpp>
 #include <boost/noncopyable.hpp>
+#include <boost/make_shared.hpp>
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -92,6 +93,8 @@ using std::list;
 using std::exception;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
+using boost::optional;
+using boost::make_shared;
 
 class FilmChangedDialog : public boost::noncopyable
 {
@@ -274,7 +277,7 @@ public:
 
        void new_film (boost::filesystem::path path)
        {
-               shared_ptr<Film> film (new Film (path));
+               shared_ptr<Film> film = make_shared<Film> (path);
                film->write_metadata ();
                film->set_name (path.filename().generic_string());
                set_film (film);
@@ -283,7 +286,7 @@ public:
        void load_film (boost::filesystem::path file)
        try
        {
-               shared_ptr<Film> film (new Film (file));
+               shared_ptr<Film> film = make_shared<Film> (file);
                list<string> const notes = film->read_metadata ();
 
                if (film->state_version() == 4) {
@@ -489,14 +492,14 @@ private:
                                        );
                        } else {
                                JobManager::instance()->add (
-                                       shared_ptr<Job> (new SendKDMEmailJob (
-                                                                _film->name(),
-                                                                _film->dcp_name(),
-                                                                d->from(),
-                                                                d->until(),
-                                                                CinemaKDMs::collect (screen_kdms),
-                                                                _film->log()
-                                                                ))
+                                       boost::make_shared<SendKDMEmailJob> (
+                                               _film->name(),
+                                               _film->dcp_name(),
+                                               d->from(),
+                                               d->until(),
+                                               CinemaKDMs::collect (screen_kdms),
+                                               _film->log()
+                                               )
                                        );
                        }
                } catch (dcp::NotEncryptedError& e) {
@@ -563,20 +566,16 @@ private:
                        return;
                }
 
+               optional<dcp::EncryptedKDM> kdm;
                try {
-                       vector<dcp::EncryptedKDM> dkdms = Config::instance()->dkdms ();
-                       dkdms.push_back (
-                               _film->make_kdm (
-                                       Config::instance()->decryption_chain()->leaf(),
-                                       vector<dcp::Certificate> (),
-                                       d->cpl (),
-                                       dcp::LocalTime ("2012-01-01T01:00:00+00:00"),
-                                       dcp::LocalTime ("2112-01-01T01:00:00+00:00"),
-                                       dcp::MODIFIED_TRANSITIONAL_1
-                                       )
+                       kdm = _film->make_kdm (
+                               Config::instance()->decryption_chain()->leaf(),
+                               vector<dcp::Certificate> (),
+                               d->cpl (),
+                               dcp::LocalTime ("2012-01-01T01:00:00+00:00"),
+                               dcp::LocalTime ("2112-01-01T01:00:00+00:00"),
+                               dcp::MODIFIED_TRANSITIONAL_1
                                );
-
-                       Config::instance()->set_dkdms (dkdms);
                } catch (dcp::NotEncryptedError& e) {
                        error_dialog (this, _("CPL's content is not encrypted."));
                } catch (exception& e) {
@@ -585,6 +584,17 @@ private:
                        error_dialog (this, _("An unknown exception occurred."));
                }
 
+               if (kdm) {
+                       if (d->internal ()) {
+                               vector<dcp::EncryptedKDM> dkdms = Config::instance()->dkdms ();
+                               dkdms.push_back (kdm.get());
+                               Config::instance()->set_dkdms (dkdms);
+                       } else {
+                               boost::filesystem::path path = d->directory() / (_film->dcp_name(false) + "_DKDM.xml");
+                               kdm->as_xml (path);
+                       }
+               }
+
                d->Destroy ();
        }