X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_kdm_cli.cc;h=bd4c4e62324fd54b8e6e0ef053220b45e31d8989;hb=70b72b53eab0f247eb4dc605a2d669d4adb4e469;hp=a3075d6752ac2d7187eeb8cedbc3b2757bee7a3b;hpb=8f12e84009d7c2685bb2eeb32665876463d4e6e5;p=dcpomatic.git diff --git a/src/tools/dcpomatic_kdm_cli.cc b/src/tools/dcpomatic_kdm_cli.cc index a3075d675..bd4c4e623 100644 --- a/src/tools/dcpomatic_kdm_cli.cc +++ b/src/tools/dcpomatic_kdm_cli.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ + /** @file src/tools/dcpomatic_kdm_cli.cc * @brief Command-line program to generate KDMs. */ -#include "lib/film.h" + #include "lib/cinema.h" -#include "lib/kdm_with_metadata.h" #include "lib/config.h" -#include "lib/exceptions.h" -#include "lib/emailer.h" #include "lib/dkdm_wrapper.h" +#include "lib/emailer.h" +#include "lib/exceptions.h" +#include "lib/film.h" +#include "lib/kdm_with_metadata.h" #include "lib/screen.h" #include #include @@ -36,18 +38,24 @@ #include #include -using std::string; -using std::cout; + using std::cerr; +using std::cout; +using std::dynamic_pointer_cast; using std::list; -using std::vector; +using std::make_shared; using std::runtime_error; -using boost::shared_ptr; +using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; using boost::bind; -using boost::dynamic_pointer_cast; +#if BOOST_VERSION >= 106100 +using namespace boost::placeholders; +#endif using namespace dcpomatic; + static void help () { @@ -77,6 +85,7 @@ help () "\t" << program_name << " -c \"Fred's Cinema\" -f now -d \"2 weeks\" -z my_great_movie\n\n"; } + static void error (string m) { @@ -84,6 +93,7 @@ error (string m) exit (EXIT_FAILURE); } + static boost::posix_time::ptime time_from_string (string t) { @@ -94,6 +104,7 @@ time_from_string (string t) return boost::posix_time::time_from_string (t); } + static boost::posix_time::time_duration duration_from_string (string d) { @@ -121,12 +132,14 @@ duration_from_string (string d) exit (EXIT_FAILURE); } + static bool always_overwrite () { return true; } + void write_files ( list kdms, @@ -161,11 +174,12 @@ write_files ( } } + shared_ptr find_cinema (string cinema_name) { - list > cinemas = Config::instance()->cinemas (); - list >::const_iterator i = cinemas.begin(); + auto cinemas = Config::instance()->cinemas (); + auto i = cinemas.begin(); while ( i != cinemas.end() && (*i)->name != cinema_name && @@ -182,9 +196,10 @@ find_cinema (string cinema_name) return *i; } + void from_film ( - list > screens, + list> screens, boost::filesystem::path film_dir, bool verbose, boost::filesystem::path output, @@ -200,7 +215,7 @@ from_film ( { shared_ptr film; try { - film.reset (new Film (film_dir)); + film = make_shared(film_dir); film->read_metadata (); if (verbose) { cout << "Read film " << film->name () << "\n"; @@ -218,12 +233,12 @@ from_film ( error ("more than one CPL found in film"); } - boost::filesystem::path cpl = cpls.front().cpl_file; + auto cpl = cpls.front().cpl_file; try { list kdms; - BOOST_FOREACH (shared_ptr i, screens) { - KDMWithMetadataPtr p = kdm_for_screen (film, cpl, i, valid_from, valid_to, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio); + for (auto i: screens) { + auto p = kdm_for_screen (film, cpl, i, valid_from, valid_to, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio); if (p) { kdms.push_back (p); } @@ -241,18 +256,19 @@ from_film ( } } + optional sub_find_dkdm (shared_ptr group, string cpl_id) { - BOOST_FOREACH (shared_ptr i, group->children()) { - shared_ptr g = dynamic_pointer_cast(i); + for (auto i: group->children()) { + auto g = dynamic_pointer_cast(i); if (g) { - optional dkdm = sub_find_dkdm (g, cpl_id); + auto dkdm = sub_find_dkdm (g, cpl_id); if (dkdm) { return dkdm; } } else { - shared_ptr d = dynamic_pointer_cast(i); + auto d = dynamic_pointer_cast(i); assert (d); if (d->dkdm().cpl_id() == cpl_id) { return d->dkdm(); @@ -263,12 +279,14 @@ sub_find_dkdm (shared_ptr group, string cpl_id) return optional(); } + optional find_dkdm (string cpl_id) { return sub_find_dkdm (Config::instance()->dkdms(), cpl_id); } + dcp::EncryptedKDM kdm_from_dkdm ( dcp::DecryptedKDM dkdm, @@ -282,7 +300,7 @@ kdm_from_dkdm ( ) { /* Signer for new KDM */ - shared_ptr signer = Config::instance()->signer_chain (); + auto signer = Config::instance()->signer_chain (); if (!signer->valid ()) { error ("signing certificate chain is invalid."); } @@ -296,16 +314,17 @@ kdm_from_dkdm ( dcp::LocalTime().as_string() ); - BOOST_FOREACH (dcp::DecryptedKDMKey const & j, dkdm.keys()) { + for (auto const& j: dkdm.keys()) { kdm.add_key(j); } return kdm.encrypt (signer, target, trusted_devices, formulation, disable_forensic_marking_picture, disable_forensic_marking_audio); } + void from_dkdm ( - list > screens, + list> screens, dcp::DecryptedKDM dkdm, bool verbose, boost::filesystem::path output, @@ -323,7 +342,7 @@ from_dkdm ( try { list kdms; - BOOST_FOREACH (shared_ptr i, screens) { + for (auto i: screens) { if (!i->recipient) { continue; } @@ -331,7 +350,7 @@ from_dkdm ( dcp::LocalTime begin(valid_from, i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()); dcp::LocalTime end(valid_to, i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute()); - dcp::EncryptedKDM const kdm = kdm_from_dkdm( + auto const kdm = kdm_from_dkdm( dkdm, i->recipient.get(), i->trusted_device_thumbprints(), @@ -350,7 +369,7 @@ from_dkdm ( name_values['e'] = end.date() + " " + end.time_of_day(true, false); name_values['i'] = kdm.cpl_id(); - kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(name_values, i->cinema, kdm))); + kdms.push_back (make_shared(name_values, i->cinema.get(), i->cinema->emails, kdm)); } write_files (kdms, zip, output, container_name_format, filename_format, verbose); } catch (FileError& e) { @@ -362,6 +381,7 @@ from_dkdm ( } } + void dump_dkdm_group (shared_ptr group, int indent) { @@ -371,30 +391,31 @@ dump_dkdm_group (shared_ptr group, int indent) } cout << group->name() << "\n"; } - BOOST_FOREACH (shared_ptr i, group->children()) { - shared_ptr g = dynamic_pointer_cast(i); + for (auto i: group->children()) { + auto g = dynamic_pointer_cast(i); if (g) { dump_dkdm_group (g, indent + 2); } else { for (int j = 0; j < indent; ++j) { cout << " "; } - shared_ptr d = dynamic_pointer_cast(i); + auto d = dynamic_pointer_cast(i); assert(d); cout << d->dkdm().cpl_id() << "\n"; } } } + int main (int argc, char* argv[]) { boost::filesystem::path output = "."; - dcp::NameFormat container_name_format = Config::instance()->kdm_container_name_format(); - dcp::NameFormat filename_format = Config::instance()->kdm_filename_format(); + auto container_name_format = Config::instance()->kdm_container_name_format(); + auto filename_format = Config::instance()->kdm_filename_format(); optional cinema_name; shared_ptr cinema; - string screen_description = ""; - list > screens; + string screen_description; + list> screens; optional dkdm; optional valid_from; optional valid_to; @@ -403,7 +424,7 @@ int main (int argc, char* argv[]) bool list_dkdm_cpls = false; optional duration_string; bool verbose = false; - dcp::Formulation formulation = dcp::MODIFIED_TRANSITIONAL_1; + dcp::Formulation formulation = dcp::Formulation::MODIFIED_TRANSITIONAL_1; bool disable_forensic_marking_picture = false; optional disable_forensic_marking_audio; @@ -462,14 +483,14 @@ int main (int argc, char* argv[]) duration_string = optarg; break; case 'F': - if (string (optarg) == "modified-transitional-1") { - formulation = dcp::MODIFIED_TRANSITIONAL_1; - } else if (string (optarg) == "multiple-modified-transitional-1") { - formulation = dcp::MULTIPLE_MODIFIED_TRANSITIONAL_1; - } else if (string (optarg) == "dci-any") { - formulation = dcp::DCI_ANY; - } else if (string (optarg) == "dci-specific") { - formulation = dcp::DCI_SPECIFIC; + if (string(optarg) == "modified-transitional-1") { + formulation = dcp::Formulation::MODIFIED_TRANSITIONAL_1; + } else if (string(optarg) == "multiple-modified-transitional-1") { + formulation = dcp::Formulation::MULTIPLE_MODIFIED_TRANSITIONAL_1; + } else if (string(optarg) == "dci-any") { + formulation = dcp::Formulation::DCI_ANY; + } else if (string(optarg) == "dci-specific") { + formulation = dcp::Formulation::DCI_SPECIFIC; } else { error ("unrecognised KDM formulation " + string (optarg)); } @@ -497,7 +518,7 @@ int main (int argc, char* argv[]) (for lookup) and by creating a Cinema which the next Screen will be added to. */ cinema_name = optarg; - cinema = shared_ptr (new Cinema (optarg, list(), "", 0, 0)); + cinema = make_shared(optarg, list(), "", 0, 0); break; case 'S': screen_description = optarg; @@ -506,7 +527,7 @@ int main (int argc, char* argv[]) { /* Make a new screen and add it to the current cinema */ dcp::CertificateChain chain (dcp::file_to_string(optarg)); - shared_ptr screen (new Screen (screen_description, "", chain.leaf(), vector())); + auto screen = make_shared(screen_description, "", chain.leaf(), vector()); if (cinema) { cinema->add_screen (screen); } @@ -529,9 +550,9 @@ int main (int argc, char* argv[]) } if (list_cinemas) { - list > cinemas = Config::instance()->cinemas (); - for (list >::const_iterator i = cinemas.begin(); i != cinemas.end(); ++i) { - cout << (*i)->name << " (" << Emailer::address_list ((*i)->emails) << ")\n"; + auto cinemas = Config::instance()->cinemas (); + for (auto i: cinemas) { + cout << i->name << " (" << Emailer::address_list (i->emails) << ")\n"; } exit (EXIT_SUCCESS); }