NeedsAssets was only added recently, so allow it not to be present.
[dcpomatic.git] / src / lib / config.cc
index 5df45ea082854d36ccf04cf0f2e91d53d4279d5b..1d9cce64e9fb81516081423b7d8a740492f8c306 100644 (file)
@@ -29,6 +29,7 @@
 #include "cinema.h"
 #include "util.h"
 #include "cross.h"
+#include "film.h"
 #include <dcp/raw_convert.h>
 #include <dcp/name_format.h>
 #include <dcp/colour_matrix.h>
@@ -296,8 +297,8 @@ try
        _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_%i"));
-       _dcp_asset_filename_format = dcp::NameFormat (f.optional_string_child("DCPAssetFilenameFormat").get_value_or ("%t_%i"));
+       _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)) {
@@ -588,3 +589,43 @@ Config::set_cinemas_file (boost::filesystem::path file)
 
        changed (OTHER);
 }
+
+void
+Config::save_template (shared_ptr<const Film> film, string name) const
+{
+       film->write_template (template_path (name));
+}
+
+list<string>
+Config::templates () const
+{
+       list<string> 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);
+}
+
+void
+Config::rename_template (string old_name, string new_name) const
+{
+       boost::filesystem::rename (template_path (old_name), template_path (new_name));
+}
+
+void
+Config::delete_template (string name) const
+{
+       boost::filesystem::remove (template_path (name));
+}