Use dcp::File in DCP-o-matic (#2231).
[dcpomatic.git] / src / lib / kdm_with_metadata.cc
index e3c0d9204a065aee1c3f31d202f54d6c265357f6..123649d127c0a00fbf468d765505a17b89794046 100644 (file)
@@ -28,6 +28,7 @@
 #include "screen.h"
 #include "util.h"
 #include "zipper.h"
+#include <dcp/file.h>
 
 #include "i18n.h"
 
@@ -66,7 +67,7 @@ write_files (
 
        /* Write KDMs to the specified directory */
        for (auto i: kdms) {
-               auto out = fix_long_path(directory / careful_string_filter(name_format.get(i->name_values(), ".xml")));
+               auto out = dcp::fix_long_path(directory / careful_string_filter(name_format.get(i->name_values(), ".xml")));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
                        i->kdm_as_xml (out);
                        ++written;
@@ -220,17 +221,17 @@ send_emails (
                zip_file /= container_name_format.get(i.front()->name_values(), ".zip");
                make_zip_file (i, zip_file, filename_format);
 
-               auto subject = config->kdm_subject();
-               boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name);
-               boost::algorithm::replace_all (subject, "$START_TIME", i.front()->get('b').get_value_or(""));
-               boost::algorithm::replace_all (subject, "$END_TIME", i.front()->get('e').get_value_or(""));
-               boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
-
-               auto body = config->kdm_email();
-               boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name);
-               boost::algorithm::replace_all (body, "$START_TIME", i.front()->get('b').get_value_or(""));
-               boost::algorithm::replace_all (body, "$END_TIME", i.front()->get('e').get_value_or(""));
-               boost::algorithm::replace_all (body, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
+               auto substitute_variables = [cpl_name, i](string target) {
+                       boost::algorithm::replace_all (target, "$CPL_NAME", cpl_name);
+                       boost::algorithm::replace_all (target, "$START_TIME", i.front()->get('b').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$END_TIME", i.front()->get('e').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$CINEMA_NAME", i.front()->get('c').get_value_or(""));
+                       boost::algorithm::replace_all (target, "$CINEMA_SHORT_NAME", i.front()->get('c').get_value_or("").substr(0, 14));
+                       return target;
+               };
+
+               auto subject = substitute_variables(config->kdm_subject());
+               auto body = substitute_variables(config->kdm_email());
 
                string screens;
                for (auto j: i) {