X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fconfig.cc;h=8f9cfab4b2543cdb330b21df2be533073981458e;hb=1a693725f9a8cc6ba58f65b2f1ef03255d295f23;hp=c483734f85f5f40a71220d01a6c90606b36cd2d5;hpb=cf2146fef7540dc5349d7ac3672da0d3bfa971c0;p=dcpomatic.git diff --git a/src/lib/config.cc b/src/lib/config.cc index c483734f8..8f9cfab4b 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -29,7 +29,9 @@ #include "cinema.h" #include "util.h" #include "cross.h" -#include "raw_convert.h" +#include "film.h" +#include +#include #include #include #include @@ -57,8 +59,10 @@ using std::cerr; using boost::shared_ptr; using boost::optional; using boost::algorithm::trim; +using dcp::raw_convert; Config* Config::_instance = 0; +boost::signals2::signal Config::FailedToLoad; /** Construct default configuration */ Config::Config () @@ -107,6 +111,9 @@ Config::set_defaults () #endif _cinemas_file = path ("cinemas.xml"); _show_hints_before_make_dcp = true; + _kdm_filename_format = dcp::NameFormat ("KDM %f %c %s"); + _dcp_metadata_filename_format = dcp::NameFormat ("%t"); + _dcp_asset_filename_format = dcp::NameFormat ("%t"); _allowed_dcp_frame_rates.clear (); _allowed_dcp_frame_rates.push_back (24); @@ -143,16 +150,8 @@ Config::create_certificate_chain () void Config::read () +try { - if (!have_existing ("config.xml")) { - /* Make a new set of signing certificates and key */ - _signer_chain = create_certificate_chain (); - /* And similar for decryption of KDMs */ - _decryption_chain = create_certificate_chain (); - write (); - return; - } - cxml::Document f ("Config"); f.read_file (path ("config.xml")); optional c; @@ -297,6 +296,9 @@ Config::read () _cinemas_file = f.optional_string_child("CinemasFile").get_value_or (path ("cinemas.xml").string ()); _show_hints_before_make_dcp = f.optional_bool_child("ShowHintsBeforeMakeDCP").get_value_or (true); + _kdm_filename_format = dcp::NameFormat (f.optional_string_child("KDMFilenameFormat").get_value_or ("KDM %f %c %s")); + _dcp_metadata_filename_format = dcp::NameFormat (f.optional_string_child("DCPMetadataFilenameFormat").get_value_or ("%t")); + _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t")); /* Replace any cinemas from config.xml with those from the configured file */ if (boost::filesystem::exists (_cinemas_file)) { @@ -305,6 +307,19 @@ Config::read () read_cinemas (f); } } +catch (...) { + if (have_existing ("config.xml")) { + /* We have a config file but it didn't load */ + FailedToLoad (); + } + set_defaults (); + /* Make a new set of signing certificates and key */ + _signer_chain = create_certificate_chain (); + /* And similar for decryption of KDMs */ + _decryption_chain = create_certificate_chain (); + write (); +} + /** @return Filename to write configuration to */ boost::filesystem::path @@ -366,7 +381,7 @@ Config::write_config_xml () const } root->add_child("OnlyServersEncode")->add_child_text (_only_servers_encode ? "1" : "0"); - root->add_child("TMSProtocol")->add_child_text (raw_convert (_tms_protocol)); + root->add_child("TMSProtocol")->add_child_text (raw_convert (static_cast (_tms_protocol))); root->add_child("TMSIP")->add_child_text (_tms_ip); root->add_child("TMSPath")->add_child_text (_tms_path); root->add_child("TMSUser")->add_child_text (_tms_user); @@ -441,6 +456,9 @@ Config::write_config_xml () const root->add_child("CinemasFile")->add_child_text (_cinemas_file.string()); root->add_child("ShowHintsBeforeMakeDCP")->add_child_text (_show_hints_before_make_dcp ? "1" : "0"); + root->add_child("KDMFilenameFormat")->add_child_text (_kdm_filename_format.specification ()); + root->add_child("DCPMetadataFilenameFormat")->add_child_text (_dcp_metadata_filename_format.specification ()); + root->add_child("DCPAssetFilenameFormat")->add_child_text (_dcp_asset_filename_format.specification ()); try { doc.write_to_file_formatted (path("config.xml").string ()); @@ -571,3 +589,31 @@ Config::set_cinemas_file (boost::filesystem::path file) changed (OTHER); } + +void +Config::save_template (shared_ptr film, string name) const +{ + film->write_template (template_path (name)); +} + +list +Config::template_names () const +{ + list n; + for (boost::filesystem::directory_iterator i (path("templates")); i != boost::filesystem::directory_iterator(); ++i) { + n.push_back (i->path().filename().string()); + } + return n; +} + +bool +Config::existing_template (string name) const +{ + return boost::filesystem::exists (template_path (name)); +} + +boost::filesystem::path +Config::template_path (string name) const +{ + return path("templates") / tidy_for_filename (name); +}